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:
08: /**
09: * 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());
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)
51: throws InterruptedException {
52: return this .connectedEvents.poll(timeout) != null;
53: }
54:
55: public boolean waitForDisconnect(long timeout)
56: throws InterruptedException {
57: return this .disconnectedEvents.poll(timeout) != null;
58: }
59:
60: public boolean waitForConnectAttempt(long timeout)
61: throws InterruptedException {
62: return this .connectAttemptEvents.poll(timeout) != null;
63: }
64:
65: public boolean waitForClose(long timeout)
66: throws InterruptedException {
67: return this.closedEvents.poll(timeout) != null;
68: }
69:
70: }
|