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