1 4 package com.tc.net.protocol.transport; 5 6 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue; 7 8 11 public class TransportEventMonitor implements MessageTransportListener { 12 13 private final LinkedQueue connectedEvents = new LinkedQueue(); 14 private final LinkedQueue disconnectedEvents = new LinkedQueue(); 15 private final LinkedQueue connectAttemptEvents = new LinkedQueue(); 16 private final LinkedQueue closedEvents = new LinkedQueue(); 17 18 public void notifyTransportConnected(MessageTransport transport) { 19 try { 20 connectedEvents.put(new Object ()); 21 } catch (InterruptedException e) { 22 e.printStackTrace(); 23 } 24 } 25 26 public void notifyTransportDisconnected(MessageTransport transport) { 27 try { 28 disconnectedEvents.put(new Object ()); 29 } catch (InterruptedException e) { 30 e.printStackTrace(); 31 } 32 } 33 34 public void notifyTransportConnectAttempt(MessageTransport transport) { 35 try { 36 this.connectAttemptEvents.put(new Object ()); 37 } catch (InterruptedException e) { 38 e.printStackTrace(); 39 } 40 } 41 42 public void notifyTransportClosed(MessageTransport transport) { 43 try { 44 this.closedEvents.put(new Object ()); 45 } catch (InterruptedException e) { 46 e.printStackTrace(); 47 } 48 } 49 50 public boolean waitForConnect(long timeout) throws InterruptedException { 51 return this.connectedEvents.poll(timeout) != null; 52 } 53 54 public boolean waitForDisconnect(long timeout) throws InterruptedException { 55 return this.disconnectedEvents.poll(timeout) != null; 56 } 57 58 public boolean waitForConnectAttempt(long timeout) throws InterruptedException { 59 return this.connectAttemptEvents.poll(timeout) != null; 60 } 61 62 public boolean waitForClose(long timeout) throws InterruptedException { 63 return this.closedEvents.poll(timeout) != null; 64 } 65 66 } | Popular Tags |