1 21 22 23 package uk.org.primrose.pool.jmx; 24 25 import javax.management.Attribute ; 26 import javax.management.MBeanServerConnection ; 27 import javax.management.MBeanServerInvocationHandler ; 28 import javax.management.ObjectName ; 29 import javax.management.ObjectInstance ; 30 import javax.management.remote.JMXConnector ; 31 import javax.management.remote.JMXConnectorFactory ; 32 import javax.management.remote.JMXServiceURL ; 33 34 public class RemoteClient { 35 36 public static void main(String [] args) throws Exception { 37 39 String serverName = args[0]; 40 String mbeanName = "PoolController Domain:name=PoolController"; 41 RemoteClient rc = new RemoteClient(); 42 rc.bindJMXConnector(args[0]); 43 rc.doIt(mbeanName, serverName); 44 rc.close(); 45 } 46 47 48 private MBeanServerConnection mbsc = null; 49 private JMXConnector jmxc = null; 50 51 public RemoteClient() { 52 } 53 54 public MBeanServerConnection bindJMXConnector(String host) throws Exception { 55 JMXServiceURL url = new JMXServiceURL ("jmxmp", host, 8091); 59 60 jmxc = JMXConnectorFactory.connect(url, null); 61 mbsc = jmxc.getMBeanServerConnection(); 63 71 return mbsc; 72 73 } 74 75 public void close() throws java.io.IOException { 76 jmxc.close(); 77 } 78 79 public void doIt(String mbeanName, String host) { 80 try { 81 if (mbsc == null) { 82 mbsc = this.bindJMXConnector(host); 83 } 84 ObjectName on = new ObjectName (mbeanName); 85 Object [] params = new Object [] { 86 new String ("show tables") 87 }; 88 String [] signature = new String [] { 89 new String ().getClass().getName() 90 }; 91 92 System.err.println(mbsc.invoke(on, "invokeRemoteDatabaseProc", params, signature)); 93 } catch (Exception e) { 95 e.printStackTrace(); 96 } 97 } 98 99 public void refreshPoolConfigFile(String mbeanName, String host, String poolName) { 100 try { 101 if (mbsc == null) { 102 mbsc = this.bindJMXConnector(host); 103 } 104 ObjectName on = new ObjectName (mbeanName); 105 106 mbsc.invoke(on, "refreshPoolConfigFile", null, null); 108 } catch (Exception e) { 110 e.printStackTrace(); 111 } 112 } 113 114 public Queue getQueue(String mbeanName, String host, String poolName) { 115 try { 116 if (mbsc == null) { 117 mbsc = this.bindJMXConnector(host); 118 } 119 ObjectName on = new ObjectName (mbeanName); 120 Object [] params = new Object [] { 121 poolName 122 }; 123 String [] signature = new String [] { 124 new String ().getClass().getName() 125 }; 126 127 return (Queue)mbsc.invoke(on, "getQueue", params, signature); 128 } catch (Exception e) { 130 e.printStackTrace(System.err); 131 return null; 132 } 133 } 134 135 } 136 | Popular Tags |