1 4 package com.tc.net.protocol; 5 6 import com.tc.bytes.TCByteBuffer; 7 import com.tc.net.core.TCConnection; 8 9 14 public class GenericNetworkMessage extends AbstractTCNetworkMessage { 15 private final TCConnection source; 16 private boolean sent = false; 17 18 public GenericNetworkMessage(TCConnection source, TCByteBuffer data) { 19 this(source, new TCByteBuffer[] { data }); 20 } 21 22 public GenericNetworkMessage(TCConnection source, TCByteBuffer data[]) { 23 super(new GenericNetworkHeader(), data); 24 25 GenericNetworkHeader hdr = (GenericNetworkHeader) getHeader(); 26 27 int msgLength = 0; 28 for (int i = 0; i < data.length; i++) { 29 msgLength += data[i].limit(); 30 } 31 32 hdr.setMessageDataLength(msgLength); 33 this.source = source; 34 } 35 36 GenericNetworkMessage(TCConnection source, TCNetworkHeader header, TCByteBuffer[] payload) { 37 super(header, payload); 38 this.source = source; 39 } 40 41 public void setSequence(int seq) { 42 ((GenericNetworkHeader) getHeader()).setSequence(seq); 43 } 44 45 public int getSequence() { 46 return ((GenericNetworkHeader) getHeader()).getSequence(); 47 } 48 49 public void setClientNum(int num) { 50 ((GenericNetworkHeader) getHeader()).setClientNum(num); 51 } 52 53 public int getClientNum() { 54 return ((GenericNetworkHeader) getHeader()).getClientNum(); 55 } 56 57 public TCConnection getSource() { 58 return source; 59 } 60 61 public synchronized void waitUntilSent() throws InterruptedException { 62 while (!sent) { 63 wait(); 64 } 65 } 66 67 public synchronized void setSent() { 68 this.sent = true; 69 notifyAll(); 70 } 71 } | Popular Tags |