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:
09: import com.tc.net.protocol.transport.TransportHandshakeMessage;
10:
11: import junit.framework.Assert;
12:
13: class ServerHandshakeMessageResponder extends
14: HandshakeMessageResponderBase {
15:
16: private LinkedQueue synAckErrors = new LinkedQueue();
17:
18: protected ServerHandshakeMessageResponder(LinkedQueue sentQueue,
19: LinkedQueue receivedQueue,
20: TransportHandshakeMessageFactory messageFactory,
21: ConnectionID assignedConnectionId,
22: MessageTransportBase transport, SynchronizedRef errorRef) {
23: super (sentQueue, receivedQueue, messageFactory,
24: assignedConnectionId, transport, errorRef);
25: }
26:
27: public void handleHandshakeMessage(
28: final TransportHandshakeMessage message) {
29: try {
30: if (message.isSynAck()) {
31: Assert.assertNotNull(message.getConnectionId());
32: Assert.assertEquals(this .assignedConnectionId, message
33: .getConnectionId());
34: final SynAckMessage synAck = (SynAckMessage) message;
35: if (synAck.hasErrorContext()) {
36: this .synAckErrors.put(synAck.getErrorContext());
37: } else {
38: TransportHandshakeMessage ack = messageFactory
39: .createAck(this .assignedConnectionId,
40: synAck.getSource());
41: this .sendResponseMessage(ack);
42: }
43: } else {
44: Assert.fail("Recieved an unexpected message type: "
45: + message);
46: }
47: } catch (Exception e) {
48: setError(e);
49: }
50: }
51:
52: public boolean wasSynAckReceived(long timeout) throws Exception {
53: TransportHandshakeMessage message = (TransportHandshakeMessage) this .receivedQueue
54: .poll(timeout);
55: return message != null && message.isSynAck();
56: }
57:
58: public String waitForSynAckErrorToBeReceived(long timeout)
59: throws InterruptedException {
60: return (String) this.synAckErrors.poll(timeout);
61: }
62:
63: }
|