KickJava   Java API By Example, From Geeks To Geeks.

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


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