01: package vicazh.hyperpool;
02:
03: import java.lang.management.*;
04: import javax.management.*;
05:
06: /**
07: * This class is the superclass of all services and selectors
08: *
09: * @author Victor Zhigunov
10: * @version 0.4.0
11: */
12: abstract public class Element extends NotificationBroadcasterSupport
13: implements ElementMBean, Unit {
14: public int getID() {
15: return hashCode();
16: }
17:
18: private long sequenceNumber;
19:
20: private long sourceID;
21:
22: synchronized public void setAttribute(String name, long sourceID,
23: Object value) throws Exception {
24: this .sourceID = sourceID;
25: setAttribute(name, value);
26: }
27:
28: public void setAttribute(String name, Object value)
29: throws Exception {
30: sendNotification(new AttributeNotification(name, this ,
31: ++sequenceNumber, sourceID, value));
32: }
33:
34: public void sendAttribute(String name, Object value) {
35: sendNotification(new AttributeNotification(name, this ,
36: ++sequenceNumber, 0, value));
37: }
38:
39: public void sendAttribute(String name) {
40: sendAttribute(name, null);
41: }
42:
43: private ObjectName objectname;
44:
45: /**
46: * Start element
47: */
48: public void start() throws Exception {
49: if (Start.server) {
50: objectname = new ObjectName("hyperpool:type=" + getID());
51: ManagementFactory.getPlatformMBeanServer().registerMBean(
52: this , objectname);
53: }
54: }
55:
56: /**
57: * Stop element
58: */
59: public void stop() throws Exception {
60: if (Start.server)
61: ManagementFactory.getPlatformMBeanServer().unregisterMBean(
62: objectname);
63: }
64: }
|