01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.protocol.delivery;
06:
07: import com.tc.net.protocol.transport.ClientConnectionEstablisher;
08: import com.tc.net.protocol.transport.ClientMessageTransport;
09: import com.tc.net.protocol.transport.ConnectionWatcher;
10: import com.tc.net.protocol.transport.MessageTransport;
11: import com.tc.net.protocol.transport.RestoreConnectionCallback;
12: import com.tc.util.DebugUtil;
13:
14: public class OOOConnectionWatcher extends ConnectionWatcher implements
15: RestoreConnectionCallback {
16:
17: private static final boolean debug = false;
18:
19: private final OnceAndOnlyOnceProtocolNetworkLayer oooLayer;
20: private final long timeoutMillis;
21:
22: public OOOConnectionWatcher(ClientMessageTransport cmt,
23: ClientConnectionEstablisher cce,
24: OnceAndOnlyOnceProtocolNetworkLayer oooLayer,
25: long timeoutMillis) {
26: super (cmt, oooLayer, cce);
27: this .oooLayer = oooLayer;
28: this .timeoutMillis = timeoutMillis;
29: }
30:
31: public void notifyTransportDisconnected(MessageTransport transport) {
32: log(transport,
33: "Transport Disconnected, calling asyncRestoreConnection for "
34: + timeoutMillis);
35: oooLayer.startRestoringConnection();
36: oooLayer.notifyTransportDisconnected(transport);
37: cce.asyncRestoreConnection(cmt, transport.getRemoteAddress(),
38: this , timeoutMillis);
39: }
40:
41: public void notifyTransportConnected(MessageTransport transport) {
42: log(transport, "Transport Connected");
43: oooLayer.notifyTransportConnected(transport);
44: }
45:
46: public void restoreConnectionFailed(MessageTransport transport) {
47: log(transport, "Restore Connection Failed");
48: oooLayer.connectionRestoreFailed();
49: super .notifyTransportDisconnected(transport);
50: }
51:
52: private static void log(MessageTransport transport, String msg) {
53: if (debug)
54: DebugUtil.trace("OOOConnectionWatcher-CLIENT-"
55: + transport.getConnectionId() + " -> " + msg);
56: }
57: }
|