001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.net.protocol.delivery;
006:
007: import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
008:
009: import com.tc.net.protocol.TCNetworkMessage;
010: import com.tc.net.protocol.delivery.OOOProtocolMessage;
011: import com.tc.net.protocol.delivery.OOOProtocolMessageDelivery;
012: import com.tc.net.protocol.transport.ConnectionID;
013: import com.tc.util.Assert;
014:
015: /**
016: *
017: */
018: public class TestProtocolMessageDelivery implements
019: OOOProtocolMessageDelivery {
020: public boolean sentAckRequest = false;
021: public long ackCount = -1;
022: public boolean sentAck = false;
023: public OOOProtocolMessage msg = null;
024: public TCNetworkMessage tcMessage = null;
025: public boolean created = false;
026: public int receivedMessageCount;
027: private LinkedQueue receivedQueue;
028:
029: public TestProtocolMessageDelivery(LinkedQueue receivedQueue) {
030: this .receivedQueue = receivedQueue;
031: }
032:
033: public OOOProtocolMessage createHandshakeMessage(long ack) {
034: sentAckRequest = true;
035: return (new TestProtocolMessage());
036: }
037:
038: public void sendAckRequest() {
039: sentAckRequest = true;
040: }
041:
042: public OOOProtocolMessage createAckMessage(long sequence) {
043: this .ackCount = sequence;
044: this .sentAck = true;
045:
046: TestProtocolMessage opm = new TestProtocolMessage(null, 0,
047: sequence);
048: opm.isAck = true;
049: return (opm);
050: }
051:
052: public void sendAck(long count) {
053: this .ackCount = count;
054: this .sentAck = true;
055: }
056:
057: public boolean sendMessage(OOOProtocolMessage pmsg) {
058: this .msg = pmsg;
059: return (true);
060: }
061:
062: public OOOProtocolMessage createProtocolMessage(long sent,
063: TCNetworkMessage tcmsg) {
064: Assert.eval(sent >= 0);
065: this .tcMessage = tcmsg;
066: this .created = true;
067: TestProtocolMessage tpm = new TestProtocolMessage(tcmsg, sent,
068: 0);
069: tpm.isSend = true;
070: return tpm;
071: }
072:
073: public void clear() {
074: sentAck = false;
075: sentAckRequest = false;
076: ackCount = -1;
077: msg = null;
078: tcMessage = null;
079: created = false;
080: }
081:
082: public void receiveMessage(OOOProtocolMessage pm) {
083: receivedMessageCount++;
084: try {
085: receivedQueue.put(((TestProtocolMessage) pm).msg);
086: } catch (InterruptedException e) {
087: e.printStackTrace();
088: junit.framework.Assert.fail("yikes! " + e);
089: }
090:
091: }
092:
093: public ConnectionID getConnectionId() {
094: return null;
095: }
096:
097: public OOOProtocolMessage createHandshakeReplyOkMessage(
098: long sequence) {
099: return null;
100: }
101:
102: public OOOProtocolMessage createHandshakeReplyFailMessage(
103: long sequence) {
104: return null;
105: }
106:
107: }
|