KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > management > impl > JMXConnectorServerFactory


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.management.impl;
16
17 import java.util.HashMap JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import javax.management.MBeanServer JavaDoc;
22 import javax.management.remote.JMXConnectorServer JavaDoc;
23 import javax.management.remote.JMXServiceURL JavaDoc;
24
25 import org.apache.hivemind.ApplicationRuntimeException;
26 import org.apache.hivemind.ServiceImplementationFactory;
27 import org.apache.hivemind.ServiceImplementationFactoryParameters;
28 import org.apache.hivemind.management.ManagementMessages;
29
30 /**
31  * An implementation of {@link org.apache.hivemind.ServiceImplementationFactory} that creates
32  * JMXConnectorServer instances using {@link javax.management.remote.JMXConnectorServerFactory}
33  *
34  * @author Achim Huegen
35  * @since 1.1
36  */

37 public class JMXConnectorServerFactory implements ServiceImplementationFactory
38 {
39     public JMXConnectorServerFactory(MBeanServer JavaDoc beanServer)
40     {
41     }
42
43     public Object JavaDoc createCoreServiceImplementation(
44             ServiceImplementationFactoryParameters factoryParameters)
45     {
46         // Read the parameters of the factory call
47
List JavaDoc parameterList = (List JavaDoc) factoryParameters.getParametersContainer();
48         JMXConnectorServerParameter parameter = (JMXConnectorServerParameter) parameterList.get(0);
49
50         Map JavaDoc env = new HashMap JavaDoc();
51
52         try
53         {
54             // Convert the serviceUrl string to instance of JMXServiceURL
55
JMXServiceURL JavaDoc address = new JMXServiceURL JavaDoc(parameter.getJmxServiceURL());
56
57             JMXConnectorServer JavaDoc server = javax.management.remote.JMXConnectorServerFactory
58                     .newJMXConnectorServer(address, env, null);
59
60             return server;
61         }
62         catch (Exception JavaDoc e)
63         {
64             throw new ApplicationRuntimeException(ManagementMessages
65                     .errorInstantiatingConnectorServer(parameter.getJmxServiceURL(), env, e), e);
66         }
67     }
68
69 }
Popular Tags