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.async.api.Sink;
08: import com.tc.net.protocol.AbstractNetworkStackHarness;
09: import com.tc.net.protocol.tcm.MessageChannelInternal;
10: import com.tc.net.protocol.tcm.ServerMessageChannelFactory;
11: import com.tc.net.protocol.transport.ClientConnectionEstablisher;
12: import com.tc.net.protocol.transport.ClientMessageTransport;
13: import com.tc.net.protocol.transport.MessageTransport;
14: import com.tc.net.protocol.transport.MessageTransportFactory;
15: import com.tc.properties.TCPropertiesImpl;
16:
17: public class OOONetworkStackHarness extends AbstractNetworkStackHarness {
18:
19: private final OnceAndOnlyOnceProtocolNetworkLayerFactory factory;
20: private Sink sink;
21: private OnceAndOnlyOnceProtocolNetworkLayer oooLayer;
22: private final boolean isClient;
23:
24: OOONetworkStackHarness(ServerMessageChannelFactory channelFactory,
25: MessageTransport transport,
26: OnceAndOnlyOnceProtocolNetworkLayerFactory factory,
27: Sink sink) {
28: super (channelFactory, transport);
29: this .isClient = false;
30: this .factory = factory;
31: this .sink = sink;
32: }
33:
34: OOONetworkStackHarness(MessageTransportFactory transportFactory,
35: MessageChannelInternal channel,
36: OnceAndOnlyOnceProtocolNetworkLayerFactory factory,
37: Sink sink) {
38: super (transportFactory, channel);
39: this .isClient = true;
40: this .factory = factory;
41: this .sink = sink;
42: }
43:
44: protected void connectStack() {
45: channel.setSendLayer(oooLayer);
46: oooLayer.setReceiveLayer(channel);
47: oooLayer.addTransportListener(channel);
48:
49: transport.setAllowConnectionReplace(true);
50:
51: oooLayer.setSendLayer(transport);
52: transport.setReceiveLayer(oooLayer);
53:
54: final long timeout = TCPropertiesImpl.getProperties().getLong(
55: "l1.reconnect.timeout.millis");
56: // XXX: this is super ugly, but...
57: if (transport instanceof ClientMessageTransport) {
58: ClientMessageTransport cmt = (ClientMessageTransport) transport;
59: ClientConnectionEstablisher cce = cmt
60: .getConnectionEstablisher();
61: OOOConnectionWatcher cw = new OOOConnectionWatcher(cmt,
62: cce, oooLayer, timeout);
63: cmt.addTransportListener(cw);
64: } else {
65: OOOReconnectionTimeout ort = new OOOReconnectionTimeout(
66: oooLayer, timeout);
67: transport.addTransportListener(ort);
68: }
69: }
70:
71: protected void createIntermediateLayers() {
72: oooLayer = (isClient) ? factory.createNewClientInstance(sink)
73: : factory.createNewServerInstance(sink);
74: }
75: }
|