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.management.remote.protocol.terracotta;
05:
06: import java.io.IOException;
07: import java.util.Map;
08:
09: import javax.management.remote.JMXServiceURL;
10: import javax.management.remote.generic.MessageConnection;
11: import javax.management.remote.generic.MessageConnectionServer;
12:
13: public final class TunnelingMessageConnectionServer implements
14: MessageConnectionServer {
15:
16: public static final String TUNNELING_HANDLER = TunnelingMessageConnectionServer.class
17: .getName()
18: + ".tunnelingHandler";
19:
20: private final JMXServiceURL address;
21: private TunnelingEventHandler handler;
22:
23: TunnelingMessageConnectionServer(final JMXServiceURL address) {
24: this .address = address;
25: }
26:
27: public MessageConnection accept() throws IOException {
28: TunnelingEventHandler h;
29: synchronized (this ) {
30: if (handler == null)
31: throw new IOException("Not yet started");
32: h = handler;
33: }
34: return h.accept();
35: }
36:
37: public JMXServiceURL getAddress() {
38: return address;
39: }
40:
41: public synchronized void start(final Map environment)
42: throws IOException {
43: handler = (TunnelingEventHandler) environment
44: .get(TUNNELING_HANDLER);
45: if (handler == null) {
46: throw new IOException(
47: "Tunneling event handler must be defined in the start environment");
48: }
49: }
50:
51: public synchronized void stop() throws IOException {
52: handler = null;
53: }
54:
55: }
|