01: /*
02: * $Id: JMXConnector.java 674 2006-10-06 12:15:59Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.org).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.client.remote;
15:
16: import java.util.Map;
17: import org.concern.Controller;
18: import org.concern.ControllerException;
19: import org.concern.client.remote.ControllerConnector;
20:
21: import javax.management.remote.JMXConnectorFactory;
22: import javax.management.remote.JMXServiceURL;
23: import javax.management.MBeanServerConnection;
24: import javax.management.ObjectName;
25: import java.lang.reflect.Proxy;
26:
27: public class JMXConnector implements ControllerConnector {
28:
29: public Controller connect(String name, Map env) {
30: try {
31: JMXServiceURL url = new JMXServiceURL(
32: "service:jmx:rmi:///jndi/JMXConnectorServer");
33: javax.management.remote.JMXConnector connector = JMXConnectorFactory
34: .connect(url, env);
35: connector.connect();
36: MBeanServerConnection connection = connector
37: .getMBeanServerConnection();
38: ObjectName objectName = new ObjectName(name);
39: JMXProxyHandler handler = new JMXProxyHandler(connection,
40: objectName);
41: Class[] ifaces = { Controller.class };
42: return (Controller) Proxy.newProxyInstance(Controller.class
43: .getClassLoader(), ifaces, handler);
44: } catch (Exception e) {
45: throw new ControllerException(e);
46: }
47: }
48: }
|