KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > protocol > transport > ClientHandshakeMessageResponder


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