KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > management > remote > protocol > terracotta > TunnelingMessageConnectionServer


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.management.remote.protocol.terracotta;
5
6 import java.io.IOException JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import javax.management.remote.JMXServiceURL JavaDoc;
10 import javax.management.remote.generic.MessageConnection;
11 import javax.management.remote.generic.MessageConnectionServer;
12
13 public final class TunnelingMessageConnectionServer implements MessageConnectionServer {
14
15   public static final String JavaDoc TUNNELING_HANDLER = TunnelingMessageConnectionServer.class.getName()
16                                                     + ".tunnelingHandler";
17
18   private final JMXServiceURL JavaDoc address;
19   private TunnelingEventHandler handler;
20
21   TunnelingMessageConnectionServer(final JMXServiceURL JavaDoc address) {
22     this.address = address;
23   }
24
25   public MessageConnection accept() throws IOException JavaDoc {
26     TunnelingEventHandler h;
27     synchronized (this) {
28       if (handler == null) throw new IOException JavaDoc("Not yet started");
29       h = handler;
30     }
31     return h.accept();
32   }
33
34   public JMXServiceURL JavaDoc getAddress() {
35     return address;
36   }
37
38   public synchronized void start(final Map JavaDoc environment) throws IOException JavaDoc {
39     handler = (TunnelingEventHandler) environment.get(TUNNELING_HANDLER);
40     if (handler == null) { throw new IOException JavaDoc("Tunneling event handler must be defined in the start environment"); }
41   }
42
43   public synchronized void stop() throws IOException JavaDoc {
44     handler = null;
45   }
46
47 }
48
Popular Tags