01: package org.concern.client.remote;
02:
03: import java.util.Map;
04: import org.concern.Controller;
05: import org.concern.ControllerException;
06: import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
07:
08: import javax.naming.InitialContext;
09: import javax.naming.NamingException;
10: import javax.management.ObjectName;
11: import javax.management.MalformedObjectNameException;
12: import java.lang.reflect.Proxy;
13:
14: public class JBossConnector implements ControllerConnector {
15: private static String adapterName = "jmx/invoker/RMIAdaptor";
16:
17: public Controller connect(String name, Map environment) {
18: try {
19: RMIAdaptor adaptor = (RMIAdaptor) new InitialContext()
20: .lookup(adapterName);
21:
22: ObjectName objectName = new ObjectName(name);
23: JBossProxyHandler handler = new JBossProxyHandler(adaptor,
24: objectName);
25: Class[] ifaces = { Controller.class };
26: ClassLoader loader = Thread.currentThread()
27: .getContextClassLoader();
28: loader = ClassLoader.getSystemClassLoader();
29: return (Controller) Proxy.newProxyInstance(loader, ifaces,
30: handler);
31: } catch (NamingException e) {
32: throw new ControllerException(e);
33: } catch (MalformedObjectNameException e) {
34: throw new ControllerException(e);
35: }
36: }
37: }
|