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.transport;
05:
06: import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
07: import EDU.oswego.cs.dl.util.concurrent.SynchronizedRef;
08: import junit.framework.Assert;
09:
10: class ClientHandshakeMessageResponder extends
11: HandshakeMessageResponderBase {
12:
13: protected ClientHandshakeMessageResponder(LinkedQueue sentQueue,
14: LinkedQueue receivedQueue,
15: TransportHandshakeMessageFactory messageFactory,
16: ConnectionID assignedConnectionId,
17: MessageTransportBase transport, SynchronizedRef errorRef) {
18: super (sentQueue, receivedQueue, messageFactory,
19: assignedConnectionId, transport, errorRef);
20: }
21:
22: public void handleHandshakeMessage(TransportHandshakeMessage message) {
23: if (message.isSyn()) {
24:
25: Assert.assertNotNull(message.getConnectionId());
26: sendResponseMessage(messageFactory.createSynAck(
27: this .assignedConnectionId, message.getSource(),
28: false, -1));
29: } else if (message.isAck()) {
30: // nothing to do.
31: } else {
32: Assert.fail("Bogus message received: " + message);
33: }
34: }
35:
36: public boolean waitForAckToBeReceived(long timeout)
37: throws InterruptedException {
38: TransportHandshakeMessage handshake;
39: do {
40: handshake = (TransportHandshakeMessage) receivedQueue
41: .poll(timeout);
42: if (handshake == null)
43: return false;
44: } while (!(handshake.isAck()));
45: return true;
46: }
47:
48: public boolean waitForSynAckToBeSent(long timeout)
49: throws InterruptedException {
50: TransportHandshakeMessage handshake;
51: do {
52: handshake = (TransportHandshakeMessage) sentQueue
53: .poll(timeout);
54: if (handshake == null)
55: return false;
56: } while (!handshake.isSynAck());
57: return true;
58: }
59: }
|