KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > jmx > JmxLayer


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 JavaDoc;
9 import javax.management.ObjectName JavaDoc;
10
11
12 /**
13  * @author Yanick Duchesne
14  * 27-Aug-2003
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class JmxLayer implements Layer {
22   public static final String JavaDoc DEFAULT_DOMAIN = "soto";
23   private Attributes _attributes = new Attributes();
24   private Operations _operations = new Operations();
25   private JmxService _service;
26   private DynamicMBean JavaDoc _mbean;
27   private ObjectName JavaDoc _name;
28   private String JavaDoc _domain = DEFAULT_DOMAIN;
29   private String JavaDoc _serviceName;
30   private String JavaDoc _description;
31
32   /**
33    * Constructor for JmxLayer.
34    */

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 JavaDoc domain) {
48     _domain = domain;
49   }
50
51   public void setDescription(String JavaDoc desc) {
52     _description = desc;
53   }
54
55   public void setServiceName(String JavaDoc name) {
56     _serviceName = name;
57   }
58
59   /**
60    * @see org.sapia.soto.Layer#init(ServiceMetaData)
61    */

62   public void init(ServiceMetaData meta) throws Exception JavaDoc {
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         // assigning a "default" service name.
76
_serviceName = getClass().getName().replace('.', '/') + "_" +
77           System.currentTimeMillis();
78       } else {
79         // using service ID...
80
_serviceName = meta.getServiceID();
81       }
82     }
83
84     // building ObjectName...
85
_name = new ObjectName JavaDoc(_domain + ":service=" + _serviceName);
86
87     // here register mbean...
88
if (_service == null) {
89       JmxServiceFactory.getDefaultInstance().registerMBean(_mbean, _name);
90     }
91
92     // allow GC...
93
_attributes = null;
94     _operations = null;
95     _mbean = null;
96     _name = null;
97     _service = null;
98   }
99
100   /**
101    * @see org.sapia.soto.Layer#start(org.sapia.soto.ServiceMetaData)
102    */

103   public void start(ServiceMetaData meta) throws Exception JavaDoc {
104   }
105
106   public void dispose() {
107   }
108 }
109
Popular Tags