KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > giopmsgheaders > Message_1_1


1 /*
2  * @(#)Message_1_1.java 1.12 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.protocol.giopmsgheaders;
9
10 import java.nio.ByteBuffer JavaDoc;
11 import org.omg.CORBA.INTERNAL JavaDoc;
12 import org.omg.CORBA.CompletionStatus JavaDoc;
13
14 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
15
16 import com.sun.corba.se.spi.logging.CORBALogDomains ;
17 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
18
19 /*
20  * This implements the GIOP 1.1 & 1.2 Message header.
21  *
22  * @author Ram Jeyaraman 05/14/2000
23  * @version 1.0
24  */

25
26 public class Message_1_1
27         extends com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase {
28
29     // Constants
30
final static int UPPER_THREE_BYTES_OF_INT_MASK = 0xFF;
31
32     private static ORBUtilSystemException wrapper =
33     ORBUtilSystemException.get( CORBALogDomains.RPC_PROTOCOL ) ;
34
35     // Instance variables
36
int magic = (int) 0;
37     GIOPVersion GIOP_version = null;
38     byte flags = (byte) 0;
39     byte message_type = (byte) 0;
40     int message_size = (int) 0;
41
42     // Constructor
43

44     Message_1_1() {
45     }
46     
47     Message_1_1(int _magic, GIOPVersion _GIOP_version, byte _flags,
48             byte _message_type, int _message_size) {
49         magic = _magic;
50         GIOP_version = _GIOP_version;
51         flags = _flags;
52         message_type = _message_type;
53         message_size = _message_size;
54     }
55
56     // Accessor methods
57

58     public GIOPVersion getGIOPVersion() {
59         return this.GIOP_version;
60     }
61
62     public int getType() {
63         return this.message_type;
64     }
65
66     public int getSize() {
67         return this.message_size;
68     }
69
70     public boolean isLittleEndian() {
71         return ((this.flags & LITTLE_ENDIAN_BIT) == LITTLE_ENDIAN_BIT);
72     }
73
74     public boolean moreFragmentsToFollow() {
75         return ( (this.flags & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT );
76     }
77
78     // Mutator methods
79

80     // NOTE: This is a SUN PROPRIETARY EXTENSION
81
// Add the poolToUse to the upper 6 bits of byte 6 of the GIOP header.
82
// this.flags represents byte 6 here.
83
public void setThreadPoolToUse(int poolToUse) {
84     // IMPORTANT: Bitwise operations will promote
85
// byte types to int before performing
86
// bitwise operations. And, Java
87
// types are signed.
88
int tmpFlags = poolToUse << 2;
89     tmpFlags &= UPPER_THREE_BYTES_OF_INT_MASK;
90     tmpFlags |= flags;
91     flags = (byte)tmpFlags;
92     }
93
94     public void setSize(ByteBuffer JavaDoc byteBuffer, int size) {
95
96     this.message_size = size;
97
98         //
99
// Patch the size field in the header.
100
//
101

102     int patch = size - GIOPMessageHeaderLength;
103         if (!isLittleEndian()) {
104             byteBuffer.put(8, (byte)((patch >>> 24) & 0xFF));
105             byteBuffer.put(9, (byte)((patch >>> 16) & 0xFF));
106             byteBuffer.put(10, (byte)((patch >>> 8) & 0xFF));
107             byteBuffer.put(11, (byte)((patch >>> 0) & 0xFF));
108         } else {
109             byteBuffer.put(8, (byte)((patch >>> 0) & 0xFF));
110             byteBuffer.put(9, (byte)((patch >>> 8) & 0xFF));
111             byteBuffer.put(10, (byte)((patch >>> 16) & 0xFF));
112             byteBuffer.put(11, (byte)((patch >>> 24) & 0xFF));
113         }
114     }
115
116     /**
117      * Allows us to create a fragment message from any message type.
118      */

119     public FragmentMessage createFragmentMessage() {
120
121         // check for message type validity
122

123         switch (this.message_type) {
124         case GIOPCancelRequest :
125         case GIOPCloseConnection :
126         case GIOPMessageError :
127         throw wrapper.fragmentationDisallowed(
128         CompletionStatus.COMPLETED_MAYBE);
129         case GIOPLocateRequest :
130         case GIOPLocateReply :
131             if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
132         throw wrapper.fragmentationDisallowed(
133             CompletionStatus.COMPLETED_MAYBE);
134             }
135             break;
136         }
137
138         /*
139         // A fragmented mesg can be created only if the current mesg' fragment
140         // bit is set. Otherwise, raise error
141         // too stringent check
142         if ( (this.flags & MORE_FRAGMENTS_BIT) != MORE_FRAGMENTS_BIT ) {
143         throw wrapper.fragmentationDisallowed( CompletionStatus.COMPLETED_MAYBE);
144         }
145         */

146         if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
147             return new FragmentMessage_1_1(this);
148         } else if (this.GIOP_version.equals(GIOPVersion.V1_2)) {
149             return new FragmentMessage_1_2(this);
150         }
151
152     throw wrapper.giopVersionError( CompletionStatus.COMPLETED_MAYBE);
153     }
154
155     // IO methods
156

157     // This should do nothing even if it is called. The Message Header is read
158
// off a java.io.InputStream (not a CDRInputStream) by IIOPConnection
159
// in order to choose the correct CDR Version , msg_type, and msg_size.
160
// So, we would never need to read the Message Header off a CDRInputStream.
161
public void read(org.omg.CORBA.portable.InputStream JavaDoc istream) {
162         /*
163         this.magic = istream.read_long();
164         this.GIOP_version = (new GIOPVersion()).read(istream);
165         this.flags = istream.read_octet();
166         this.message_type = istream.read_octet();
167         this.message_size = istream.read_ulong();
168         */

169     }
170
171     public void write(org.omg.CORBA.portable.OutputStream JavaDoc ostream) {
172         ostream.write_long(this.magic);
173         nullCheck(this.GIOP_version);
174         this.GIOP_version.write(ostream);
175         ostream.write_octet(this.flags);
176         ostream.write_octet(this.message_type);
177         ostream.write_ulong(this.message_size);
178     }
179 } // class Message_1_1
180
Popular Tags