corba/src/share/classes/com/sun/corba/se/impl/protocol/giopmsgheaders/Message_1_1.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.protocol.giopmsgheaders;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
 * This implements the GIOP 1.1 & 1.2 Message header.
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
 * @author Ram Jeyaraman 05/14/2000
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
public class Message_1_1
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
        extends com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase {
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
    // Constants
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
    final static int UPPER_THREE_BYTES_OF_INT_MASK = 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
    private static ORBUtilSystemException wrapper =
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
        ORBUtilSystemException.get( CORBALogDomains.RPC_PROTOCOL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    // Instance variables
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
    int magic = (int) 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    GIOPVersion GIOP_version = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    byte flags = (byte) 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    byte message_type = (byte) 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    int message_size = (int) 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    // Constructor
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    Message_1_1() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    Message_1_1(int _magic, GIOPVersion _GIOP_version, byte _flags,
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
            byte _message_type, int _message_size) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
        magic = _magic;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        GIOP_version = _GIOP_version;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
        flags = _flags;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        message_type = _message_type;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        message_size = _message_size;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    // Accessor methods
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    public GIOPVersion getGIOPVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        return this.GIOP_version;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    public int getType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        return this.message_type;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    public int getSize() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            return this.message_size;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    public boolean isLittleEndian() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        return ((this.flags & LITTLE_ENDIAN_BIT) == LITTLE_ENDIAN_BIT);
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    public boolean moreFragmentsToFollow() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        return ( (this.flags & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT );
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    // Mutator methods
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    // NOTE: This is a SUN PROPRIETARY EXTENSION
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    // Add the poolToUse to the upper 6 bits of byte 6 of the GIOP header.
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    // this.flags represents byte 6 here.
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    public void setThreadPoolToUse(int poolToUse) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        // IMPORTANT: Bitwise operations will promote
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        //            byte types to int before performing
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        //            bitwise operations. And, Java
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        //            types are signed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        int tmpFlags = poolToUse << 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        tmpFlags &= UPPER_THREE_BYTES_OF_INT_MASK;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        tmpFlags |= flags;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        flags = (byte)tmpFlags;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    public void setSize(ByteBuffer byteBuffer, int size) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        this.message_size = size;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        // Patch the size field in the header.
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        int patch = size - GIOPMessageHeaderLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        if (!isLittleEndian()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            byteBuffer.put(8,  (byte)((patch >>> 24) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
            byteBuffer.put(9,  (byte)((patch >>> 16) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            byteBuffer.put(10, (byte)((patch >>> 8)  & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
            byteBuffer.put(11, (byte)((patch >>> 0)  & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            byteBuffer.put(8,  (byte)((patch >>> 0)  & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
            byteBuffer.put(9,  (byte)((patch >>> 8)  & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            byteBuffer.put(10, (byte)((patch >>> 16) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            byteBuffer.put(11, (byte)((patch >>> 24) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
     * Allows us to create a fragment message from any message type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    public FragmentMessage createFragmentMessage() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        // check for message type validity
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        switch (this.message_type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        case GIOPCancelRequest :
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        case GIOPCloseConnection :
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        case GIOPMessageError :
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
            throw wrapper.fragmentationDisallowed(
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
                CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        case GIOPLocateRequest :
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        case GIOPLocateReply :
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                throw wrapper.fragmentationDisallowed(
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
                    CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        // A fragmented mesg can be created only if the current mesg' fragment
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        // bit is set. Otherwise, raise error
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        // too stringent check
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        if ( (this.flags & MORE_FRAGMENTS_BIT) != MORE_FRAGMENTS_BIT ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
                throw wrapper.fragmentationDisallowed( CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        */
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
        if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
            return new FragmentMessage_1_1(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
        } else if (this.GIOP_version.equals(GIOPVersion.V1_2)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
            return new FragmentMessage_1_2(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        throw wrapper.giopVersionError( CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    // IO methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
    // This should do nothing even if it is called. The Message Header is read
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    // off a java.io.InputStream (not a CDRInputStream) by IIOPConnection
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    // in order to choose the correct CDR Version , msg_type, and msg_size.
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    // So, we would never need to read the Message Header off a CDRInputStream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    public void read(org.omg.CORBA.portable.InputStream istream) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
        this.magic = istream.read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
        this.GIOP_version = (new GIOPVersion()).read(istream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
        this.flags = istream.read_octet();
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        this.message_type = istream.read_octet();
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        this.message_size = istream.read_ulong();
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        */
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    public void write(org.omg.CORBA.portable.OutputStream ostream) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
        ostream.write_long(this.magic);
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
        nullCheck(this.GIOP_version);
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        this.GIOP_version.write(ostream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        ostream.write_octet(this.flags);
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
        ostream.write_octet(this.message_type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
        ostream.write_ulong(this.message_size);
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
} // class Message_1_1