01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.protocol;
06:
07: import com.tc.net.protocol.tcm.MessageChannelInternal;
08: import com.tc.net.protocol.tcm.ServerMessageChannelFactory;
09: import com.tc.net.protocol.transport.ClientConnectionEstablisher;
10: import com.tc.net.protocol.transport.ClientMessageTransport;
11: import com.tc.net.protocol.transport.ConnectionWatcher;
12: import com.tc.net.protocol.transport.MessageTransport;
13: import com.tc.net.protocol.transport.MessageTransportFactory;
14: import com.tc.net.protocol.transport.MessageTransportListener;
15:
16: /**
17: * Plain (no guarenteed messages) network stack harness factory
18: */
19: public class PlainNetworkStackHarnessFactory implements
20: NetworkStackHarnessFactory {
21:
22: private final boolean allowConnectionReplace;
23:
24: public PlainNetworkStackHarnessFactory() {
25: this (false);
26: }
27:
28: public PlainNetworkStackHarnessFactory(
29: boolean allowConnectionReplace) {
30: this .allowConnectionReplace = allowConnectionReplace;
31: }
32:
33: public NetworkStackHarness createServerHarness(
34: ServerMessageChannelFactory channelFactory,
35: MessageTransport transport,
36: MessageTransportListener[] transportListeners) {
37: return new PlainNetworkStackHarness(channelFactory, transport);
38: }
39:
40: public NetworkStackHarness createClientHarness(
41: MessageTransportFactory transportFactory,
42: MessageChannelInternal channel,
43: MessageTransportListener[] transportListeners) {
44: return new PlainNetworkStackHarness(transportFactory, channel);
45: }
46:
47: private class PlainNetworkStackHarness extends
48: AbstractNetworkStackHarness {
49:
50: PlainNetworkStackHarness(
51: ServerMessageChannelFactory channelFactory,
52: MessageTransport transport) {
53: super (channelFactory, transport);
54: }
55:
56: PlainNetworkStackHarness(
57: MessageTransportFactory transportFactory,
58: MessageChannelInternal channel) {
59: super (transportFactory, channel);
60: }
61:
62: protected void connectStack() {
63: channel.setSendLayer(transport);
64: transport.setReceiveLayer(channel);
65: transport.setAllowConnectionReplace(allowConnectionReplace);
66:
67: // XXX: this is super ugly, but...
68: if (transport instanceof ClientMessageTransport) {
69: ClientMessageTransport cmt = (ClientMessageTransport) transport;
70: ClientConnectionEstablisher cce = cmt
71: .getConnectionEstablisher();
72: ConnectionWatcher cw = new ConnectionWatcher(cmt,
73: channel, cce);
74: transport.addTransportListener(cw);
75: } else {
76: transport.addTransportListener(channel);
77: }
78: }
79:
80: protected void createIntermediateLayers() {
81: // No intermediate layers to create.
82: }
83: }
84: }
|