1 4 package com.tc.net.protocol.transport; 5 6 import com.tc.bytes.TCByteBuffer; 7 import com.tc.net.core.TCConnection; 8 import com.tc.net.protocol.AbstractTCNetworkMessage; 9 import com.tc.net.protocol.TCNetworkHeader; 10 import com.tc.net.protocol.TCNetworkMessage; 11 12 19 public class WireProtocolMessageImpl extends AbstractTCNetworkMessage implements WireProtocolMessage { 20 private final TCConnection sourceConnection; 21 22 29 static WireProtocolMessage wrapMessage(TCNetworkMessage msgPayload, TCConnection source) { 30 WireProtocolHeader header = new WireProtocolHeader(); 31 header.setProtocol(WireProtocolHeader.getProtocolForMessageClass(msgPayload)); 32 33 if (!msgPayload.isSealed()) { 35 msgPayload.seal(); 36 } 37 38 WireProtocolMessage rv = new WireProtocolMessageImpl(source, header, msgPayload); 39 return rv; 40 } 41 42 protected WireProtocolMessageImpl(TCConnection source, TCNetworkHeader header, TCByteBuffer[] data) { 43 super(header, data); 44 recordLength(); 45 this.sourceConnection = source; 46 } 47 48 private WireProtocolMessageImpl(TCConnection source, TCNetworkHeader header, TCNetworkMessage subMessage) { 49 super(header, subMessage); 50 recordLength(); 51 this.sourceConnection = source; 52 } 53 54 public void doRecycleOnWrite() { 55 getWireProtocolHeader().recycle(); 56 AbstractTCNetworkMessage messagePayLoad = (AbstractTCNetworkMessage) getMessagePayload(); 57 if(messagePayLoad != null) { 58 messagePayLoad.doRecycleOnWrite(); 59 } 60 } 61 62 public short getMessageProtocol() { 63 return ((WireProtocolHeader) getHeader()).getProtocol(); 64 } 65 66 public WireProtocolHeader getWireProtocolHeader() { 67 return ((WireProtocolHeader) getHeader()); 68 } 69 70 public TCConnection getSource() { 71 return sourceConnection; 72 } 73 74 protected void recordLength() { 75 TCNetworkMessage msgPayload = getMessagePayload(); 76 int packetLength = msgPayload == null ? getTotalLength() : getHeader().getHeaderByteLength() 79 + msgPayload.getTotalLength(); 80 81 ((WireProtocolHeader) getHeader()).setTotalPacketLength(packetLength); 82 } 83 84 } | Popular Tags |