messagebase.java

来自「JAVA 所有包」· Java 代码 · 共 949 行 · 第 1/3 页

JAVA
949
字号
            //msg = new FragmentMessage(orb.giopDebugFlag);            if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { // 1.0                // not possible (error checking done already)            } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { // 1.1                msg = new FragmentMessage_1_1();            } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { // 1.2                msg = new FragmentMessage_1_2();            } else {		throw wrapper.giopVersionError(		    CompletionStatus.COMPLETED_MAYBE);            }            break;        default:            if (orb.giopDebugFlag)                dprint(".readGIOPHeader: UNKNOWN MESSAGE TYPE: "		       + buf.get(7));            // unknown message type ?            // ACTION : send MessageError and close the connection	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }        //        // Initialize the generic GIOP header instance variables.        //        if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { // 1.0            Message_1_0 msg10 = (Message_1_0) msg;            msg10.magic = magic;            msg10.GIOP_version = new GIOPVersion(buf.get(4), buf.get(5));            msg10.byte_order = (buf.get(6) == LITTLE_ENDIAN_BIT);	    // 'request partitioning' not supported on GIOP version 1.0	    // so just use the default thread pool, 0.	    msg.threadPoolToUse = 0;            msg10.message_type = buf.get(7);            msg10.message_size = readSize(buf.get(8), buf.get(9), buf.get(10), buf.get(11),                                          msg10.isLittleEndian()) +                                 GIOPMessageHeaderLength;        } else { // 1.1 & 1.2            Message_1_1 msg11 = (Message_1_1) msg;            msg11.magic = magic;            msg11.GIOP_version = new GIOPVersion(buf.get(4), buf.get(5));            msg11.flags = (byte)(buf.get(6) & TRAILING_TWO_BIT_BYTE_MASK);	    // IMPORTANT: For 'request partitioning', the thread pool to use	    //            information is stored in the leading 6 bits of byte 6.	    //	    // IMPORTANT: Request partitioning is a PROPRIETARY EXTENSION !!!	    //	    // NOTE: Bitwise operators will promote a byte to an int before 	    //       performing a bitwise operation and bytes, ints, longs, etc	    //       are signed types in Java. Thus, the need for the 	    //       THREAD_POOL_TO_USE_MASK operation.	    msg.threadPoolToUse = (buf.get(6) >>> 2) & THREAD_POOL_TO_USE_MASK;            msg11.message_type = buf.get(7);            msg11.message_size =                       readSize(buf.get(8), buf.get(9), buf.get(10), buf.get(11),                              msg11.isLittleEndian()) + GIOPMessageHeaderLength;        }        if (orb.giopDebugFlag) {            // Since this is executed in debug mode only the overhead of            // using a View Buffer is not an issue. We'll also use a            // read-only View Buffer so we don't disturb the state of            // byteBuffer.             dprint(".readGIOPHeader: header construction complete.");            // For debugging purposes, save the 12 bytes of the header            ByteBuffer viewBuf = buf.asReadOnlyBuffer();            byte[] msgBuf = new byte[GIOPMessageHeaderLength];            viewBuf.position(0).limit(GIOPMessageHeaderLength);            viewBuf.get(msgBuf,0,msgBuf.length);	    // REVISIT: is giopHeader still used?            ((MessageBase)msg).giopHeader = msgBuf;        }	msg.setByteBuffer(buf);	msg.setEncodingVersion(requestEncodingVersion);	return msg;    }    public static Message readGIOPBody(ORB orb,			               CorbaConnection connection,				       Message msg)    {        ReadTimeouts readTimeouts =	                   orb.getORBData().getTransportTCPReadTimeouts();	ByteBuffer buf = msg.getByteBuffer();	buf.position(MessageBase.GIOPMessageHeaderLength);	int msgSizeMinusHeader =	    msg.getSize() - MessageBase.GIOPMessageHeaderLength;	try {	    buf = connection.read(buf, 			  GIOPMessageHeaderLength, msgSizeMinusHeader,			  readTimeouts.get_max_time_to_wait());	} catch (IOException e) {	    throw wrapper.ioexceptionWhenReadingConnection(e);	}	msg.setByteBuffer(buf);	if (orb.giopDebugFlag) {	    dprint(".readGIOPBody: received message:");	    ByteBuffer viewBuffer = buf.asReadOnlyBuffer();	    viewBuffer.position(0).limit(msg.getSize());	    ByteBufferWithInfo bbwi = new ByteBufferWithInfo(orb, viewBuffer);	    CDRInputStream_1_0.printBuffer(bbwi);	}        return msg;    }    private static RequestMessage createRequest(            ORB orb, GIOPVersion gv, byte encodingVersion, int request_id,            boolean response_expected, byte[] object_key, String operation,            ServiceContexts service_contexts, Principal requesting_principal) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new RequestMessage_1_0(orb, service_contexts, request_id,					 response_expected, object_key,					 operation, requesting_principal);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new RequestMessage_1_1(orb, service_contexts, request_id,                response_expected, new byte[] { 0x00, 0x00, 0x00 },                object_key, operation, requesting_principal);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            // Note: Currently we use response_expected flag to decide if the            // call is oneway or not. Ideally, it is possible to expect a            // response on a oneway call too, but we do not support it now.            byte response_flags = 0x03;            if (response_expected) {                response_flags = 0x03;            } else {                response_flags = 0x00;            }            /*            // REVISIT The following is the correct way to do it. This gives            // more flexibility.            if ((DII::INV_NO_RESPONSE == false) && response_expected) {                response_flags = 0x03; // regular two-way            } else if ((DII::INV_NO_RESPONSE == false) && !response_expected) {                // this condition is not possible            } else if ((DII::INV_NO_RESPONSE == true) && response_expected) {                // oneway, but we need response for LocationForwards or                // SystemExceptions.                response_flags = 0x01;            } else if ((DII::INV_NO_RESPONSE == true) && !response_expected) {                // oneway, no response required                response_flags = 0x00;            }            */            TargetAddress target = new TargetAddress();            target.object_key(object_key);            RequestMessage msg = 		new RequestMessage_1_2(orb, request_id, response_flags,				       new byte[] { 0x00, 0x00, 0x00 },				       target, operation, service_contexts);	    msg.setEncodingVersion(encodingVersion);	    return msg;        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }    public static RequestMessage createRequest(            ORB orb, GIOPVersion gv, byte encodingVersion, int request_id,	    boolean response_expected, IOR ior,	    short addrDisp, String operation,            ServiceContexts service_contexts, Principal requesting_principal) {	RequestMessage requestMessage = null;        IIOPProfile profile = ior.getProfile();                    if (addrDisp == KeyAddr.value) {              // object key will be used for target addressing            profile = ior.getProfile();    	    ObjectKey objKey = profile.getObjectKey();	    byte[] object_key = objKey.getBytes(orb);            	    requestMessage = 		   createRequest(orb, gv, encodingVersion, request_id,				 response_expected, object_key,				 operation, service_contexts,                                 requesting_principal);                    } else {                    if (!(gv.equals(GIOPVersion.V1_2))) {                        // only object_key based target addressing is allowed for                 // GIOP 1.0 & 1.1	        throw wrapper.giopVersionError(		    CompletionStatus.COMPLETED_MAYBE);            }                // Note: Currently we use response_expected flag to decide if the            // call is oneway or not. Ideally, it is possible to expect a            // response on a oneway call too, but we do not support it now.            byte response_flags = 0x03;            if (response_expected) {                response_flags = 0x03;            } else {                response_flags = 0x00;            }                        TargetAddress target = new TargetAddress();                        if (addrDisp == ProfileAddr.value) { // iop profile will be used                profile = ior.getProfile();                target.profile(profile.getIOPProfile());            } else if (addrDisp == ReferenceAddr.value) {  // ior will be used                IORAddressingInfo iorInfo =                     new IORAddressingInfo( 0, // profile index                        ior.getIOPIOR());                target.ior(iorInfo);              } else {                 // invalid target addressing disposition value	        throw wrapper.illegalTargetAddressDisposition(		    CompletionStatus.COMPLETED_NO);            }        	    requestMessage =                   new RequestMessage_1_2(orb, request_id, response_flags,                                  new byte[] { 0x00, 0x00, 0x00 }, target,                                  operation, service_contexts);	    requestMessage.setEncodingVersion(encodingVersion);	}	if (gv.supportsIORIIOPProfileComponents()) {	    // add request partitioning thread pool to use info	    int poolToUse = 0; // default pool	    IIOPProfileTemplate temp = 		(IIOPProfileTemplate)profile.getTaggedProfileTemplate();	    Iterator iter = 		temp.iteratorById(ORBConstants.TAG_REQUEST_PARTITIONING_ID);	    if (iter.hasNext()) {		poolToUse = 		    ((RequestPartitioningComponent)iter.next()).getRequestPartitioningId();	    }	    if (poolToUse < ORBConstants.REQUEST_PARTITIONING_MIN_THREAD_POOL_ID ||		poolToUse > ORBConstants.REQUEST_PARTITIONING_MAX_THREAD_POOL_ID) {		throw wrapper.invalidRequestPartitioningId(new Integer(poolToUse),		      new Integer(ORBConstants.REQUEST_PARTITIONING_MIN_THREAD_POOL_ID),	      	      new Integer(ORBConstants.REQUEST_PARTITIONING_MAX_THREAD_POOL_ID));	    }	    requestMessage.setThreadPoolToUse(poolToUse);	}	return requestMessage;    }                        public static ReplyMessage createReply(            ORB orb, GIOPVersion gv, byte encodingVersion, int request_id,            int reply_status, ServiceContexts service_contexts, IOR ior) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new ReplyMessage_1_0(orb, service_contexts, request_id,                                        reply_status, ior);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new ReplyMessage_1_1(orb, service_contexts, request_id,                                        reply_status, ior);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            ReplyMessage msg = 		new ReplyMessage_1_2(orb, request_id, reply_status,				     service_contexts, ior);	    msg.setEncodingVersion(encodingVersion);	    return msg;        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }    public static LocateRequestMessage createLocateRequest(            ORB orb, GIOPVersion gv, byte encodingVersion,            int request_id, byte[] object_key) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new LocateRequestMessage_1_0(orb, request_id, object_key);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new LocateRequestMessage_1_1(orb, request_id, object_key);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            TargetAddress target = new TargetAddress();            target.object_key(object_key);            LocateRequestMessage msg =		new LocateRequestMessage_1_2(orb, request_id, target);	    msg.setEncodingVersion(encodingVersion);	    return msg;        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }    public static LocateReplyMessage createLocateReply(	    ORB orb, GIOPVersion gv, byte encodingVersion,            int request_id, int locate_status, IOR ior) {        if (gv.equals(GIOPVersion.V1_0)) { // 1.0            return new LocateReplyMessage_1_0(orb, request_id,                                              locate_status, ior);        } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1            return new LocateReplyMessage_1_1(orb, request_id,                                              locate_status, ior);        } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2            LocateReplyMessage msg = 		new LocateReplyMessage_1_2(orb, request_id, 					   locate_status, ior);	    msg.setEncodingVersion(encodingVersion);	    return msg;        } else {	    throw wrapper.giopVersionError(		CompletionStatus.COMPLETED_MAYBE);        }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?