1 22 package org.jboss.test; 23 24 25 import org.jboss.logging.Logger; 26 27 import javax.management.MBeanInfo ; 28 import javax.management.MBeanServerConnection ; 29 import javax.management.ObjectName ; 30 import javax.naming.Context ; 31 import javax.naming.InitialContext ; 32 import javax.naming.NamingException ; 33 import java.util.Hashtable ; 34 35 36 44 45 public class JBossRMIAdaptorHelper 46 { 47 protected MBeanServerConnection rmiserver = null; 48 protected Logger log = Logger.getLogger(JBossRMIAdaptorHelper.class); 49 50 53 public JBossRMIAdaptorHelper() 54 { 55 } 56 57 62 public JBossRMIAdaptorHelper(String jndiurl) 63 { 64 this(); 65 try 66 { 67 Hashtable env = new Hashtable (); 69 env.put(Context.PROVIDER_URL, jndiurl); 70 env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 71 env.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces"); 72 getMBeanServer(new InitialContext (env)); 73 } catch (Exception e) 74 { 75 log.debug(e); 76 } 77 } 78 79 84 public JBossRMIAdaptorHelper(InitialContext ctx) 85 { 86 this(); 87 getMBeanServer(ctx); 88 } 89 90 91 97 public MBeanInfo getMBeanInfo(ObjectName oname) 98 { 99 103 MBeanInfo info = null; 104 105 try 106 { 107 info = rmiserver.getMBeanInfo(oname); 108 } catch (Exception e) 109 { 110 log.debug(e); 111 } 112 return info; 113 } 114 115 125 public Object invokeOperation(ObjectName oname, 126 String methodname, Object [] pParams, 127 String [] pSignature) 128 throws Exception 129 { 130 Object result = null; 131 try 132 { 133 137 result = rmiserver.invoke(oname, methodname, pParams, pSignature); 138 } catch (Exception e) 139 { 140 log.debug(e); 141 } 142 143 return result; 144 } 145 146 private void getMBeanServer(InitialContext ctx) 147 { 148 if (ctx == null) 149 throw new IllegalArgumentException ("Initial Context passed is null"); 150 try 151 { 152 rmiserver = (MBeanServerConnection ) ctx.lookup("jmx/invoker/RMIAdaptor"); 153 } catch (NamingException e) 154 { 155 log.debug(e); 156 } 157 if (rmiserver == null) log.debug("RMIAdaptor is null"); 158 159 } 160 161 162 } | Popular Tags |