author | emcmanus |
Thu, 27 Nov 2008 15:44:32 +0100 | |
changeset 1636 | eb801ce73ac9 |
parent 1247 | b4c26443dee5 |
permissions | -rw-r--r-- |
1004 | 1 |
/* |
1247 | 2 |
* Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. |
1004 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test DynamicWrapperMBeanTest |
|
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
26 |
* @bug 6624232 6776225 |
1004 | 27 |
* @summary Test the DynamicWrapperMBean interface |
28 |
* @author Eamonn McManus |
|
29 |
*/ |
|
30 |
||
31 |
import java.lang.management.ManagementFactory; |
|
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
32 |
import javax.annotation.Resource; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
33 |
import javax.management.JMX; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
34 |
import javax.management.ListenerNotFoundException; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
35 |
import javax.management.MBeanNotificationInfo; |
1004 | 36 |
import javax.management.MBeanServer; |
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
37 |
import javax.management.Notification; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
38 |
import javax.management.NotificationBroadcaster; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
39 |
import javax.management.NotificationBroadcasterSupport; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
40 |
import javax.management.NotificationEmitter; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
41 |
import javax.management.NotificationFilter; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
42 |
import javax.management.NotificationInfo; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
43 |
import javax.management.NotificationListener; |
1004 | 44 |
import javax.management.ObjectName; |
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
45 |
import javax.management.SendNotification; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
46 |
import javax.management.StandardEmitterMBean; |
1004 | 47 |
import javax.management.StandardMBean; |
48 |
import javax.management.modelmbean.ModelMBeanInfo; |
|
49 |
import javax.management.modelmbean.ModelMBeanInfoSupport; |
|
50 |
import javax.management.modelmbean.ModelMBeanOperationInfo; |
|
51 |
import javax.management.modelmbean.RequiredModelMBean; |
|
52 |
import static javax.management.StandardMBean.Options; |
|
53 |
||
54 |
public class DynamicWrapperMBeanTest { |
|
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
55 |
private static String failure; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
56 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
57 |
public static void main(String[] args) throws Exception { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
58 |
wrapTest(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
59 |
notifTest(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
60 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
61 |
if (failure == null) |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
62 |
System.out.println("TEST PASSED"); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
63 |
else |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
64 |
throw new Exception("TEST FAILED: " + failure); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
65 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
66 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
67 |
private static final Options wrappedVisOpts = new Options(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
68 |
private static final Options wrappedInvisOpts = new Options(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
69 |
static { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
70 |
wrappedVisOpts.setWrappedObjectVisible(true); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
71 |
wrappedInvisOpts.setWrappedObjectVisible(false); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
72 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
73 |
|
1004 | 74 |
public static interface WrappedMBean { |
75 |
public void sayHello(); |
|
76 |
} |
|
77 |
public static class Wrapped implements WrappedMBean { |
|
78 |
public void sayHello() { |
|
79 |
System.out.println("Hello"); |
|
80 |
} |
|
81 |
} |
|
82 |
||
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
83 |
private static void wrapTest() throws Exception { |
1004 | 84 |
if (Wrapped.class.getClassLoader() == |
85 |
StandardMBean.class.getClassLoader()) { |
|
86 |
throw new Exception( |
|
87 |
"TEST ERROR: Resource and StandardMBean have same ClassLoader"); |
|
88 |
} |
|
89 |
||
90 |
assertEquals("Options withWrappedObjectVisible(false)", |
|
91 |
new Options(), wrappedInvisOpts); |
|
92 |
||
93 |
Wrapped resource = new Wrapped(); |
|
94 |
||
95 |
StandardMBean visible = |
|
96 |
new StandardMBean(resource, WrappedMBean.class, wrappedVisOpts); |
|
97 |
StandardMBean invisible = |
|
98 |
new StandardMBean(resource, WrappedMBean.class, wrappedInvisOpts); |
|
99 |
||
100 |
assertEquals("getResource withWrappedObjectVisible(true)", |
|
101 |
resource, visible.getWrappedObject()); |
|
102 |
assertEquals("getResource withWrappedObjectVisible(false)", |
|
103 |
invisible, invisible.getWrappedObject()); |
|
104 |
||
105 |
System.out.println("===Testing StandardMBean==="); |
|
106 |
||
107 |
ObjectName visibleName = new ObjectName("a:type=visible"); |
|
108 |
ObjectName invisibleName = new ObjectName("a:type=invisible"); |
|
109 |
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); |
|
110 |
mbs.registerMBean(visible, visibleName); |
|
111 |
mbs.registerMBean(invisible, invisibleName); |
|
112 |
||
113 |
assertEquals("ClassLoader for visible resource", |
|
114 |
Wrapped.class.getClassLoader(), |
|
115 |
mbs.getClassLoaderFor(visibleName)); |
|
116 |
assertEquals("ClassLoader for invisible resource", |
|
117 |
StandardMBean.class.getClassLoader(), |
|
118 |
mbs.getClassLoaderFor(invisibleName)); |
|
119 |
||
120 |
assertEquals("isInstanceOf(WrappedMBean) for visible wrapped", |
|
121 |
true, mbs.isInstanceOf(visibleName, WrappedMBean.class.getName())); |
|
122 |
assertEquals("isInstanceOf(WrappedMBean) for invisible wrapped", |
|
123 |
false, mbs.isInstanceOf(invisibleName, WrappedMBean.class.getName())); |
|
124 |
assertEquals("isInstanceOf(StandardMBean) for visible wrapped", |
|
125 |
false, mbs.isInstanceOf(visibleName, StandardMBean.class.getName())); |
|
126 |
assertEquals("isInstanceOf(StandardMBean) for invisible wrapped", |
|
127 |
true, mbs.isInstanceOf(invisibleName, StandardMBean.class.getName())); |
|
128 |
||
129 |
mbs.unregisterMBean(visibleName); |
|
130 |
mbs.unregisterMBean(invisibleName); |
|
131 |
||
132 |
System.out.println("===Testing RequiredModelMBean==="); |
|
133 |
||
134 |
// Godawful Model MBeans... |
|
135 |
ModelMBeanOperationInfo mmboi = new ModelMBeanOperationInfo( |
|
136 |
"say hello to the nice man", Wrapped.class.getMethod("sayHello")); |
|
137 |
ModelMBeanInfo visibleMmbi = new ModelMBeanInfoSupport( |
|
138 |
Wrapped.class.getName(), "Visible wrapped", null, null, |
|
139 |
new ModelMBeanOperationInfo[] {mmboi}, null); |
|
140 |
ModelMBeanInfo invisibleMmbi = new ModelMBeanInfoSupport( |
|
141 |
Wrapped.class.getName(), "Invisible wrapped", null, null, |
|
142 |
new ModelMBeanOperationInfo[] {mmboi}, null); |
|
143 |
RequiredModelMBean visibleRmmb = new RequiredModelMBean(visibleMmbi); |
|
144 |
RequiredModelMBean invisibleRmmb = new RequiredModelMBean(invisibleMmbi); |
|
145 |
visibleRmmb.setManagedResource(resource, "VisibleObjectReference"); |
|
146 |
invisibleRmmb.setManagedResource(resource, "ObjectReference"); |
|
147 |
||
148 |
mbs.registerMBean(visibleRmmb, visibleName); |
|
149 |
mbs.registerMBean(invisibleRmmb, invisibleName); |
|
150 |
||
151 |
assertEquals("ClassLoader for visible wrapped", |
|
152 |
Wrapped.class.getClassLoader(), |
|
153 |
mbs.getClassLoaderFor(visibleName)); |
|
154 |
assertEquals("ClassLoader for invisible wrapped", |
|
155 |
StandardMBean.class.getClassLoader(), |
|
156 |
mbs.getClassLoaderFor(invisibleName)); |
|
157 |
||
158 |
assertEquals("isInstanceOf(WrappedMBean) for visible resource", |
|
159 |
true, mbs.isInstanceOf(visibleName, WrappedMBean.class.getName())); |
|
160 |
assertEquals("isInstanceOf(WrappedMBean) for invisible resource", |
|
161 |
false, mbs.isInstanceOf(invisibleName, WrappedMBean.class.getName())); |
|
162 |
assertEquals("isInstanceOf(RequiredModelMBean) for visible resource", |
|
163 |
false, mbs.isInstanceOf(visibleName, RequiredModelMBean.class.getName())); |
|
164 |
assertEquals("isInstanceOf(RequiredModelMBean) for invisible resource", |
|
165 |
true, mbs.isInstanceOf(invisibleName, RequiredModelMBean.class.getName())); |
|
166 |
||
1636
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
167 |
mbs.unregisterMBean(visibleName); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
168 |
mbs.unregisterMBean(invisibleName); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
169 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
170 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
171 |
private static enum WrapType { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
172 |
NBS("NotificationBroadcasterSupport"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
173 |
INJ("@Resource SendNotification"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
174 |
STD_MBEAN_NBS("StandardMBean delegating to NotificationBroadcasterSupport"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
175 |
STD_MBEAN_INJ("StandardMBean delegating to @Resource SendNotification"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
176 |
STD_MBEAN_SUB_NBS("StandardMBean subclass implementing NotificationBroadcaster"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
177 |
STD_MBEAN_SUB_INJ("StandardMBean subclass with @Resource SendNotification"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
178 |
STD_EMIT_MBEAN_NBS("StandardEmitterMBean delegating to NotificationBroadcasterSupport"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
179 |
STD_EMIT_MBEAN_INJ("StandardEmitterMBean delegating to @Resource SendNotification"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
180 |
STD_EMIT_MBEAN_SUB("StandardEmitterMBean subclass"), |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
181 |
STD_EMIT_MBEAN_SUB_INJ("StandardEmitterMBean subclass with @Resource SendNotification"); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
182 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
183 |
WrapType(String s) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
184 |
this.s = s; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
185 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
186 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
187 |
@Override |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
188 |
public String toString() { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
189 |
return s; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
190 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
191 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
192 |
private final String s; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
193 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
194 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
195 |
@NotificationInfo( |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
196 |
types = {"foo", "bar"} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
197 |
) |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
198 |
public static interface BroadcasterMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
199 |
public void send(Notification n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
200 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
201 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
202 |
public static class Broadcaster |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
203 |
extends NotificationBroadcasterSupport implements BroadcasterMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
204 |
public void send(Notification n) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
205 |
super.sendNotification(n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
206 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
207 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
208 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
209 |
public static interface SendNotifMBean extends BroadcasterMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
210 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
211 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
212 |
public static class SendNotif implements SendNotifMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
213 |
@Resource |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
214 |
private volatile SendNotification sendNotif; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
215 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
216 |
public void send(Notification n) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
217 |
sendNotif.sendNotification(n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
218 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
219 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
220 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
221 |
public static class StdBroadcaster |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
222 |
extends StandardMBean |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
223 |
implements BroadcasterMBean, NotificationBroadcaster { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
224 |
private final NotificationBroadcasterSupport nbs = |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
225 |
new NotificationBroadcasterSupport(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
226 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
227 |
public StdBroadcaster() throws Exception { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
228 |
super(BroadcasterMBean.class); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
229 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
230 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
231 |
public void send(Notification n) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
232 |
nbs.sendNotification(n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
233 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
234 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
235 |
public void addNotificationListener(NotificationListener listener, |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
236 |
NotificationFilter filter, Object handback) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
237 |
nbs.addNotificationListener(listener, filter, handback); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
238 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
239 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
240 |
public MBeanNotificationInfo[] getNotificationInfo() { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
241 |
return null; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
242 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
243 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
244 |
public void removeNotificationListener(NotificationListener listener) |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
245 |
throws ListenerNotFoundException { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
246 |
nbs.removeNotificationListener(listener); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
247 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
248 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
249 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
250 |
public static class StdSendNotif |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
251 |
extends StandardMBean implements SendNotifMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
252 |
@Resource |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
253 |
private volatile SendNotification sendNotif; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
254 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
255 |
public StdSendNotif() throws Exception { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
256 |
super(SendNotifMBean.class); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
257 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
258 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
259 |
public void send(Notification n) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
260 |
sendNotif.sendNotification(n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
261 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
262 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
263 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
264 |
public static class StdEmitterBroadcaster // :-) |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
265 |
extends StandardEmitterMBean |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
266 |
implements BroadcasterMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
267 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
268 |
public StdEmitterBroadcaster() throws Exception { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
269 |
super(BroadcasterMBean.class, null); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
270 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
271 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
272 |
public void send(Notification n) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
273 |
super.sendNotification(n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
274 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
275 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
276 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
277 |
// This case is unlikely - if you're using @Resource SendNotification |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
278 |
// then there's no point in using StandardEmitterMBean, since |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
279 |
// StandardMBean would suffice. |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
280 |
public static class StdEmitterSendNotif |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
281 |
extends StandardEmitterMBean implements SendNotifMBean { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
282 |
@Resource |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
283 |
private volatile SendNotification sendNotif; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
284 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
285 |
public StdEmitterSendNotif() { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
286 |
super(SendNotifMBean.class, null); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
287 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
288 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
289 |
public void send(Notification n) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
290 |
sendNotif.sendNotification(n); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
291 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
292 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
293 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
294 |
// Test that JMX.isNotificationSource and |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
295 |
// mbs.isInstanceOf("NotificationBroadcaster") work correctly even when |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
296 |
// the MBean is a broadcaster by virtue of its wrapped resource. |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
297 |
// Test that we find the MBeanNotificationInfo[] from the @NotificationInfo |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
298 |
// annotation on BroadcasterMBean. We cover a large number of different |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
299 |
// MBean types, but all ultimately implement that interface. |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
300 |
private static void notifTest() throws Exception { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
301 |
System.out.println("===Testing notification senders==="); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
302 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
303 |
for (WrapType wrapType : WrapType.values()) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
304 |
System.out.println("---" + wrapType); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
305 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
306 |
final Object mbean; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
307 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
308 |
switch (wrapType) { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
309 |
case NBS: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
310 |
// An MBean that extends NotificationBroadcasterSupport |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
311 |
mbean = new Broadcaster(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
312 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
313 |
case INJ: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
314 |
// An MBean that injects SendNotification |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
315 |
mbean = new SendNotif(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
316 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
317 |
case STD_MBEAN_NBS: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
318 |
// A StandardMBean that delegates to a NotificationBroadcasterSupport |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
319 |
mbean = new StandardMBean( |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
320 |
new Broadcaster(), BroadcasterMBean.class, wrappedVisOpts); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
321 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
322 |
case STD_MBEAN_INJ: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
323 |
// A StandardMBean that delegates to an object that injects |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
324 |
// SendNotification |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
325 |
mbean = new StandardMBean( |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
326 |
new SendNotif(), BroadcasterMBean.class, wrappedVisOpts); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
327 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
328 |
case STD_EMIT_MBEAN_NBS: { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
329 |
// A StandardEmitterMBean that delegates to a NotificationBroadcasterSupport |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
330 |
Broadcaster broadcaster = new Broadcaster(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
331 |
mbean = new StandardEmitterMBean( |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
332 |
broadcaster, BroadcasterMBean.class, wrappedVisOpts, |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
333 |
broadcaster); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
334 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
335 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
336 |
case STD_EMIT_MBEAN_INJ: { |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
337 |
// A StandardEmitterMBean that delegates to an object that injects |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
338 |
// SendNotification |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
339 |
SendNotif sendNotif = new SendNotif(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
340 |
mbean = new StandardEmitterMBean( |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
341 |
sendNotif, BroadcasterMBean.class, wrappedVisOpts, |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
342 |
null); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
343 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
344 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
345 |
case STD_MBEAN_SUB_NBS: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
346 |
// A subclass of StandardMBean that implements NotificationBroadcaster |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
347 |
mbean = new StdBroadcaster(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
348 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
349 |
case STD_MBEAN_SUB_INJ: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
350 |
// A subclass of StandardMBean that injects SendNotification |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
351 |
mbean = new StdSendNotif(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
352 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
353 |
case STD_EMIT_MBEAN_SUB: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
354 |
// A subclass of StandardEmitterMBean |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
355 |
mbean = new StdEmitterBroadcaster(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
356 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
357 |
case STD_EMIT_MBEAN_SUB_INJ: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
358 |
// A subclass of StandardEmitterMBean that injects SendNotification |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
359 |
// (which is a rather strange thing to do and probably a user |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
360 |
// misunderstanding but we should do the right thing anyway). |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
361 |
mbean = new StdEmitterSendNotif(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
362 |
break; |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
363 |
default: |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
364 |
throw new AssertionError(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
365 |
} |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
366 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
367 |
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
368 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
369 |
final ObjectName name = new ObjectName("a:type=Sender"); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
370 |
mbs.registerMBean(mbean, name); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
371 |
boolean isBroadcaster = mbs.isInstanceOf( |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
372 |
name, NotificationBroadcaster.class.getName()); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
373 |
assertEquals("JMX.isNotificationSource(mbean)", |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
374 |
true, JMX.isNotificationSource(mbean)); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
375 |
assertEquals("isInstanceOf(NotificationBroadcaster)", |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
376 |
true, isBroadcaster); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
377 |
MBeanNotificationInfo[] mbnis = |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
378 |
mbs.getMBeanInfo(name).getNotifications(); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
379 |
assertEquals("MBeanNotificationInfo not empty", |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
380 |
true, (mbnis.length > 0)); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
381 |
|
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
382 |
mbs.unregisterMBean(name); |
eb801ce73ac9
6776225: JMX.isNotificationSource wrong when DynamicWrapperMBean + SendNotification injection
emcmanus
parents:
1247
diff
changeset
|
383 |
} |
1004 | 384 |
} |
385 |
||
386 |
private static void assertEquals(String what, Object expect, Object actual) { |
|
387 |
if (equal(expect, actual)) |
|
388 |
System.out.println("OK: " + what + " = " + expect); |
|
389 |
else |
|
390 |
fail(what + " should be " + expect + ", is " + actual); |
|
391 |
} |
|
392 |
||
393 |
private static boolean equal(Object x, Object y) { |
|
394 |
if (x == y) |
|
395 |
return true; |
|
396 |
if (x == null || y == null) |
|
397 |
return false; |
|
398 |
return x.equals(y); |
|
399 |
} |
|
400 |
||
401 |
private static void fail(String why) { |
|
402 |
failure = why; |
|
403 |
System.out.println("FAIL: " + why); |
|
404 |
} |
|
405 |
} |