01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.net.protocol;
05:
06: import com.tc.bytes.TCByteBuffer;
07: import com.tc.net.core.TCConnection;
08:
09: /**
10: * A generic network messge. Not really useful except for testing
11: *
12: * @author teck
13: */
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,
23: TCByteBuffer data[]) {
24: super (new GenericNetworkHeader(), data);
25:
26: GenericNetworkHeader hdr = (GenericNetworkHeader) getHeader();
27:
28: int msgLength = 0;
29: for (int i = 0; i < data.length; i++) {
30: msgLength += data[i].limit();
31: }
32:
33: hdr.setMessageDataLength(msgLength);
34: this .source = source;
35: }
36:
37: GenericNetworkMessage(TCConnection source, TCNetworkHeader header,
38: TCByteBuffer[] payload) {
39: super (header, payload);
40: this .source = source;
41: }
42:
43: public void setSequence(int seq) {
44: ((GenericNetworkHeader) getHeader()).setSequence(seq);
45: }
46:
47: public int getSequence() {
48: return ((GenericNetworkHeader) getHeader()).getSequence();
49: }
50:
51: public void setClientNum(int num) {
52: ((GenericNetworkHeader) getHeader()).setClientNum(num);
53: }
54:
55: public int getClientNum() {
56: return ((GenericNetworkHeader) getHeader()).getClientNum();
57: }
58:
59: public TCConnection getSource() {
60: return source;
61: }
62:
63: public synchronized void waitUntilSent()
64: throws InterruptedException {
65: while (!sent) {
66: wait();
67: }
68: }
69:
70: public synchronized void setSent() {
71: this .sent = true;
72: notifyAll();
73: }
74: }
|