1 12 13 package org.ejtools.jmx.browser.model.connector; 14 15 16 17 import java.lang.reflect.Constructor ; 18 19 import java.lang.reflect.Method ; 20 21 import java.util.Hashtable ; 22 23 24 25 import javax.naming.Context ; 26 27 import javax.naming.InitialContext ; 28 29 import javax.rmi.PortableRemoteObject ; 30 31 32 33 import org.ejtools.jmx.MBeanServerProxy; 34 35 import org.ejtools.jmx.browser.model.service.ConnectionMetaData; 36 37 38 39 40 41 50 51 public class JBoss30RMIConnectionService extends AbstractConnectionService 52 53 { 54 55 56 57 protected Object connector = null; 58 59 60 61 62 63 64 65 public JBoss30RMIConnectionService() 66 67 { 68 69 } 70 71 72 73 74 75 76 77 public void disconnect() 78 79 { 80 81 super.disconnect(); 82 83 try 84 85 { 86 87 89 Method m = this.connector.getClass().getMethod("stop", new Class [0]); 90 91 m.invoke(this.connector, new Object [0]); 92 93 } 94 95 catch (Exception e) 96 97 { 98 99 101 } 102 103 this.setConnected(false); 104 105 } 106 107 108 109 110 111 112 113 118 119 protected void createMBeanServer() 120 121 throws Exception 122 123 { 124 125 System.setProperty("jmx.serial.form", "1.1"); 126 127 128 129 Hashtable props = new Hashtable (); 130 131 props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY)); 132 133 props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES)); 134 135 props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL)); 136 137 props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL)); 138 139 props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS)); 140 141 142 143 InitialContext context = new InitialContext (props); 144 145 Object ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT)); 146 147 148 149 Class clazzAdaptor = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.rmi.RMIAdaptor"); 150 151 Object adaptor = PortableRemoteObject.narrow(ref, clazzAdaptor); 152 153 Class clazzConnector = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.connector.rmi.RMIConnectorImpl"); 154 155 Constructor constructor = clazzConnector.getConstructor(new Class []{clazzAdaptor}); 156 157 this.connector = constructor.newInstance(new Object []{adaptor}); 158 159 160 161 this.setMBeanServer(MBeanServerProxy.createMBeanProxy(this.connector)); 162 163 } 164 165 } 166 167 | Popular Tags |