1 package org.sapia.soto.jmx; 2 3 import org.sapia.soto.Layer; 4 import org.sapia.soto.ServiceMetaData; 5 import org.sapia.soto.jmx.config.Attributes; 6 import org.sapia.soto.jmx.config.Operations; 7 8 import javax.management.DynamicMBean ; 9 import javax.management.ObjectName ; 10 11 12 21 public class JmxLayer implements Layer { 22 public static final String DEFAULT_DOMAIN = "soto"; 23 private Attributes _attributes = new Attributes(); 24 private Operations _operations = new Operations(); 25 private JmxService _service; 26 private DynamicMBean _mbean; 27 private ObjectName _name; 28 private String _domain = DEFAULT_DOMAIN; 29 private String _serviceName; 30 private String _description; 31 32 35 public JmxLayer() { 36 super(); 37 } 38 39 public Operations createOperations() { 40 return _operations; 41 } 42 43 public Attributes createAttributes() { 44 return _attributes; 45 } 46 47 public void setDomain(String domain) { 48 _domain = domain; 49 } 50 51 public void setDescription(String desc) { 52 _description = desc; 53 } 54 55 public void setServiceName(String name) { 56 _serviceName = name; 57 } 58 59 62 public void init(ServiceMetaData meta) throws Exception { 63 MBeanDescriptor mbeanDesc = MBeanDescriptor.newInstanceFor(meta.getService()); 64 65 _attributes.init(mbeanDesc); 66 _operations.init(mbeanDesc); 67 68 mbeanDesc.setDescription(_description); 69 mbeanDesc.init(); 70 71 _mbean = new DynamicMBeanAdaptor(mbeanDesc); 72 73 if (_serviceName == null) { 74 if (meta.getServiceID() == null) { 75 _serviceName = getClass().getName().replace('.', '/') + "_" + 77 System.currentTimeMillis(); 78 } else { 79 _serviceName = meta.getServiceID(); 81 } 82 } 83 84 _name = new ObjectName (_domain + ":service=" + _serviceName); 86 87 if (_service == null) { 89 JmxServiceFactory.getDefaultInstance().registerMBean(_mbean, _name); 90 } 91 92 _attributes = null; 94 _operations = null; 95 _mbean = null; 96 _name = null; 97 _service = null; 98 } 99 100 103 public void start(ServiceMetaData meta) throws Exception { 104 } 105 106 public void dispose() { 107 } 108 } 109 | Popular Tags |