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