author | dfuchs |
Thu, 04 Sep 2008 14:46:36 +0200 | |
changeset 1156 | bbc2d15aaf7a |
child 1222 | 78e3d021d528 |
permissions | -rw-r--r-- |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
1 |
/* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
4 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
8 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
14 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
18 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
21 |
* have any questions. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
22 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
23 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
24 |
import java.util.Random; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
25 |
import java.util.Set; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
26 |
import javax.management.AttributeChangeNotification; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
27 |
import javax.management.ListenerNotFoundException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
28 |
import javax.management.MBeanAttributeInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
29 |
import javax.management.MBeanInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
30 |
import javax.management.MBeanNotificationInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
31 |
import javax.management.MBeanOperationInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
32 |
import javax.management.MBeanParameterInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
33 |
import javax.management.MBeanRegistration; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
34 |
import javax.management.MBeanServer; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
35 |
import javax.management.NotCompliantMBeanException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
36 |
import javax.management.NotificationBroadcasterSupport; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
37 |
import javax.management.NotificationEmitter; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
38 |
import javax.management.NotificationFilter; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
39 |
import javax.management.NotificationListener; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
40 |
import javax.management.ObjectName; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
41 |
import javax.management.StandardMBean; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
42 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
43 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
44 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
45 |
* Dynamic MBean based on StandardMBean |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
46 |
* Class Wombat |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
47 |
* Wombat Description |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
48 |
* @author dfuchs |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
49 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
50 |
public class Wombat extends StandardMBean |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
51 |
implements WombatMBean, NotificationEmitter, MBeanRegistration { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
52 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
53 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
54 |
* Attribute : Caption |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
55 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
56 |
private String caption = "I'm a wombat"; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
57 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
58 |
private final long MAX_SEED = 36000; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
59 |
private final long seed; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
60 |
private final long period; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
61 |
private volatile int mood = 0; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
62 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
63 |
public int getMood() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
64 |
final long degree = seed + (System.currentTimeMillis()/period)%MAX_SEED; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
65 |
final double angle = ((double)degree)/100; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
66 |
mood = (int)(100.0*Math.sin(angle)); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
67 |
return mood; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
68 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
69 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
70 |
public Wombat() throws NotCompliantMBeanException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
71 |
super(WombatMBean.class); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
72 |
final Random r = new Random(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
73 |
seed = ((r.nextLong() % MAX_SEED) + MAX_SEED)%MAX_SEED; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
74 |
period = 200 + (((r.nextLong()%80)+80)%80)*10; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
75 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
76 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
77 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
78 |
* Next are the methods to compute MBeanInfo. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
79 |
* You shouldn't update these methods. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
80 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
81 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
82 |
protected String getDescription(MBeanInfo info) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
83 |
return "Wombats are strange beasts. You will find them down under " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
84 |
"and in some computer programms."; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
85 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
86 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
87 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
88 |
protected String getDescription(MBeanAttributeInfo info) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
89 |
String description = null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
90 |
if (info.getName().equals("Caption")) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
91 |
description = "A simple caption to describe a wombat"; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
92 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
93 |
if (info.getName().equals("Mood")) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
94 |
description = "This Wombat's mood on a [-100,+100] scale."+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
95 |
" -100 means that this wombat is very angry."; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
96 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
97 |
return description; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
98 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
99 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
100 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
101 |
protected String getDescription(MBeanOperationInfo op, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
102 |
MBeanParameterInfo param, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
103 |
int sequence) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
104 |
return null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
105 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
106 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
107 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
108 |
protected String getParameterName(MBeanOperationInfo op, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
109 |
MBeanParameterInfo param, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
110 |
int sequence) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
111 |
return null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
112 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
113 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
114 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
115 |
protected String getDescription(MBeanOperationInfo info) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
116 |
String description = null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
117 |
return description; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
118 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
119 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
120 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
121 |
public MBeanInfo getMBeanInfo() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
122 |
MBeanInfo mbinfo = super.getMBeanInfo(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
123 |
return new MBeanInfo(mbinfo.getClassName(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
124 |
mbinfo.getDescription(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
125 |
mbinfo.getAttributes(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
126 |
mbinfo.getConstructors(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
127 |
mbinfo.getOperations(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
128 |
getNotificationInfo()); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
129 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
130 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
131 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
132 |
* Get A simple caption to describe a wombat |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
133 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
134 |
public synchronized String getCaption() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
135 |
return caption; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
136 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
137 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
138 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
139 |
* Set A simple caption to describe a wombat |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
140 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
141 |
public void setCaption(String value) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
142 |
final String oldValue; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
143 |
synchronized (this) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
144 |
oldValue = caption; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
145 |
caption = value; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
146 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
147 |
final AttributeChangeNotification notif = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
148 |
new AttributeChangeNotification(objectName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
149 |
getNextSeqNumber(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
150 |
System.currentTimeMillis(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
151 |
"Caption changed","Caption", |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
152 |
String.class.getName(),oldValue,value); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
153 |
broadcaster.sendNotification(notif); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
154 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
155 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
156 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
157 |
* MBeanNotification support |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
158 |
* You shouldn't update these methods |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
159 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
160 |
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
161 |
broadcaster.addNotificationListener(listener, filter, handback); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
162 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
163 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
164 |
public MBeanNotificationInfo[] getNotificationInfo() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
165 |
return new MBeanNotificationInfo[] { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
166 |
new MBeanNotificationInfo(new String[] { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
167 |
AttributeChangeNotification.ATTRIBUTE_CHANGE}, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
168 |
javax.management.AttributeChangeNotification.class.getName(), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
169 |
"Sent when the caption changes") |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
170 |
}; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
171 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
172 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
173 |
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
174 |
broadcaster.removeNotificationListener(listener); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
175 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
176 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
177 |
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
178 |
broadcaster.removeNotificationListener(listener, filter, handback); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
179 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
180 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
181 |
private synchronized long getNextSeqNumber() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
182 |
return seqNumber++; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
183 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
184 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
185 |
private long seqNumber; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
186 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
187 |
private final NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
188 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
189 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
190 |
* Allows the MBean to perform any operations it needs before being |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
191 |
* registered in the MBean server. If the name of the MBean is not |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
192 |
* specified, the MBean can provide a name for its registration. If |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
193 |
* any exception is raised, the MBean will not be registered in the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
194 |
* MBean server. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
195 |
* @param server The MBean server in which the MBean will be registered. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
196 |
* @param name The object name of the MBean. This name is null if the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
197 |
* name parameter to one of the createMBean or registerMBean methods in |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
198 |
* the MBeanServer interface is null. In that case, this method must |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
199 |
* return a non-null ObjectName for the new MBean. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
200 |
* @return The name under which the MBean is to be registered. This value |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
201 |
* must not be null. If the name parameter is not null, it will usually |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
202 |
* but not necessarily be the returned value. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
203 |
* @throws Exception This exception will be caught by the MBean server and |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
204 |
* re-thrown as an MBeanRegistrationException. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
205 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
206 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
207 |
public ObjectName preRegister(MBeanServer server, ObjectName name) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
208 |
throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
209 |
objectName = name; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
210 |
mbeanServer = server; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
211 |
return super.preRegister(server, name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
212 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
213 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
214 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
215 |
* Allows the MBean to perform any operations needed after having |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
216 |
* been registered in the MBean server or after the registration has |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
217 |
* failed. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
218 |
* @param registrationDone Indicates wether or not the MBean has been |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
219 |
* successfully registered in the MBean server. The value false means |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
220 |
* that the registration has failed. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
221 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
222 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
223 |
public void postRegister(Boolean registrationDone) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
224 |
super.postRegister(registrationDone); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
225 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
226 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
227 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
228 |
* Allows the MBean to perform any operations it needs before being |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
229 |
* unregistered by the MBean server. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
230 |
* @throws Exception This exception will be caught by the MBean server and |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
231 |
* re-thrown as an MBeanRegistrationException. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
232 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
233 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
234 |
public void preDeregister() throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
235 |
super.preDeregister(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
236 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
237 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
238 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
239 |
* Allows the MBean to perform any operations needed after having been |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
240 |
* unregistered in the MBean server. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
241 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
242 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
243 |
public void postDeregister() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
244 |
super.postDeregister(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
245 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
246 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
247 |
public Set<ObjectName> listMatching(ObjectName pattern) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
248 |
return mbeanServer.queryNames(pattern, null); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
249 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
250 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
251 |
private MBeanServer mbeanServer; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
252 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
253 |
private ObjectName objectName; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
254 |
} |