1 48 49 package com.caucho.services.jmx; 50 51 import javax.management.MBeanAttributeInfo; 52 import javax.management.MBeanServer; 53 import javax.management.ObjectName; 54 import javax.management.ObjectInstance; 55 import javax.management.MBeanInfo; 56 import javax.management.JMException; 57 import javax.management.RuntimeMBeanException; 58 59 import com.caucho.hessian.jmx.JMXSerializerFactory; 60 61 import com.caucho.hessian.client.HessianProxyFactory; 62 63 import com.caucho.services.server.GenericService; 64 65 68 public class MBeanClient { 69 private String _url; 70 private RemoteJMX _jmxProxy; 71 72 75 public MBeanClient() 76 { 77 } 78 79 82 public MBeanClient(String url) 83 { 84 _url = url; 85 } 86 87 90 public void setProxy(RemoteJMX proxy) 91 { 92 _jmxProxy = proxy; 93 } 94 95 98 public MBeanInfo getMBeanInfo(ObjectName objectName) 99 throws Exception 100 { 101 return getProxy().getMBeanInfo(objectName.getCanonicalName()); 102 } 103 104 107 public Object getAttribute(ObjectName objectName, String attrName) 108 throws Exception 109 { 110 return getProxy().getAttribute(objectName.getCanonicalName(), attrName); 111 } 112 113 private RemoteJMX getProxy() 114 { 115 if (_jmxProxy == null) { 116 try { 117 HessianProxyFactory proxy = new HessianProxyFactory(); 118 proxy.getSerializerFactory().addFactory(new JMXSerializerFactory()); 119 _jmxProxy = (RemoteJMX) proxy.create(_url); 120 } catch (Exception e) { 121 throw new RuntimeException(e); 122 } 123 } 124 125 return _jmxProxy; 126 } 127 } 128 | Popular Tags |