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.net.MalformedURLException;
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: import javax.management.remote.JMXConnector;
12: import javax.management.remote.JMXConnectorProvider;
13: import javax.management.remote.JMXServiceURL;
14: import javax.management.remote.generic.GenericConnector;
15:
16: import com.tc.net.protocol.tcm.MessageChannel;
17:
18: public class ClientProvider implements JMXConnectorProvider {
19:
20: public static final String JMX_MESSAGE_CHANNEL = "JmxMessageChannel";
21: public static final String CONNECTION_LIST = "channelIdToMsgConnection";
22:
23: public JMXConnector newJMXConnector(
24: final JMXServiceURL jmxserviceurl,
25: final Map initialEnvironment) throws IOException {
26: if (!jmxserviceurl.getProtocol().equals("terracotta")) {
27: MalformedURLException exception = new MalformedURLException(
28: "Protocol not terracotta: "
29: + jmxserviceurl.getProtocol());
30: throw exception;
31: }
32: final Map terracottaEnvironment = initialEnvironment != null ? new HashMap(
33: initialEnvironment)
34: : new HashMap();
35: final MessageChannel channel = (MessageChannel) terracottaEnvironment
36: .remove(JMX_MESSAGE_CHANNEL);
37: final TunnelingMessageConnection tmc = new TunnelingMessageConnection(
38: channel, false);
39: final Map channelIdToMsgConnection = (Map) terracottaEnvironment
40: .remove(CONNECTION_LIST);
41: synchronized (channelIdToMsgConnection) {
42: channelIdToMsgConnection.put(channel.getChannelID(), tmc);
43: }
44: terracottaEnvironment.put(GenericConnector.MESSAGE_CONNECTION,
45: tmc);
46: return new GenericConnector(terracottaEnvironment);
47: }
48:
49: }
|