KickJava   Java API By Example, From Geeks To Geeks.

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


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
8 /**
9  * Monitors transport events.
10  */

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 JavaDoc());
21     } catch (InterruptedException JavaDoc e) {
22       e.printStackTrace();
23     }
24   }
25
26   public void notifyTransportDisconnected(MessageTransport transport) {
27     try {
28       disconnectedEvents.put(new Object JavaDoc());
29     } catch (InterruptedException JavaDoc e) {
30       e.printStackTrace();
31     }
32   }
33
34   public void notifyTransportConnectAttempt(MessageTransport transport) {
35     try {
36       this.connectAttemptEvents.put(new Object JavaDoc());
37     } catch (InterruptedException JavaDoc e) {
38       e.printStackTrace();
39     }
40   }
41
42   public void notifyTransportClosed(MessageTransport transport) {
43     try {
44       this.closedEvents.put(new Object JavaDoc());
45     } catch (InterruptedException JavaDoc e) {
46       e.printStackTrace();
47     }
48   }
49
50   public boolean waitForConnect(long timeout) throws InterruptedException JavaDoc {
51     return this.connectedEvents.poll(timeout) != null;
52   }
53
54   public boolean waitForDisconnect(long timeout) throws InterruptedException JavaDoc {
55     return this.disconnectedEvents.poll(timeout) != null;
56   }
57
58   public boolean waitForConnectAttempt(long timeout) throws InterruptedException JavaDoc {
59     return this.connectAttemptEvents.poll(timeout) != null;
60   }
61
62   public boolean waitForClose(long timeout) throws InterruptedException JavaDoc {
63     return this.closedEvents.poll(timeout) != null;
64   }
65
66 }
Popular Tags