KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > protocol > delivery > TestProtocolMessageDelivery


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.protocol.delivery;
5
6 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
7
8 import com.tc.net.protocol.TCNetworkMessage;
9 import com.tc.net.protocol.delivery.OOOProtocolMessage;
10 import com.tc.net.protocol.delivery.OOOProtocolMessageDelivery;
11 import com.tc.util.Assert;
12
13 /**
14  *
15  */

16 public class TestProtocolMessageDelivery implements OOOProtocolMessageDelivery {
17   public boolean sentAckRequest = false;
18   public long ackCount = -1;
19   public boolean sentAck = false;
20   public OOOProtocolMessage msg = null;
21   public TCNetworkMessage tcMessage = null;
22   public boolean created = false;
23   public int receivedMessageCount;
24   private LinkedQueue receivedQueue;
25
26   public TestProtocolMessageDelivery(LinkedQueue receivedQueue) {
27     this.receivedQueue = receivedQueue;
28   }
29   
30   public void sendAckRequest() {
31     sentAckRequest = true;
32   }
33
34   public void sendAck(long count) {
35     this.ackCount = count;
36     this.sentAck = true;
37   }
38
39   public void sendMessage(OOOProtocolMessage pmsg) {
40     this.msg = pmsg;
41   }
42
43   public OOOProtocolMessage createProtocolMessage(long sent, TCNetworkMessage tcmsg) {
44     Assert.eval(sent >= 0);
45     this.tcMessage = tcmsg;
46     this.created = true;
47     TestProtocolMessage tpm = new TestProtocolMessage(tcmsg, sent, 0);
48     tpm.isSend = true;
49     return tpm;
50   }
51
52   public void clear() {
53     sentAck = false;
54     sentAckRequest = false;
55     ackCount = -1;
56     msg = null;
57     tcMessage = null;
58     created = false;
59   }
60
61   public void receiveMessage(OOOProtocolMessage pm) {
62     receivedMessageCount++;
63     try {
64       receivedQueue.put(((TestProtocolMessage)pm).msg);
65     } catch (InterruptedException JavaDoc e) {
66       e.printStackTrace();
67       junit.framework.Assert.fail("yikes! " + e);
68     }
69     
70   }
71
72 }
Popular Tags