author | dfuchs |
Thu, 04 Sep 2008 14:46:36 +0200 | |
changeset 1156 | bbc2d15aaf7a |
parent 1002 | 1e6a1b77f22a |
child 1222 | 78e3d021d528 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.jmx.interceptor; |
|
27 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
28 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
29 |
// JMX RI |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
30 |
import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
31 |
import com.sun.jmx.mbeanserver.DynamicMBean2; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
32 |
import com.sun.jmx.mbeanserver.Introspector; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
33 |
import com.sun.jmx.mbeanserver.MBeanInjector; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
34 |
import com.sun.jmx.mbeanserver.MBeanInstantiator; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
35 |
import com.sun.jmx.mbeanserver.ModifiableClassLoaderRepository; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
36 |
import com.sun.jmx.mbeanserver.NamedObject; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
37 |
import com.sun.jmx.mbeanserver.NotifySupport; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
38 |
import com.sun.jmx.mbeanserver.Repository; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
39 |
import com.sun.jmx.mbeanserver.Repository.RegistrationContext; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
40 |
import com.sun.jmx.mbeanserver.Util; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
41 |
import com.sun.jmx.remote.util.EnvHelp; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
42 |
|
2 | 43 |
import java.lang.ref.WeakReference; |
44 |
import java.security.AccessControlContext; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
45 |
import java.security.AccessController; |
2 | 46 |
import java.security.Permission; |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
47 |
import java.security.PrivilegedAction; |
2 | 48 |
import java.security.ProtectionDomain; |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
49 |
import java.util.ArrayList; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
50 |
import java.util.HashSet; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
51 |
import java.util.Iterator; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
52 |
import java.util.LinkedList; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
53 |
import java.util.List; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
54 |
import java.util.Queue; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
55 |
import java.util.Set; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
56 |
import java.util.WeakHashMap; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
57 |
import java.util.logging.Level; |
2 | 58 |
|
59 |
// JMX import |
|
60 |
import javax.management.Attribute; |
|
61 |
import javax.management.AttributeList; |
|
62 |
import javax.management.AttributeNotFoundException; |
|
63 |
import javax.management.DynamicMBean; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
64 |
import javax.management.DynamicWrapperMBean; |
2 | 65 |
import javax.management.InstanceAlreadyExistsException; |
66 |
import javax.management.InstanceNotFoundException; |
|
67 |
import javax.management.IntrospectionException; |
|
68 |
import javax.management.InvalidAttributeValueException; |
|
69 |
import javax.management.JMRuntimeException; |
|
70 |
import javax.management.ListenerNotFoundException; |
|
71 |
import javax.management.MBeanException; |
|
72 |
import javax.management.MBeanInfo; |
|
73 |
import javax.management.MBeanPermission; |
|
74 |
import javax.management.MBeanRegistration; |
|
75 |
import javax.management.MBeanRegistrationException; |
|
76 |
import javax.management.MBeanServer; |
|
77 |
import javax.management.MBeanServerDelegate; |
|
78 |
import javax.management.MBeanServerNotification; |
|
79 |
import javax.management.MBeanTrustPermission; |
|
80 |
import javax.management.NotCompliantMBeanException; |
|
81 |
import javax.management.Notification; |
|
82 |
import javax.management.NotificationBroadcaster; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
83 |
import javax.management.NotificationBroadcasterSupport; |
2 | 84 |
import javax.management.NotificationEmitter; |
85 |
import javax.management.NotificationFilter; |
|
86 |
import javax.management.NotificationListener; |
|
87 |
import javax.management.ObjectInstance; |
|
88 |
import javax.management.ObjectName; |
|
89 |
import javax.management.QueryEval; |
|
90 |
import javax.management.QueryExp; |
|
91 |
import javax.management.ReflectionException; |
|
92 |
import javax.management.RuntimeErrorException; |
|
93 |
import javax.management.RuntimeMBeanException; |
|
94 |
import javax.management.RuntimeOperationsException; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
95 |
import javax.management.namespace.JMXNamespace; |
2 | 96 |
|
97 |
/** |
|
98 |
* This is the default class for MBean manipulation on the agent side. It |
|
99 |
* contains the methods necessary for the creation, registration, and |
|
100 |
* deletion of MBeans as well as the access methods for registered MBeans. |
|
101 |
* This is the core component of the JMX infrastructure. |
|
102 |
* <P> |
|
103 |
* Every MBean which is added to the MBean server becomes manageable: its attributes and operations |
|
104 |
* become remotely accessible through the connectors/adaptors connected to that MBean server. |
|
105 |
* A Java object cannot be registered in the MBean server unless it is a JMX compliant MBean. |
|
106 |
* <P> |
|
107 |
* When an MBean is registered or unregistered in the MBean server an |
|
108 |
* {@link javax.management.MBeanServerNotification MBeanServerNotification} |
|
109 |
* Notification is emitted. To register an object as listener to MBeanServerNotifications |
|
110 |
* you should call the MBean server method {@link #addNotificationListener addNotificationListener} with <CODE>ObjectName</CODE> |
|
111 |
* the <CODE>ObjectName</CODE> of the {@link javax.management.MBeanServerDelegate MBeanServerDelegate}. |
|
112 |
* This <CODE>ObjectName</CODE> is: |
|
113 |
* <BR> |
|
114 |
* <CODE>JMImplementation:type=MBeanServerDelegate</CODE>. |
|
115 |
* |
|
116 |
* @since 1.5 |
|
117 |
*/ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
118 |
public class DefaultMBeanServerInterceptor |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
119 |
extends MBeanServerInterceptorSupport { |
2 | 120 |
|
121 |
/** The MBeanInstantiator object used by the |
|
122 |
* DefaultMBeanServerInterceptor */ |
|
123 |
private final transient MBeanInstantiator instantiator; |
|
124 |
||
125 |
/** The MBean server object that is associated to the |
|
126 |
* DefaultMBeanServerInterceptor */ |
|
127 |
private transient MBeanServer server = null; |
|
128 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
129 |
/** The MBean server delegate object that is associated to the |
2 | 130 |
* DefaultMBeanServerInterceptor */ |
131 |
private final transient MBeanServerDelegate delegate; |
|
132 |
||
133 |
/** The Repository object used by the DefaultMBeanServerInterceptor */ |
|
134 |
private final transient Repository repository; |
|
135 |
||
136 |
/** Wrappers for client listeners. */ |
|
137 |
/* See the comment before addNotificationListener below. */ |
|
138 |
private final transient |
|
139 |
WeakHashMap<ListenerWrapper, WeakReference<ListenerWrapper>> |
|
140 |
listenerWrappers = |
|
141 |
new WeakHashMap<ListenerWrapper, |
|
142 |
WeakReference<ListenerWrapper>>(); |
|
143 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
144 |
private final NamespaceDispatchInterceptor dispatcher; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
145 |
|
2 | 146 |
/** The default domain of the object names */ |
147 |
private final String domain; |
|
148 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
149 |
/** The mbeanServerName */ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
150 |
private final String mbeanServerName; |
2 | 151 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
152 |
/** The sequence number identifying the notifications sent */ |
2 | 153 |
// Now sequence number is handled by MBeanServerDelegate. |
154 |
// private int sequenceNumber=0; |
|
155 |
||
156 |
/** |
|
157 |
* Creates a DefaultMBeanServerInterceptor with the specified |
|
158 |
* repository instance. |
|
159 |
* <p>Do not forget to call <code>initialize(outer,delegate)</code> |
|
160 |
* before using this object. |
|
161 |
* @param outer A pointer to the MBeanServer object that must be |
|
162 |
* passed to the MBeans when invoking their |
|
163 |
* {@link javax.management.MBeanRegistration} interface. |
|
164 |
* @param delegate A pointer to the MBeanServerDelegate associated |
|
165 |
* with the new MBeanServer. The new MBeanServer must register |
|
166 |
* this MBean in its MBean repository. |
|
167 |
* @param instantiator The MBeanInstantiator that will be used to |
|
168 |
* instantiate MBeans and take care of class loading issues. |
|
169 |
* @param repository The repository to use for this MBeanServer. |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
170 |
* @param dispatcher The dispatcher used by this MBeanServer |
2 | 171 |
*/ |
172 |
public DefaultMBeanServerInterceptor(MBeanServer outer, |
|
173 |
MBeanServerDelegate delegate, |
|
174 |
MBeanInstantiator instantiator, |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
175 |
Repository repository, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
176 |
NamespaceDispatchInterceptor dispatcher) { |
2 | 177 |
if (outer == null) throw new |
178 |
IllegalArgumentException("outer MBeanServer cannot be null"); |
|
179 |
if (delegate == null) throw new |
|
180 |
IllegalArgumentException("MBeanServerDelegate cannot be null"); |
|
181 |
if (instantiator == null) throw new |
|
182 |
IllegalArgumentException("MBeanInstantiator cannot be null"); |
|
183 |
if (repository == null) throw new |
|
184 |
IllegalArgumentException("Repository cannot be null"); |
|
185 |
||
186 |
this.server = outer; |
|
187 |
this.delegate = delegate; |
|
188 |
this.instantiator = instantiator; |
|
189 |
this.repository = repository; |
|
190 |
this.domain = repository.getDefaultDomain(); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
191 |
this.dispatcher = dispatcher; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
192 |
this.mbeanServerName = Util.getMBeanServerSecurityName(delegate); |
2 | 193 |
} |
194 |
||
195 |
public ObjectInstance createMBean(String className, ObjectName name) |
|
196 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
197 |
MBeanRegistrationException, MBeanException, |
|
198 |
NotCompliantMBeanException { |
|
199 |
||
200 |
return createMBean(className, name, (Object[]) null, (String[]) null); |
|
201 |
||
202 |
} |
|
203 |
||
204 |
public ObjectInstance createMBean(String className, ObjectName name, |
|
205 |
ObjectName loaderName) |
|
206 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
207 |
MBeanRegistrationException, MBeanException, |
|
208 |
NotCompliantMBeanException, InstanceNotFoundException { |
|
209 |
||
210 |
return createMBean(className, name, loaderName, (Object[]) null, |
|
211 |
(String[]) null); |
|
212 |
} |
|
213 |
||
214 |
public ObjectInstance createMBean(String className, ObjectName name, |
|
215 |
Object[] params, String[] signature) |
|
216 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
217 |
MBeanRegistrationException, MBeanException, |
|
218 |
NotCompliantMBeanException { |
|
219 |
||
220 |
try { |
|
221 |
return createMBean(className, name, null, true, |
|
222 |
params, signature); |
|
223 |
} catch (InstanceNotFoundException e) { |
|
224 |
/* Can only happen if loaderName doesn't exist, but we just |
|
225 |
passed null, so we shouldn't get this exception. */ |
|
226 |
throw EnvHelp.initCause( |
|
227 |
new IllegalArgumentException("Unexpected exception: " + e), e); |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
public ObjectInstance createMBean(String className, ObjectName name, |
|
232 |
ObjectName loaderName, |
|
233 |
Object[] params, String[] signature) |
|
234 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
235 |
MBeanRegistrationException, MBeanException, |
|
236 |
NotCompliantMBeanException, InstanceNotFoundException { |
|
237 |
||
238 |
return createMBean(className, name, loaderName, false, |
|
239 |
params, signature); |
|
240 |
} |
|
241 |
||
242 |
private ObjectInstance createMBean(String className, ObjectName name, |
|
243 |
ObjectName loaderName, |
|
244 |
boolean withDefaultLoaderRepository, |
|
245 |
Object[] params, String[] signature) |
|
246 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
247 |
MBeanRegistrationException, MBeanException, |
|
248 |
NotCompliantMBeanException, InstanceNotFoundException { |
|
249 |
||
250 |
Class theClass; |
|
251 |
||
252 |
if (className == null) { |
|
253 |
final RuntimeException wrapped = |
|
254 |
new IllegalArgumentException("The class name cannot be null"); |
|
255 |
throw new RuntimeOperationsException(wrapped, |
|
256 |
"Exception occurred during MBean creation"); |
|
257 |
} |
|
258 |
||
259 |
if (name != null) { |
|
260 |
if (name.isPattern()) { |
|
261 |
final RuntimeException wrapped = |
|
262 |
new IllegalArgumentException("Invalid name->" + |
|
263 |
name.toString()); |
|
264 |
final String msg = "Exception occurred during MBean creation"; |
|
265 |
throw new RuntimeOperationsException(wrapped, msg); |
|
266 |
} |
|
267 |
||
268 |
name = nonDefaultDomain(name); |
|
269 |
} |
|
270 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
271 |
checkMBeanPermission(mbeanServerName,className, null, null, "instantiate"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
272 |
checkMBeanPermission(mbeanServerName,className, null, name, "registerMBean"); |
2 | 273 |
|
274 |
/* Load the appropriate class. */ |
|
275 |
if (withDefaultLoaderRepository) { |
|
276 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
277 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
278 |
DefaultMBeanServerInterceptor.class.getName(), |
|
279 |
"createMBean", |
|
280 |
"ClassName = " + className + ", ObjectName = " + name); |
|
281 |
} |
|
282 |
theClass = |
|
283 |
instantiator.findClassWithDefaultLoaderRepository(className); |
|
284 |
} else if (loaderName == null) { |
|
285 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
286 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
287 |
DefaultMBeanServerInterceptor.class.getName(), |
|
288 |
"createMBean", "ClassName = " + className + |
|
289 |
", ObjectName = " + name + ", Loader name = null"); |
|
290 |
} |
|
291 |
||
292 |
theClass = instantiator.findClass(className, |
|
293 |
server.getClass().getClassLoader()); |
|
294 |
} else { |
|
295 |
loaderName = nonDefaultDomain(loaderName); |
|
296 |
||
297 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
298 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
299 |
DefaultMBeanServerInterceptor.class.getName(), |
|
300 |
"createMBean", "ClassName = " + className + |
|
301 |
", ObjectName = " + name + |
|
302 |
", Loader name = " + loaderName); |
|
303 |
} |
|
304 |
||
305 |
theClass = instantiator.findClass(className, loaderName); |
|
306 |
} |
|
307 |
||
308 |
checkMBeanTrustPermission(theClass); |
|
309 |
||
310 |
// Check that the MBean can be instantiated by the MBeanServer. |
|
311 |
Introspector.testCreation(theClass); |
|
312 |
||
313 |
// Check the JMX MBean compliance of the class |
|
314 |
Introspector.checkCompliance(theClass); |
|
315 |
||
316 |
Object moi= instantiator.instantiate(theClass, params, signature, |
|
317 |
server.getClass().getClassLoader()); |
|
318 |
||
319 |
final String infoClassName = getNewMBeanClassName(moi); |
|
320 |
||
321 |
return registerObject(infoClassName, moi, name); |
|
322 |
} |
|
323 |
||
324 |
public ObjectInstance registerMBean(Object object, ObjectName name) |
|
325 |
throws InstanceAlreadyExistsException, MBeanRegistrationException, |
|
326 |
NotCompliantMBeanException { |
|
327 |
||
328 |
// ------------------------------ |
|
329 |
// ------------------------------ |
|
330 |
Class theClass = object.getClass(); |
|
331 |
||
332 |
Introspector.checkCompliance(theClass); |
|
333 |
||
334 |
final String infoClassName = getNewMBeanClassName(object); |
|
335 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
336 |
checkMBeanPermission(mbeanServerName,infoClassName, null, name, "registerMBean"); |
2 | 337 |
checkMBeanTrustPermission(theClass); |
338 |
||
339 |
return registerObject(infoClassName, object, name); |
|
340 |
} |
|
341 |
||
342 |
private static String getNewMBeanClassName(Object mbeanToRegister) |
|
343 |
throws NotCompliantMBeanException { |
|
344 |
if (mbeanToRegister instanceof DynamicMBean) { |
|
345 |
DynamicMBean mbean = (DynamicMBean) mbeanToRegister; |
|
346 |
final String name; |
|
347 |
try { |
|
348 |
name = mbean.getMBeanInfo().getClassName(); |
|
349 |
} catch (Exception e) { |
|
350 |
// Includes case where getMBeanInfo() returns null |
|
351 |
NotCompliantMBeanException ncmbe = |
|
352 |
new NotCompliantMBeanException("Bad getMBeanInfo()"); |
|
353 |
ncmbe.initCause(e); |
|
354 |
throw ncmbe; |
|
355 |
} |
|
356 |
if (name == null) { |
|
357 |
final String msg = "MBeanInfo has null class name"; |
|
358 |
throw new NotCompliantMBeanException(msg); |
|
359 |
} |
|
360 |
return name; |
|
361 |
} else |
|
362 |
return mbeanToRegister.getClass().getName(); |
|
363 |
} |
|
364 |
||
365 |
private final Set<ObjectName> beingUnregistered = |
|
366 |
new HashSet<ObjectName>(); |
|
367 |
||
368 |
public void unregisterMBean(ObjectName name) |
|
369 |
throws InstanceNotFoundException, MBeanRegistrationException { |
|
370 |
||
371 |
if (name == null) { |
|
372 |
final RuntimeException wrapped = |
|
373 |
new IllegalArgumentException("Object name cannot be null"); |
|
374 |
throw new RuntimeOperationsException(wrapped, |
|
375 |
"Exception occurred trying to unregister the MBean"); |
|
376 |
} |
|
377 |
||
378 |
name = nonDefaultDomain(name); |
|
379 |
||
380 |
/* The semantics of preDeregister are tricky. If it throws an |
|
381 |
exception, then the unregisterMBean fails. This allows an |
|
382 |
MBean to refuse to be unregistered. If it returns |
|
383 |
successfully, then the unregisterMBean can proceed. In |
|
384 |
this case the preDeregister may have cleaned up some state, |
|
385 |
and will not expect to be called a second time. So if two |
|
386 |
threads try to unregister the same MBean at the same time |
|
387 |
then one of them must wait for the other one to either (a) |
|
388 |
call preDeregister and get an exception or (b) call |
|
389 |
preDeregister successfully and unregister the MBean. |
|
390 |
Suppose thread T1 is unregistering an MBean and thread T2 |
|
391 |
is trying to unregister the same MBean, so waiting for T1. |
|
392 |
Then a deadlock is possible if the preDeregister for T1 |
|
393 |
ends up needing a lock held by T2. Given the semantics |
|
394 |
just described, there does not seem to be any way to avoid |
|
395 |
this. This will not happen to code where it is clear for |
|
396 |
any given MBean what thread may unregister that MBean. |
|
397 |
||
398 |
On the other hand we clearly do not want a thread that is |
|
399 |
unregistering MBean A to have to wait for another thread |
|
400 |
that is unregistering another MBean B (see bug 6318664). A |
|
401 |
deadlock in this situation could reasonably be considered |
|
402 |
gratuitous. So holding a global lock across the |
|
403 |
preDeregister call would be bad. |
|
404 |
||
405 |
So we have a set of ObjectNames that some thread is |
|
406 |
currently unregistering. When a thread wants to unregister |
|
407 |
a name, it must first check if the name is in the set, and |
|
408 |
if so it must wait. When a thread successfully unregisters |
|
409 |
a name it removes the name from the set and notifies any |
|
410 |
waiting threads that the set has changed. |
|
411 |
||
412 |
This implies that we must be very careful to ensure that |
|
413 |
the name is removed from the set and waiters notified, no |
|
414 |
matter what code path is taken. */ |
|
415 |
||
416 |
synchronized (beingUnregistered) { |
|
417 |
while (beingUnregistered.contains(name)) { |
|
418 |
try { |
|
419 |
beingUnregistered.wait(); |
|
420 |
} catch (InterruptedException e) { |
|
421 |
throw new MBeanRegistrationException(e, e.toString()); |
|
422 |
// pretend the exception came from preDeregister; |
|
423 |
// in another execution sequence it could have |
|
424 |
} |
|
425 |
} |
|
426 |
beingUnregistered.add(name); |
|
427 |
} |
|
428 |
||
429 |
try { |
|
430 |
exclusiveUnregisterMBean(name); |
|
431 |
} finally { |
|
432 |
synchronized (beingUnregistered) { |
|
433 |
beingUnregistered.remove(name); |
|
434 |
beingUnregistered.notifyAll(); |
|
435 |
} |
|
436 |
} |
|
437 |
} |
|
438 |
||
439 |
private void exclusiveUnregisterMBean(ObjectName name) |
|
440 |
throws InstanceNotFoundException, MBeanRegistrationException { |
|
441 |
||
442 |
DynamicMBean instance = getMBean(name); |
|
443 |
// may throw InstanceNotFoundException |
|
444 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
445 |
checkMBeanPermission(mbeanServerName, instance, null, name, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
446 |
"unregisterMBean"); |
2 | 447 |
|
448 |
if (instance instanceof MBeanRegistration) |
|
449 |
preDeregisterInvoke((MBeanRegistration) instance); |
|
450 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
451 |
final Object resource = getResource(instance); |
2 | 452 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
453 |
// Unregisters the MBean from the repository. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
454 |
// Returns the resource context that was used. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
455 |
// The returned context does nothing for regular MBeans. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
456 |
// For ClassLoader MBeans and JMXNamespace (and JMXDomain) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
457 |
// MBeans - the context makes it possible to unregister these |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
458 |
// objects from the appropriate framework artifacts, such as |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
459 |
// the CLR or the dispatcher, from within the repository lock. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
460 |
// In case of success, we also need to call context.done() at the |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
461 |
// end of this method. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
462 |
// |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
463 |
final ResourceContext context = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
464 |
unregisterFromRepository(resource, instance, name); |
2 | 465 |
|
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
466 |
try { |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
467 |
if (instance instanceof MBeanRegistration) |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
468 |
postDeregisterInvoke(name,(MBeanRegistration) instance); |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
469 |
} finally { |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
470 |
context.done(); |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
471 |
} |
2 | 472 |
} |
473 |
||
474 |
public ObjectInstance getObjectInstance(ObjectName name) |
|
475 |
throws InstanceNotFoundException { |
|
476 |
||
477 |
name = nonDefaultDomain(name); |
|
478 |
DynamicMBean instance = getMBean(name); |
|
479 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
480 |
checkMBeanPermission(mbeanServerName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
481 |
instance, null, name, "getObjectInstance"); |
2 | 482 |
|
483 |
final String className = getClassName(instance); |
|
484 |
||
485 |
return new ObjectInstance(name, className); |
|
486 |
} |
|
487 |
||
488 |
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) { |
|
489 |
SecurityManager sm = System.getSecurityManager(); |
|
490 |
if (sm != null) { |
|
491 |
// Check if the caller has the right to invoke 'queryMBeans' |
|
492 |
// |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
493 |
checkMBeanPermission(mbeanServerName,(String) null, null, null, "queryMBeans"); |
2 | 494 |
|
495 |
// Perform query without "query". |
|
496 |
// |
|
497 |
Set<ObjectInstance> list = queryMBeansImpl(name, null); |
|
498 |
||
499 |
// Check if the caller has the right to invoke 'queryMBeans' |
|
500 |
// on each specific classname/objectname in the list. |
|
501 |
// |
|
502 |
Set<ObjectInstance> allowedList = |
|
503 |
new HashSet<ObjectInstance>(list.size()); |
|
504 |
for (ObjectInstance oi : list) { |
|
505 |
try { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
506 |
checkMBeanPermission(mbeanServerName,oi.getClassName(), null, |
2 | 507 |
oi.getObjectName(), "queryMBeans"); |
508 |
allowedList.add(oi); |
|
509 |
} catch (SecurityException e) { |
|
510 |
// OK: Do not add this ObjectInstance to the list |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
// Apply query to allowed MBeans only. |
|
515 |
// |
|
516 |
return filterListOfObjectInstances(allowedList, query); |
|
517 |
} else { |
|
518 |
// Perform query. |
|
519 |
// |
|
520 |
return queryMBeansImpl(name, query); |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
private Set<ObjectInstance> queryMBeansImpl(ObjectName name, |
|
525 |
QueryExp query) { |
|
526 |
// Query the MBeans on the repository |
|
527 |
// |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
287
diff
changeset
|
528 |
Set<NamedObject> list = repository.query(name, query); |
2 | 529 |
|
530 |
return (objectInstancesFromFilteredNamedObjects(list, query)); |
|
531 |
} |
|
532 |
||
533 |
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) { |
|
534 |
Set<ObjectName> queryList; |
|
535 |
SecurityManager sm = System.getSecurityManager(); |
|
536 |
if (sm != null) { |
|
537 |
// Check if the caller has the right to invoke 'queryNames' |
|
538 |
// |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
539 |
checkMBeanPermission(mbeanServerName,(String) null, null, null, "queryNames"); |
2 | 540 |
|
541 |
// Perform query without "query". |
|
542 |
// |
|
543 |
Set<ObjectInstance> list = queryMBeansImpl(name, null); |
|
544 |
||
545 |
// Check if the caller has the right to invoke 'queryNames' |
|
546 |
// on each specific classname/objectname in the list. |
|
547 |
// |
|
548 |
Set<ObjectInstance> allowedList = |
|
549 |
new HashSet<ObjectInstance>(list.size()); |
|
550 |
for (ObjectInstance oi : list) { |
|
551 |
try { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
552 |
checkMBeanPermission(mbeanServerName, oi.getClassName(), null, |
2 | 553 |
oi.getObjectName(), "queryNames"); |
554 |
allowedList.add(oi); |
|
555 |
} catch (SecurityException e) { |
|
556 |
// OK: Do not add this ObjectInstance to the list |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
// Apply query to allowed MBeans only. |
|
561 |
// |
|
562 |
Set<ObjectInstance> queryObjectInstanceList = |
|
563 |
filterListOfObjectInstances(allowedList, query); |
|
564 |
queryList = new HashSet<ObjectName>(queryObjectInstanceList.size()); |
|
565 |
for (ObjectInstance oi : queryObjectInstanceList) { |
|
566 |
queryList.add(oi.getObjectName()); |
|
567 |
} |
|
568 |
} else { |
|
569 |
// Perform query. |
|
570 |
// |
|
571 |
queryList = queryNamesImpl(name, query); |
|
572 |
} |
|
573 |
return queryList; |
|
574 |
} |
|
575 |
||
576 |
private Set<ObjectName> queryNamesImpl(ObjectName name, QueryExp query) { |
|
577 |
// Query the MBeans on the repository |
|
578 |
// |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
287
diff
changeset
|
579 |
Set<NamedObject> list = repository.query(name, query); |
2 | 580 |
|
581 |
return (objectNamesFromFilteredNamedObjects(list, query)); |
|
582 |
} |
|
583 |
||
584 |
public boolean isRegistered(ObjectName name) { |
|
585 |
if (name == null) { |
|
586 |
throw new RuntimeOperationsException( |
|
587 |
new IllegalArgumentException("Object name cannot be null"), |
|
588 |
"Object name cannot be null"); |
|
589 |
} |
|
590 |
||
591 |
name = nonDefaultDomain(name); |
|
592 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
593 |
/* No Permission check */ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
594 |
// isRegistered is always unchecked as per JMX spec. |
2 | 595 |
|
596 |
return (repository.contains(name)); |
|
597 |
} |
|
598 |
||
599 |
public String[] getDomains() { |
|
600 |
SecurityManager sm = System.getSecurityManager(); |
|
601 |
if (sm != null) { |
|
602 |
// Check if the caller has the right to invoke 'getDomains' |
|
603 |
// |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
604 |
checkMBeanPermission(mbeanServerName, (String) null, null, null, "getDomains"); |
2 | 605 |
|
606 |
// Return domains |
|
607 |
// |
|
608 |
String[] domains = repository.getDomains(); |
|
609 |
||
610 |
// Check if the caller has the right to invoke 'getDomains' |
|
611 |
// on each specific domain in the list. |
|
612 |
// |
|
613 |
List<String> result = new ArrayList<String>(domains.length); |
|
614 |
for (int i = 0; i < domains.length; i++) { |
|
615 |
try { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
616 |
ObjectName dom = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
617 |
Util.newObjectName(domains[i] + ":x=x"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
618 |
checkMBeanPermission(mbeanServerName, (String) null, null, dom, "getDomains"); |
2 | 619 |
result.add(domains[i]); |
620 |
} catch (SecurityException e) { |
|
621 |
// OK: Do not add this domain to the list |
|
622 |
} |
|
623 |
} |
|
624 |
||
625 |
// Make an array from result. |
|
626 |
// |
|
627 |
return result.toArray(new String[result.size()]); |
|
628 |
} else { |
|
629 |
return repository.getDomains(); |
|
630 |
} |
|
631 |
} |
|
632 |
||
633 |
public Integer getMBeanCount() { |
|
634 |
return (repository.getCount()); |
|
635 |
} |
|
636 |
||
637 |
public Object getAttribute(ObjectName name, String attribute) |
|
638 |
throws MBeanException, AttributeNotFoundException, |
|
639 |
InstanceNotFoundException, ReflectionException { |
|
640 |
||
641 |
if (name == null) { |
|
642 |
throw new RuntimeOperationsException(new |
|
643 |
IllegalArgumentException("Object name cannot be null"), |
|
644 |
"Exception occurred trying to invoke the getter on the MBean"); |
|
645 |
} |
|
646 |
if (attribute == null) { |
|
647 |
throw new RuntimeOperationsException(new |
|
648 |
IllegalArgumentException("Attribute cannot be null"), |
|
649 |
"Exception occurred trying to invoke the getter on the MBean"); |
|
650 |
} |
|
651 |
||
652 |
name = nonDefaultDomain(name); |
|
653 |
||
654 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
655 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
656 |
DefaultMBeanServerInterceptor.class.getName(), |
|
657 |
"getAttribute", |
|
658 |
"Attribute = " + attribute + ", ObjectName = " + name); |
|
659 |
} |
|
660 |
||
661 |
final DynamicMBean instance = getMBean(name); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
662 |
checkMBeanPermission(mbeanServerName, instance, attribute, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
663 |
name, "getAttribute"); |
2 | 664 |
|
665 |
try { |
|
666 |
return instance.getAttribute(attribute); |
|
667 |
} catch (AttributeNotFoundException e) { |
|
668 |
throw e; |
|
669 |
} catch (Throwable t) { |
|
670 |
rethrowMaybeMBeanException(t); |
|
671 |
throw new AssertionError(); // not reached |
|
672 |
} |
|
673 |
} |
|
674 |
||
675 |
public AttributeList getAttributes(ObjectName name, String[] attributes) |
|
676 |
throws InstanceNotFoundException, ReflectionException { |
|
677 |
||
678 |
if (name == null) { |
|
679 |
throw new RuntimeOperationsException(new |
|
680 |
IllegalArgumentException("ObjectName name cannot be null"), |
|
681 |
"Exception occurred trying to invoke the getter on the MBean"); |
|
682 |
} |
|
683 |
||
684 |
if (attributes == null) { |
|
685 |
throw new RuntimeOperationsException(new |
|
686 |
IllegalArgumentException("Attributes cannot be null"), |
|
687 |
"Exception occurred trying to invoke the getter on the MBean"); |
|
688 |
} |
|
689 |
||
690 |
name = nonDefaultDomain(name); |
|
691 |
||
692 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
693 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
694 |
DefaultMBeanServerInterceptor.class.getName(), |
|
695 |
"getAttributes", "ObjectName = " + name); |
|
696 |
} |
|
697 |
||
698 |
final DynamicMBean instance = getMBean(name); |
|
699 |
final String[] allowedAttributes; |
|
700 |
final SecurityManager sm = System.getSecurityManager(); |
|
701 |
if (sm == null) |
|
702 |
allowedAttributes = attributes; |
|
703 |
else { |
|
704 |
final String classname = getClassName(instance); |
|
705 |
||
706 |
// Check if the caller has the right to invoke 'getAttribute' |
|
707 |
// |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
708 |
checkMBeanPermission(mbeanServerName, classname, null, name, "getAttribute"); |
2 | 709 |
|
710 |
// Check if the caller has the right to invoke 'getAttribute' |
|
711 |
// on each specific attribute |
|
712 |
// |
|
713 |
List<String> allowedList = |
|
714 |
new ArrayList<String>(attributes.length); |
|
715 |
for (String attr : attributes) { |
|
716 |
try { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
717 |
checkMBeanPermission(mbeanServerName, classname, attr, |
2 | 718 |
name, "getAttribute"); |
719 |
allowedList.add(attr); |
|
720 |
} catch (SecurityException e) { |
|
721 |
// OK: Do not add this attribute to the list |
|
722 |
} |
|
723 |
} |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
724 |
allowedAttributes = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
725 |
allowedList.toArray(new String[allowedList.size()]); |
2 | 726 |
} |
727 |
||
728 |
try { |
|
729 |
return instance.getAttributes(allowedAttributes); |
|
730 |
} catch (Throwable t) { |
|
731 |
rethrow(t); |
|
732 |
throw new AssertionError(); |
|
733 |
} |
|
734 |
} |
|
735 |
||
736 |
public void setAttribute(ObjectName name, Attribute attribute) |
|
737 |
throws InstanceNotFoundException, AttributeNotFoundException, |
|
738 |
InvalidAttributeValueException, MBeanException, |
|
739 |
ReflectionException { |
|
740 |
||
741 |
if (name == null) { |
|
742 |
throw new RuntimeOperationsException(new |
|
743 |
IllegalArgumentException("ObjectName name cannot be null"), |
|
744 |
"Exception occurred trying to invoke the setter on the MBean"); |
|
745 |
} |
|
746 |
||
747 |
if (attribute == null) { |
|
748 |
throw new RuntimeOperationsException(new |
|
749 |
IllegalArgumentException("Attribute cannot be null"), |
|
750 |
"Exception occurred trying to invoke the setter on the MBean"); |
|
751 |
} |
|
752 |
||
753 |
name = nonDefaultDomain(name); |
|
754 |
||
755 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
756 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
757 |
DefaultMBeanServerInterceptor.class.getName(), |
|
758 |
"setAttribute", "ObjectName = " + name + |
|
759 |
", Attribute = " + attribute.getName()); |
|
760 |
} |
|
761 |
||
762 |
DynamicMBean instance = getMBean(name); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
763 |
checkMBeanPermission(mbeanServerName, instance, attribute.getName(), |
2 | 764 |
name, "setAttribute"); |
765 |
||
766 |
try { |
|
767 |
instance.setAttribute(attribute); |
|
768 |
} catch (AttributeNotFoundException e) { |
|
769 |
throw e; |
|
770 |
} catch (InvalidAttributeValueException e) { |
|
771 |
throw e; |
|
772 |
} catch (Throwable t) { |
|
773 |
rethrowMaybeMBeanException(t); |
|
774 |
throw new AssertionError(); |
|
775 |
} |
|
776 |
} |
|
777 |
||
778 |
public AttributeList setAttributes(ObjectName name, |
|
779 |
AttributeList attributes) |
|
780 |
throws InstanceNotFoundException, ReflectionException { |
|
781 |
||
782 |
if (name == null) { |
|
783 |
throw new RuntimeOperationsException(new |
|
784 |
IllegalArgumentException("ObjectName name cannot be null"), |
|
785 |
"Exception occurred trying to invoke the setter on the MBean"); |
|
786 |
} |
|
787 |
||
788 |
if (attributes == null) { |
|
789 |
throw new RuntimeOperationsException(new |
|
790 |
IllegalArgumentException("AttributeList cannot be null"), |
|
791 |
"Exception occurred trying to invoke the setter on the MBean"); |
|
792 |
} |
|
793 |
||
794 |
name = nonDefaultDomain(name); |
|
795 |
||
796 |
final DynamicMBean instance = getMBean(name); |
|
797 |
final AttributeList allowedAttributes; |
|
798 |
final SecurityManager sm = System.getSecurityManager(); |
|
799 |
if (sm == null) |
|
800 |
allowedAttributes = attributes; |
|
801 |
else { |
|
802 |
String classname = getClassName(instance); |
|
803 |
||
804 |
// Check if the caller has the right to invoke 'setAttribute' |
|
805 |
// |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
806 |
checkMBeanPermission(mbeanServerName, classname, null, name, "setAttribute"); |
2 | 807 |
|
808 |
// Check if the caller has the right to invoke 'setAttribute' |
|
809 |
// on each specific attribute |
|
810 |
// |
|
811 |
allowedAttributes = new AttributeList(attributes.size()); |
|
812 |
for (Iterator i = attributes.iterator(); i.hasNext();) { |
|
813 |
try { |
|
814 |
Attribute attribute = (Attribute) i.next(); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
815 |
checkMBeanPermission(mbeanServerName, classname, attribute.getName(), |
2 | 816 |
name, "setAttribute"); |
817 |
allowedAttributes.add(attribute); |
|
818 |
} catch (SecurityException e) { |
|
819 |
// OK: Do not add this attribute to the list |
|
820 |
} |
|
821 |
} |
|
822 |
} |
|
823 |
try { |
|
824 |
return instance.setAttributes(allowedAttributes); |
|
825 |
} catch (Throwable t) { |
|
826 |
rethrow(t); |
|
827 |
throw new AssertionError(); |
|
828 |
} |
|
829 |
} |
|
830 |
||
831 |
public Object invoke(ObjectName name, String operationName, |
|
832 |
Object params[], String signature[]) |
|
833 |
throws InstanceNotFoundException, MBeanException, |
|
834 |
ReflectionException { |
|
835 |
||
836 |
name = nonDefaultDomain(name); |
|
837 |
||
838 |
DynamicMBean instance = getMBean(name); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
839 |
checkMBeanPermission(mbeanServerName, instance, operationName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
840 |
name, "invoke"); |
2 | 841 |
try { |
842 |
return instance.invoke(operationName, params, signature); |
|
843 |
} catch (Throwable t) { |
|
844 |
rethrowMaybeMBeanException(t); |
|
845 |
throw new AssertionError(); |
|
846 |
} |
|
847 |
} |
|
848 |
||
849 |
/* Centralize some of the tedious exception wrapping demanded by the JMX |
|
850 |
spec. */ |
|
851 |
private static void rethrow(Throwable t) |
|
852 |
throws ReflectionException { |
|
853 |
try { |
|
854 |
throw t; |
|
855 |
} catch (ReflectionException e) { |
|
856 |
throw e; |
|
857 |
} catch (RuntimeOperationsException e) { |
|
858 |
throw e; |
|
859 |
} catch (RuntimeErrorException e) { |
|
860 |
throw e; |
|
861 |
} catch (RuntimeException e) { |
|
862 |
throw new RuntimeMBeanException(e, e.toString()); |
|
863 |
} catch (Error e) { |
|
864 |
throw new RuntimeErrorException(e, e.toString()); |
|
865 |
} catch (Throwable t2) { |
|
866 |
// should not happen |
|
867 |
throw new RuntimeException("Unexpected exception", t2); |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
private static void rethrowMaybeMBeanException(Throwable t) |
|
872 |
throws ReflectionException, MBeanException { |
|
873 |
if (t instanceof MBeanException) |
|
874 |
throw (MBeanException) t; |
|
875 |
rethrow(t); |
|
876 |
} |
|
877 |
||
878 |
/** |
|
879 |
* Register <code>object</code> in the repository, with the |
|
880 |
* given <code>name</code>. |
|
881 |
* This method is called by the various createMBean() flavours |
|
882 |
* and by registerMBean() after all MBean compliance tests |
|
883 |
* have been performed. |
|
884 |
* <p> |
|
885 |
* This method does not performed any kind of test compliance, |
|
886 |
* and the caller should make sure that the given <code>object</code> |
|
887 |
* is MBean compliant. |
|
888 |
* <p> |
|
889 |
* This methods performed all the basic steps needed for object |
|
890 |
* registration: |
|
891 |
* <ul> |
|
892 |
* <li>If the <code>object</code> implements the MBeanRegistration |
|
893 |
* interface, it invokes preRegister() on the object.</li> |
|
894 |
* <li>Then the object is added to the repository with the given |
|
895 |
* <code>name</code>.</li> |
|
896 |
* <li>Finally, if the <code>object</code> implements the |
|
897 |
* MBeanRegistration interface, it invokes postRegister() |
|
898 |
* on the object.</li> |
|
899 |
* </ul> |
|
900 |
* @param object A reference to a MBean compliant object. |
|
901 |
* @param name The ObjectName of the <code>object</code> MBean. |
|
902 |
* @return the actual ObjectName with which the object was registered. |
|
903 |
* @exception InstanceAlreadyExistsException if an object is already |
|
904 |
* registered with that name. |
|
905 |
* @exception MBeanRegistrationException if an exception occurs during |
|
906 |
* registration. |
|
907 |
**/ |
|
908 |
private ObjectInstance registerObject(String classname, |
|
909 |
Object object, ObjectName name) |
|
910 |
throws InstanceAlreadyExistsException, |
|
911 |
MBeanRegistrationException, |
|
912 |
NotCompliantMBeanException { |
|
913 |
||
914 |
if (object == null) { |
|
915 |
final RuntimeException wrapped = |
|
916 |
new IllegalArgumentException("Cannot add null object"); |
|
917 |
throw new RuntimeOperationsException(wrapped, |
|
918 |
"Exception occurred trying to register the MBean"); |
|
919 |
} |
|
920 |
||
921 |
DynamicMBean mbean = Introspector.makeDynamicMBean(object); |
|
922 |
||
923 |
return registerDynamicMBean(classname, mbean, name); |
|
924 |
} |
|
925 |
||
926 |
private ObjectInstance registerDynamicMBean(String classname, |
|
927 |
DynamicMBean mbean, |
|
928 |
ObjectName name) |
|
929 |
throws InstanceAlreadyExistsException, |
|
930 |
MBeanRegistrationException, |
|
931 |
NotCompliantMBeanException { |
|
932 |
||
933 |
||
934 |
name = nonDefaultDomain(name); |
|
935 |
||
936 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
937 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
938 |
DefaultMBeanServerInterceptor.class.getName(), |
|
939 |
"registerMBean", "ObjectName = " + name); |
|
940 |
} |
|
941 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
942 |
ObjectName logicalName = preRegister(mbean, server, name); |
2 | 943 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
944 |
// preRegister returned successfully, so from this point on we |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
945 |
// must call postRegister(false) if there is any problem. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
946 |
boolean registered = false; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
947 |
boolean registerFailed = false; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
948 |
ResourceContext context = null; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
949 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
950 |
try { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
951 |
mbean = injectResources(mbean, server, logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
952 |
|
2 | 953 |
if (mbean instanceof DynamicMBean2) { |
954 |
try { |
|
955 |
((DynamicMBean2) mbean).preRegister2(server, logicalName); |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
956 |
registerFailed = true; // until we succeed |
2 | 957 |
} catch (Exception e) { |
958 |
if (e instanceof RuntimeException) |
|
959 |
throw (RuntimeException) e; |
|
960 |
if (e instanceof InstanceAlreadyExistsException) |
|
961 |
throw (InstanceAlreadyExistsException) e; |
|
962 |
throw new RuntimeException(e); |
|
963 |
} |
|
964 |
} |
|
965 |
||
966 |
if (logicalName != name && logicalName != null) { |
|
967 |
logicalName = |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
968 |
ObjectName.getInstance(nonDefaultDomain(logicalName)); |
2 | 969 |
} |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
970 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
971 |
checkMBeanPermission(mbeanServerName, classname, null, logicalName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
972 |
"registerMBean"); |
2 | 973 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
974 |
if (logicalName == null) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
975 |
final RuntimeException wrapped = |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
976 |
new IllegalArgumentException("No object name specified"); |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
977 |
throw new RuntimeOperationsException(wrapped, |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
978 |
"Exception occurred trying to register the MBean"); |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
979 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
980 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
981 |
final Object resource = getResource(mbean); |
2 | 982 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
983 |
// Register the MBean with the repository. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
984 |
// Returns the resource context that was used. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
985 |
// The returned context does nothing for regular MBeans. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
986 |
// For ClassLoader MBeans and JMXNamespace (and JMXDomain) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
987 |
// MBeans - the context makes it possible to register these |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
988 |
// objects with the appropriate framework artifacts, such as |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
989 |
// the CLR or the dispatcher, from within the repository lock. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
990 |
// In case of success, we also need to call context.done() at the |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
991 |
// end of this method. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
992 |
// |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
993 |
context = registerWithRepository(resource, mbean, logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
994 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
995 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
996 |
registerFailed = false; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
997 |
registered = true; |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
998 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
999 |
} finally { |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1000 |
try { |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1001 |
postRegister(logicalName, mbean, registered, registerFailed); |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1002 |
} finally { |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1003 |
if (registered && context!=null) context.done(); |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1004 |
} |
2 | 1005 |
} |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1006 |
return new ObjectInstance(logicalName, classname); |
2 | 1007 |
} |
1008 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1009 |
private static void throwMBeanRegistrationException(Throwable t, String where) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1010 |
throws MBeanRegistrationException { |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1011 |
if (t instanceof RuntimeException) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1012 |
throw new RuntimeMBeanException((RuntimeException)t, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1013 |
"RuntimeException thrown " + where); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1014 |
} else if (t instanceof Error) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1015 |
throw new RuntimeErrorException((Error)t, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1016 |
"Error thrown " + where); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1017 |
} else if (t instanceof MBeanRegistrationException) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1018 |
throw (MBeanRegistrationException)t; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1019 |
} else if (t instanceof Exception) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1020 |
throw new MBeanRegistrationException((Exception)t, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1021 |
"Exception thrown " + where); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1022 |
} else // neither Error nor Exception?? |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1023 |
throw new RuntimeException(t); |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1024 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1025 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1026 |
private static ObjectName preRegister( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1027 |
DynamicMBean mbean, MBeanServer mbs, ObjectName name) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1028 |
throws InstanceAlreadyExistsException, MBeanRegistrationException { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1029 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1030 |
ObjectName newName = null; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1031 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1032 |
try { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1033 |
if (mbean instanceof MBeanRegistration) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1034 |
newName = ((MBeanRegistration) mbean).preRegister(mbs, name); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1035 |
} catch (Throwable t) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1036 |
throwMBeanRegistrationException(t, "in preRegister method"); |
2 | 1037 |
} |
1038 |
||
1039 |
if (newName != null) return newName; |
|
1040 |
else return name; |
|
1041 |
} |
|
1042 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1043 |
private static DynamicMBean injectResources( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1044 |
DynamicMBean mbean, MBeanServer mbs, ObjectName name) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1045 |
throws MBeanRegistrationException { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1046 |
try { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1047 |
Object resource = getResource(mbean); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1048 |
MBeanInjector.inject(resource, mbs, name); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1049 |
if (MBeanInjector.injectsSendNotification(resource)) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1050 |
NotificationBroadcasterSupport nbs = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1051 |
new NotificationBroadcasterSupport(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1052 |
MBeanInjector.injectSendNotification(resource, nbs); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1053 |
mbean = NotifySupport.wrap(mbean, nbs); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1054 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1055 |
return mbean; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1056 |
} catch (Throwable t) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1057 |
throwMBeanRegistrationException(t, "injecting @Resources"); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1058 |
return null; // not reached |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1059 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1060 |
} |
2 | 1061 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1062 |
private static void postRegister( |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1063 |
ObjectName logicalName, DynamicMBean mbean, |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1064 |
boolean registrationDone, boolean registerFailed) { |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1065 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1066 |
if (registerFailed && mbean instanceof DynamicMBean2) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1067 |
((DynamicMBean2) mbean).registerFailed(); |
2 | 1068 |
try { |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1069 |
if (mbean instanceof MBeanRegistration) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1070 |
((MBeanRegistration) mbean).postRegister(registrationDone); |
2 | 1071 |
} catch (RuntimeException e) { |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1072 |
MBEANSERVER_LOGGER.fine("While registering MBean ["+logicalName+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1073 |
"]: " + "Exception thrown by postRegister: " + |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1074 |
"rethrowing <"+e+">, but keeping the MBean registered"); |
2 | 1075 |
throw new RuntimeMBeanException(e, |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1076 |
"RuntimeException thrown in postRegister method: "+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1077 |
"rethrowing <"+e+">, but keeping the MBean registered"); |
2 | 1078 |
} catch (Error er) { |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1079 |
MBEANSERVER_LOGGER.fine("While registering MBean ["+logicalName+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1080 |
"]: " + "Error thrown by postRegister: " + |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1081 |
"rethrowing <"+er+">, but keeping the MBean registered"); |
2 | 1082 |
throw new RuntimeErrorException(er, |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1083 |
"Error thrown in postRegister method: "+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1084 |
"rethrowing <"+er+">, but keeping the MBean registered"); |
2 | 1085 |
} |
1086 |
} |
|
1087 |
||
1088 |
private static void preDeregisterInvoke(MBeanRegistration moi) |
|
1089 |
throws MBeanRegistrationException { |
|
1090 |
try { |
|
1091 |
moi.preDeregister(); |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1092 |
} catch (Throwable t) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1093 |
throwMBeanRegistrationException(t, "in preDeregister method"); |
2 | 1094 |
} |
1095 |
} |
|
1096 |
||
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1097 |
private static void postDeregisterInvoke(ObjectName mbean, |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1098 |
MBeanRegistration moi) { |
2 | 1099 |
try { |
1100 |
moi.postDeregister(); |
|
1101 |
} catch (RuntimeException e) { |
|
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1102 |
MBEANSERVER_LOGGER.fine("While unregistering MBean ["+mbean+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1103 |
"]: " + "Exception thrown by postDeregister: " + |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1104 |
"rethrowing <"+e+">, although the MBean is succesfully " + |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1105 |
"unregistered"); |
2 | 1106 |
throw new RuntimeMBeanException(e, |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1107 |
"RuntimeException thrown in postDeregister method: "+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1108 |
"rethrowing <"+e+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1109 |
">, although the MBean is sucessfully unregistered"); |
2 | 1110 |
} catch (Error er) { |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1111 |
MBEANSERVER_LOGGER.fine("While unregistering MBean ["+mbean+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1112 |
"]: " + "Error thrown by postDeregister: " + |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1113 |
"rethrowing <"+er+">, although the MBean is succesfully " + |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1114 |
"unregistered"); |
2 | 1115 |
throw new RuntimeErrorException(er, |
1002
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1116 |
"Error thrown in postDeregister method: "+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1117 |
"rethrowing <"+er+ |
1e6a1b77f22a
6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
834
diff
changeset
|
1118 |
">, although the MBean is sucessfully unregistered"); |
2 | 1119 |
} |
1120 |
} |
|
1121 |
||
1122 |
/** |
|
1123 |
* Gets a specific MBean controlled by the DefaultMBeanServerInterceptor. |
|
1124 |
* The name must have a non-default domain. |
|
1125 |
*/ |
|
1126 |
private DynamicMBean getMBean(ObjectName name) |
|
1127 |
throws InstanceNotFoundException { |
|
1128 |
||
1129 |
if (name == null) { |
|
1130 |
throw new RuntimeOperationsException(new |
|
1131 |
IllegalArgumentException("Object name cannot be null"), |
|
1132 |
"Exception occurred trying to get an MBean"); |
|
1133 |
} |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
287
diff
changeset
|
1134 |
DynamicMBean obj = repository.retrieve(name); |
2 | 1135 |
if (obj == null) { |
1136 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1137 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1138 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1139 |
"getMBean", name + " : Found no object"); |
|
1140 |
} |
|
1141 |
throw new InstanceNotFoundException(name.toString()); |
|
1142 |
} |
|
1143 |
return obj; |
|
1144 |
} |
|
1145 |
||
1146 |
private static Object getResource(DynamicMBean mbean) { |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1147 |
if (mbean instanceof DynamicWrapperMBean) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1148 |
return ((DynamicWrapperMBean) mbean).getWrappedObject(); |
2 | 1149 |
else |
1150 |
return mbean; |
|
1151 |
} |
|
1152 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1153 |
private static ClassLoader getResourceLoader(DynamicMBean mbean) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1154 |
if (mbean instanceof DynamicWrapperMBean) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1155 |
return ((DynamicWrapperMBean) mbean).getWrappedClassLoader(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1156 |
else |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1157 |
return mbean.getClass().getClassLoader(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1158 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1159 |
|
2 | 1160 |
private ObjectName nonDefaultDomain(ObjectName name) { |
1161 |
if (name == null || name.getDomain().length() > 0) |
|
1162 |
return name; |
|
1163 |
||
1164 |
/* The ObjectName looks like ":a=b", and that's what its |
|
1165 |
toString() will return in this implementation. So |
|
1166 |
we can just stick the default domain in front of it |
|
1167 |
to get a non-default-domain name. We depend on the |
|
1168 |
fact that toString() works like that and that it |
|
1169 |
leaves wildcards in place (so we can detect an error |
|
1170 |
if one is supplied where it shouldn't be). */ |
|
1171 |
final String completeName = domain + name; |
|
1172 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1173 |
return Util.newObjectName(completeName); |
2 | 1174 |
} |
1175 |
||
1176 |
public String getDefaultDomain() { |
|
1177 |
return domain; |
|
1178 |
} |
|
1179 |
||
1180 |
/* |
|
1181 |
* Notification handling. |
|
1182 |
* |
|
1183 |
* This is not trivial, because the MBeanServer translates the |
|
1184 |
* source of a received notification from a reference to an MBean |
|
1185 |
* into the ObjectName of that MBean. While that does make |
|
1186 |
* notification sending easier for MBean writers, it comes at a |
|
1187 |
* considerable cost. We need to replace the source of a |
|
1188 |
* notification, which is basically wrong if there are also |
|
1189 |
* listeners registered directly with the MBean (without going |
|
1190 |
* through the MBean server). We also need to wrap the listener |
|
1191 |
* supplied by the client of the MBeanServer with a listener that |
|
1192 |
* performs the substitution before forwarding. This is why we |
|
1193 |
* strongly discourage people from putting MBean references in the |
|
1194 |
* source of their notifications. Instead they should arrange to |
|
1195 |
* put the ObjectName there themselves. |
|
1196 |
* |
|
1197 |
* However, existing code relies on the substitution, so we are |
|
1198 |
* stuck with it. |
|
1199 |
* |
|
1200 |
* Here's how we handle it. When you add a listener, we make a |
|
1201 |
* ListenerWrapper around it. We look that up in the |
|
1202 |
* listenerWrappers map, and if there was already a wrapper for |
|
1203 |
* that listener with the given ObjectName, we reuse it. This map |
|
1204 |
* is a WeakHashMap, so a listener that is no longer registered |
|
1205 |
* with any MBean can be garbage collected. |
|
1206 |
* |
|
1207 |
* We cannot use simpler solutions such as always creating a new |
|
1208 |
* wrapper or always registering the same listener with the MBean |
|
1209 |
* and using the handback to find the client's original listener. |
|
1210 |
* The reason is that we need to support the removeListener |
|
1211 |
* variant that removes all (listener,filter,handback) triples on |
|
1212 |
* a broadcaster that have a given listener. And we do not have |
|
1213 |
* any way to inspect a broadcaster's internal list of triples. |
|
1214 |
* So the same client listener must always map to the same |
|
1215 |
* listener registered with the broadcaster. |
|
1216 |
* |
|
1217 |
* Another possible solution would be to map from ObjectName to |
|
1218 |
* list of listener wrappers (or IdentityHashMap of listener |
|
1219 |
* wrappers), making this list the first time a listener is added |
|
1220 |
* on a given MBean, and removing it when the MBean is removed. |
|
1221 |
* This is probably more costly in memory, but could be useful if |
|
1222 |
* some day we don't want to rely on weak references. |
|
1223 |
*/ |
|
1224 |
public void addNotificationListener(ObjectName name, |
|
1225 |
NotificationListener listener, |
|
1226 |
NotificationFilter filter, |
|
1227 |
Object handback) |
|
1228 |
throws InstanceNotFoundException { |
|
1229 |
||
1230 |
// ------------------------------ |
|
1231 |
// ------------------------------ |
|
1232 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1233 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1234 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1235 |
"addNotificationListener", "ObjectName = " + name); |
|
1236 |
} |
|
1237 |
||
1238 |
DynamicMBean instance = getMBean(name); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1239 |
checkMBeanPermission(mbeanServerName, instance, null, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1240 |
name, "addNotificationListener"); |
2 | 1241 |
|
1242 |
NotificationBroadcaster broadcaster = |
|
1243 |
getNotificationBroadcaster(name, instance, |
|
1244 |
NotificationBroadcaster.class); |
|
1245 |
||
1246 |
// ------------------ |
|
1247 |
// Check listener |
|
1248 |
// ------------------ |
|
1249 |
if (listener == null) { |
|
1250 |
throw new RuntimeOperationsException(new |
|
1251 |
IllegalArgumentException("Null listener"),"Null listener"); |
|
1252 |
} |
|
1253 |
||
1254 |
NotificationListener listenerWrapper = |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1255 |
getListenerWrapper(listener, name, instance, true); |
2 | 1256 |
broadcaster.addNotificationListener(listenerWrapper, filter, handback); |
1257 |
} |
|
1258 |
||
1259 |
public void addNotificationListener(ObjectName name, |
|
1260 |
ObjectName listener, |
|
1261 |
NotificationFilter filter, |
|
1262 |
Object handback) |
|
1263 |
throws InstanceNotFoundException { |
|
1264 |
||
1265 |
// ------------------------------ |
|
1266 |
// ------------------------------ |
|
1267 |
||
1268 |
// ---------------- |
|
1269 |
// Get listener object |
|
1270 |
// ---------------- |
|
1271 |
DynamicMBean instance = getMBean(listener); |
|
1272 |
Object resource = getResource(instance); |
|
1273 |
if (!(resource instanceof NotificationListener)) { |
|
1274 |
throw new RuntimeOperationsException(new |
|
1275 |
IllegalArgumentException(listener.getCanonicalName()), |
|
1276 |
"The MBean " + listener.getCanonicalName() + |
|
1277 |
"does not implement the NotificationListener interface") ; |
|
1278 |
} |
|
1279 |
||
1280 |
// ---------------- |
|
1281 |
// Add a listener on an MBean |
|
1282 |
// ---------------- |
|
1283 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1284 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1285 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1286 |
"addNotificationListener", |
|
1287 |
"ObjectName = " + name + ", Listener = " + listener); |
|
1288 |
} |
|
1289 |
server.addNotificationListener(name,(NotificationListener) resource, |
|
1290 |
filter, handback) ; |
|
1291 |
} |
|
1292 |
||
1293 |
public void removeNotificationListener(ObjectName name, |
|
1294 |
NotificationListener listener) |
|
1295 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
1296 |
removeNotificationListener(name, listener, null, null, true); |
|
1297 |
} |
|
1298 |
||
1299 |
public void removeNotificationListener(ObjectName name, |
|
1300 |
NotificationListener listener, |
|
1301 |
NotificationFilter filter, |
|
1302 |
Object handback) |
|
1303 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
1304 |
removeNotificationListener(name, listener, filter, handback, false); |
|
1305 |
} |
|
1306 |
||
1307 |
public void removeNotificationListener(ObjectName name, |
|
1308 |
ObjectName listener) |
|
1309 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
1310 |
NotificationListener instance = getListener(listener); |
|
1311 |
||
1312 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1313 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1314 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1315 |
"removeNotificationListener", |
|
1316 |
"ObjectName = " + name + ", Listener = " + listener); |
|
1317 |
} |
|
1318 |
server.removeNotificationListener(name, instance); |
|
1319 |
} |
|
1320 |
||
1321 |
public void removeNotificationListener(ObjectName name, |
|
1322 |
ObjectName listener, |
|
1323 |
NotificationFilter filter, |
|
1324 |
Object handback) |
|
1325 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
1326 |
||
1327 |
NotificationListener instance = getListener(listener); |
|
1328 |
||
1329 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1330 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1331 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1332 |
"removeNotificationListener", |
|
1333 |
"ObjectName = " + name + ", Listener = " + listener); |
|
1334 |
} |
|
1335 |
server.removeNotificationListener(name, instance, filter, handback); |
|
1336 |
} |
|
1337 |
||
1338 |
private NotificationListener getListener(ObjectName listener) |
|
1339 |
throws ListenerNotFoundException { |
|
1340 |
// ---------------- |
|
1341 |
// Get listener object |
|
1342 |
// ---------------- |
|
1343 |
DynamicMBean instance; |
|
1344 |
try { |
|
1345 |
instance = getMBean(listener); |
|
1346 |
} catch (InstanceNotFoundException e) { |
|
1347 |
throw EnvHelp.initCause( |
|
1348 |
new ListenerNotFoundException(e.getMessage()), e); |
|
1349 |
} |
|
1350 |
||
1351 |
Object resource = getResource(instance); |
|
1352 |
if (!(resource instanceof NotificationListener)) { |
|
1353 |
final RuntimeException exc = |
|
1354 |
new IllegalArgumentException(listener.getCanonicalName()); |
|
1355 |
final String msg = |
|
1356 |
"MBean " + listener.getCanonicalName() + " does not " + |
|
1357 |
"implement " + NotificationListener.class.getName(); |
|
1358 |
throw new RuntimeOperationsException(exc, msg); |
|
1359 |
} |
|
1360 |
return (NotificationListener) resource; |
|
1361 |
} |
|
1362 |
||
1363 |
private void removeNotificationListener(ObjectName name, |
|
1364 |
NotificationListener listener, |
|
1365 |
NotificationFilter filter, |
|
1366 |
Object handback, |
|
1367 |
boolean removeAll) |
|
1368 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
1369 |
||
1370 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1371 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1372 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1373 |
"removeNotificationListener", "ObjectName = " + name); |
|
1374 |
} |
|
1375 |
||
1376 |
DynamicMBean instance = getMBean(name); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1377 |
checkMBeanPermission(mbeanServerName, instance, null, name, |
2 | 1378 |
"removeNotificationListener"); |
1379 |
||
1380 |
/* We could simplify the code by assigning broadcaster after |
|
1381 |
assigning listenerWrapper, but that would change the error |
|
1382 |
behavior when both the broadcaster and the listener are |
|
1383 |
erroneous. */ |
|
1384 |
||
1385 |
Class<? extends NotificationBroadcaster> reqClass = |
|
1386 |
removeAll ? NotificationBroadcaster.class : NotificationEmitter.class; |
|
1387 |
NotificationBroadcaster broadcaster = |
|
1388 |
getNotificationBroadcaster(name, instance, reqClass); |
|
1389 |
||
1390 |
NotificationListener listenerWrapper = |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1391 |
getListenerWrapper(listener, name, instance, false); |
2 | 1392 |
|
1393 |
if (listenerWrapper == null) |
|
1394 |
throw new ListenerNotFoundException("Unknown listener"); |
|
1395 |
||
1396 |
if (removeAll) |
|
1397 |
broadcaster.removeNotificationListener(listenerWrapper); |
|
1398 |
else { |
|
1399 |
NotificationEmitter emitter = (NotificationEmitter) broadcaster; |
|
1400 |
emitter.removeNotificationListener(listenerWrapper, |
|
1401 |
filter, |
|
1402 |
handback); |
|
1403 |
} |
|
1404 |
} |
|
1405 |
||
1406 |
private static <T extends NotificationBroadcaster> |
|
1407 |
T getNotificationBroadcaster(ObjectName name, Object instance, |
|
1408 |
Class<T> reqClass) { |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1409 |
if (reqClass.isInstance(instance)) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1410 |
return reqClass.cast(instance); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1411 |
if (instance instanceof DynamicWrapperMBean) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1412 |
instance = ((DynamicWrapperMBean) instance).getWrappedObject(); |
2 | 1413 |
if (reqClass.isInstance(instance)) |
1414 |
return reqClass.cast(instance); |
|
1415 |
final RuntimeException exc = |
|
1416 |
new IllegalArgumentException(name.getCanonicalName()); |
|
1417 |
final String msg = |
|
1418 |
"MBean " + name.getCanonicalName() + " does not " + |
|
1419 |
"implement " + reqClass.getName(); |
|
1420 |
throw new RuntimeOperationsException(exc, msg); |
|
1421 |
} |
|
1422 |
||
1423 |
public MBeanInfo getMBeanInfo(ObjectName name) |
|
1424 |
throws InstanceNotFoundException, IntrospectionException, |
|
1425 |
ReflectionException { |
|
1426 |
||
1427 |
// ------------------------------ |
|
1428 |
// ------------------------------ |
|
1429 |
||
1430 |
DynamicMBean moi = getMBean(name); |
|
1431 |
final MBeanInfo mbi; |
|
1432 |
try { |
|
1433 |
mbi = moi.getMBeanInfo(); |
|
1434 |
} catch (RuntimeMBeanException e) { |
|
1435 |
throw e; |
|
1436 |
} catch (RuntimeErrorException e) { |
|
1437 |
throw e; |
|
1438 |
} catch (RuntimeException e) { |
|
1439 |
throw new RuntimeMBeanException(e, |
|
1440 |
"getMBeanInfo threw RuntimeException"); |
|
1441 |
} catch (Error e) { |
|
1442 |
throw new RuntimeErrorException(e, "getMBeanInfo threw Error"); |
|
1443 |
} |
|
1444 |
if (mbi == null) |
|
1445 |
throw new JMRuntimeException("MBean " + name + |
|
1446 |
"has no MBeanInfo"); |
|
1447 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1448 |
checkMBeanPermission(mbeanServerName, mbi.getClassName(), null, name, "getMBeanInfo"); |
2 | 1449 |
|
1450 |
return mbi; |
|
1451 |
} |
|
1452 |
||
1453 |
public boolean isInstanceOf(ObjectName name, String className) |
|
1454 |
throws InstanceNotFoundException { |
|
1455 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1456 |
final DynamicMBean instance = getMBean(name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1457 |
checkMBeanPermission(mbeanServerName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1458 |
instance, null, name, "isInstanceOf"); |
2 | 1459 |
|
1460 |
try { |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1461 |
Object resource = getResource(instance); |
2 | 1462 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1463 |
final String resourceClassName = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1464 |
(resource instanceof DynamicMBean) ? |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1465 |
getClassName((DynamicMBean) resource) : |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1466 |
resource.getClass().getName(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1467 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1468 |
if (resourceClassName.equals(className)) |
2 | 1469 |
return true; |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1470 |
final ClassLoader cl = getResourceLoader(instance); |
2 | 1471 |
|
1472 |
final Class<?> classNameClass = Class.forName(className, false, cl); |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1473 |
if (classNameClass.isInstance(resource)) |
2 | 1474 |
return true; |
1475 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1476 |
// Ensure that isInstanceOf(NotificationEmitter) is true when |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1477 |
// the MBean is a NotificationEmitter by virtue of a @Resource |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1478 |
// annotation specifying a SendNotification resource. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1479 |
// This is a hack. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1480 |
if (instance instanceof NotificationBroadcaster && |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1481 |
classNameClass.isAssignableFrom(NotificationEmitter.class)) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1482 |
return true; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1483 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1484 |
final Class<?> resourceClass = Class.forName(resourceClassName, false, cl); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1485 |
return classNameClass.isAssignableFrom(resourceClass); |
2 | 1486 |
} catch (Exception x) { |
1487 |
/* Could be SecurityException or ClassNotFoundException */ |
|
1488 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) { |
|
1489 |
MBEANSERVER_LOGGER.logp(Level.FINEST, |
|
1490 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1491 |
"isInstanceOf", "Exception calling isInstanceOf", x); |
|
1492 |
} |
|
1493 |
return false; |
|
1494 |
} |
|
1495 |
||
1496 |
} |
|
1497 |
||
1498 |
/** |
|
1499 |
* <p>Return the {@link java.lang.ClassLoader} that was used for |
|
1500 |
* loading the class of the named MBean. |
|
1501 |
* @param mbeanName The ObjectName of the MBean. |
|
1502 |
* @return The ClassLoader used for that MBean. |
|
1503 |
* @exception InstanceNotFoundException if the named MBean is not found. |
|
1504 |
*/ |
|
1505 |
public ClassLoader getClassLoaderFor(ObjectName mbeanName) |
|
1506 |
throws InstanceNotFoundException { |
|
1507 |
||
1508 |
DynamicMBean instance = getMBean(mbeanName); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1509 |
checkMBeanPermission(mbeanServerName, instance, null, mbeanName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1510 |
"getClassLoaderFor"); |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1511 |
return getResourceLoader(instance); |
2 | 1512 |
} |
1513 |
||
1514 |
/** |
|
1515 |
* <p>Return the named {@link java.lang.ClassLoader}. |
|
1516 |
* @param loaderName The ObjectName of the ClassLoader. |
|
1517 |
* @return The named ClassLoader. |
|
1518 |
* @exception InstanceNotFoundException if the named ClassLoader |
|
1519 |
* is not found. |
|
1520 |
*/ |
|
1521 |
public ClassLoader getClassLoader(ObjectName loaderName) |
|
1522 |
throws InstanceNotFoundException { |
|
1523 |
||
1524 |
if (loaderName == null) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1525 |
checkMBeanPermission(mbeanServerName, (String) null, null, null, "getClassLoader"); |
2 | 1526 |
return server.getClass().getClassLoader(); |
1527 |
} |
|
1528 |
||
1529 |
DynamicMBean instance = getMBean(loaderName); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1530 |
checkMBeanPermission(mbeanServerName, instance, null, loaderName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1531 |
"getClassLoader"); |
2 | 1532 |
|
1533 |
Object resource = getResource(instance); |
|
1534 |
||
1535 |
/* Check if the given MBean is a ClassLoader */ |
|
1536 |
if (!(resource instanceof ClassLoader)) |
|
1537 |
throw new InstanceNotFoundException(loaderName.toString() + |
|
1538 |
" is not a classloader"); |
|
1539 |
||
1540 |
return (ClassLoader) resource; |
|
1541 |
} |
|
1542 |
||
1543 |
/** |
|
1544 |
* Sends an MBeanServerNotifications with the specified type for the |
|
1545 |
* MBean with the specified ObjectName |
|
1546 |
*/ |
|
1547 |
private void sendNotification(String NotifType, ObjectName name) { |
|
1548 |
||
1549 |
// ------------------------------ |
|
1550 |
// ------------------------------ |
|
1551 |
||
1552 |
// --------------------- |
|
1553 |
// Create notification |
|
1554 |
// --------------------- |
|
1555 |
MBeanServerNotification notif = new MBeanServerNotification( |
|
1556 |
NotifType,MBeanServerDelegate.DELEGATE_NAME,0,name); |
|
1557 |
||
1558 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
|
1559 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
|
1560 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1561 |
"sendNotification", NotifType + " " + name); |
|
1562 |
} |
|
1563 |
||
1564 |
delegate.sendNotification(notif); |
|
1565 |
} |
|
1566 |
||
1567 |
/** |
|
1568 |
* Applies the specified queries to the set of NamedObjects. |
|
1569 |
*/ |
|
1570 |
private Set<ObjectName> |
|
1571 |
objectNamesFromFilteredNamedObjects(Set<NamedObject> list, |
|
1572 |
QueryExp query) { |
|
1573 |
Set<ObjectName> result = new HashSet<ObjectName>(); |
|
1574 |
// No query ... |
|
1575 |
if (query == null) { |
|
1576 |
for (NamedObject no : list) { |
|
1577 |
result.add(no.getName()); |
|
1578 |
} |
|
1579 |
} else { |
|
1580 |
// Access the filter |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1581 |
final MBeanServer oldServer = QueryEval.getMBeanServer(); |
2 | 1582 |
query.setMBeanServer(server); |
1583 |
try { |
|
1584 |
for (NamedObject no : list) { |
|
1585 |
boolean res; |
|
1586 |
try { |
|
1587 |
res = query.apply(no.getName()); |
|
1588 |
} catch (Exception e) { |
|
1589 |
res = false; |
|
1590 |
} |
|
1591 |
if (res) { |
|
1592 |
result.add(no.getName()); |
|
1593 |
} |
|
1594 |
} |
|
1595 |
} finally { |
|
1596 |
/* |
|
1597 |
* query.setMBeanServer is probably |
|
1598 |
* QueryEval.setMBeanServer so put back the old |
|
1599 |
* value. Since that method uses a ThreadLocal |
|
1600 |
* variable, this code is only needed for the |
|
1601 |
* unusual case where the user creates a custom |
|
1602 |
* QueryExp that calls a nested query on another |
|
1603 |
* MBeanServer. |
|
1604 |
*/ |
|
1605 |
query.setMBeanServer(oldServer); |
|
1606 |
} |
|
1607 |
} |
|
1608 |
return result; |
|
1609 |
} |
|
1610 |
||
1611 |
/** |
|
1612 |
* Applies the specified queries to the set of NamedObjects. |
|
1613 |
*/ |
|
1614 |
private Set<ObjectInstance> |
|
1615 |
objectInstancesFromFilteredNamedObjects(Set<NamedObject> list, |
|
1616 |
QueryExp query) { |
|
1617 |
Set<ObjectInstance> result = new HashSet<ObjectInstance>(); |
|
1618 |
// No query ... |
|
1619 |
if (query == null) { |
|
1620 |
for (NamedObject no : list) { |
|
1621 |
final DynamicMBean obj = no.getObject(); |
|
1622 |
final String className = safeGetClassName(obj); |
|
1623 |
result.add(new ObjectInstance(no.getName(), className)); |
|
1624 |
} |
|
1625 |
} else { |
|
1626 |
// Access the filter |
|
1627 |
MBeanServer oldServer = QueryEval.getMBeanServer(); |
|
1628 |
query.setMBeanServer(server); |
|
1629 |
try { |
|
1630 |
for (NamedObject no : list) { |
|
1631 |
final DynamicMBean obj = no.getObject(); |
|
1632 |
boolean res; |
|
1633 |
try { |
|
1634 |
res = query.apply(no.getName()); |
|
1635 |
} catch (Exception e) { |
|
1636 |
res = false; |
|
1637 |
} |
|
1638 |
if (res) { |
|
1639 |
String className = safeGetClassName(obj); |
|
1640 |
result.add(new ObjectInstance(no.getName(), className)); |
|
1641 |
} |
|
1642 |
} |
|
1643 |
} finally { |
|
1644 |
/* |
|
1645 |
* query.setMBeanServer is probably |
|
1646 |
* QueryEval.setMBeanServer so put back the old |
|
1647 |
* value. Since that method uses a ThreadLocal |
|
1648 |
* variable, this code is only needed for the |
|
1649 |
* unusual case where the user creates a custom |
|
1650 |
* QueryExp that calls a nested query on another |
|
1651 |
* MBeanServer. |
|
1652 |
*/ |
|
1653 |
query.setMBeanServer(oldServer); |
|
1654 |
} |
|
1655 |
} |
|
1656 |
return result; |
|
1657 |
} |
|
1658 |
||
1659 |
private static String safeGetClassName(DynamicMBean mbean) { |
|
1660 |
try { |
|
1661 |
return getClassName(mbean); |
|
1662 |
} catch (Exception e) { |
|
1663 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) { |
|
1664 |
MBEANSERVER_LOGGER.logp(Level.FINEST, |
|
1665 |
DefaultMBeanServerInterceptor.class.getName(), |
|
1666 |
"safeGetClassName", |
|
1667 |
"Exception getting MBean class name", e); |
|
1668 |
} |
|
1669 |
return null; |
|
1670 |
} |
|
1671 |
} |
|
1672 |
||
1673 |
/** |
|
1674 |
* Applies the specified queries to the set of ObjectInstances. |
|
1675 |
*/ |
|
1676 |
private Set<ObjectInstance> |
|
1677 |
filterListOfObjectInstances(Set<ObjectInstance> list, |
|
1678 |
QueryExp query) { |
|
1679 |
// Null query. |
|
1680 |
// |
|
1681 |
if (query == null) { |
|
1682 |
return list; |
|
1683 |
} else { |
|
1684 |
Set<ObjectInstance> result = new HashSet<ObjectInstance>(); |
|
1685 |
// Access the filter. |
|
1686 |
// |
|
1687 |
for (ObjectInstance oi : list) { |
|
1688 |
boolean res = false; |
|
1689 |
MBeanServer oldServer = QueryEval.getMBeanServer(); |
|
1690 |
query.setMBeanServer(server); |
|
1691 |
try { |
|
1692 |
res = query.apply(oi.getObjectName()); |
|
1693 |
} catch (Exception e) { |
|
1694 |
res = false; |
|
1695 |
} finally { |
|
1696 |
/* |
|
1697 |
* query.setMBeanServer is probably |
|
1698 |
* QueryEval.setMBeanServer so put back the old |
|
1699 |
* value. Since that method uses a ThreadLocal |
|
1700 |
* variable, this code is only needed for the |
|
1701 |
* unusual case where the user creates a custom |
|
1702 |
* QueryExp that calls a nested query on another |
|
1703 |
* MBeanServer. |
|
1704 |
*/ |
|
1705 |
query.setMBeanServer(oldServer); |
|
1706 |
} |
|
1707 |
if (res) { |
|
1708 |
result.add(oi); |
|
1709 |
} |
|
1710 |
} |
|
1711 |
return result; |
|
1712 |
} |
|
1713 |
} |
|
1714 |
||
1715 |
/* |
|
1716 |
* Get the existing wrapper for this listener, name, and mbean, if |
|
1717 |
* there is one. Otherwise, if "create" is true, create and |
|
1718 |
* return one. Otherwise, return null. |
|
1719 |
* |
|
1720 |
* We use a WeakHashMap so that if the only reference to a user |
|
1721 |
* listener is in listenerWrappers, it can be garbage collected. |
|
1722 |
* This requires a certain amount of care, because only the key in |
|
1723 |
* a WeakHashMap is weak; the value is strong. We need to recover |
|
1724 |
* the existing wrapper object (not just an object that is equal |
|
1725 |
* to it), so we would like listenerWrappers to map any |
|
1726 |
* ListenerWrapper to the canonical ListenerWrapper for that |
|
1727 |
* (listener,name,mbean) set. But we do not want this canonical |
|
1728 |
* wrapper to be referenced strongly. Therefore we put it inside |
|
1729 |
* a WeakReference and that is the value in the WeakHashMap. |
|
1730 |
*/ |
|
1731 |
private NotificationListener getListenerWrapper(NotificationListener l, |
|
1732 |
ObjectName name, |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1733 |
DynamicMBean mbean, |
2 | 1734 |
boolean create) { |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1735 |
Object resource = getResource(mbean); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1736 |
ListenerWrapper wrapper = new ListenerWrapper(l, name, resource); |
2 | 1737 |
synchronized (listenerWrappers) { |
1738 |
WeakReference<ListenerWrapper> ref = listenerWrappers.get(wrapper); |
|
1739 |
if (ref != null) { |
|
1740 |
NotificationListener existing = ref.get(); |
|
1741 |
if (existing != null) |
|
1742 |
return existing; |
|
1743 |
} |
|
1744 |
if (create) { |
|
1745 |
ref = new WeakReference<ListenerWrapper>(wrapper); |
|
1746 |
listenerWrappers.put(wrapper, ref); |
|
1747 |
return wrapper; |
|
1748 |
} else |
|
1749 |
return null; |
|
1750 |
} |
|
1751 |
} |
|
1752 |
||
1753 |
private static class ListenerWrapper implements NotificationListener { |
|
1754 |
ListenerWrapper(NotificationListener l, ObjectName name, |
|
1755 |
Object mbean) { |
|
1756 |
this.listener = l; |
|
1757 |
this.name = name; |
|
1758 |
this.mbean = mbean; |
|
1759 |
} |
|
1760 |
||
1761 |
public void handleNotification(Notification notification, |
|
1762 |
Object handback) { |
|
1763 |
if (notification != null) { |
|
1764 |
if (notification.getSource() == mbean) |
|
1765 |
notification.setSource(name); |
|
1766 |
} |
|
1767 |
||
1768 |
/* |
|
1769 |
* Listeners are not supposed to throw exceptions. If |
|
1770 |
* this one does, we could remove it from the MBean. It |
|
1771 |
* might indicate that a connector has stopped working, |
|
1772 |
* for instance, and there is no point in sending future |
|
1773 |
* notifications over that connection. However, this |
|
1774 |
* seems rather drastic, so instead we propagate the |
|
1775 |
* exception and let the broadcaster handle it. |
|
1776 |
*/ |
|
1777 |
listener.handleNotification(notification, handback); |
|
1778 |
} |
|
1779 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1780 |
@Override |
2 | 1781 |
public boolean equals(Object o) { |
1782 |
if (!(o instanceof ListenerWrapper)) |
|
1783 |
return false; |
|
1784 |
ListenerWrapper w = (ListenerWrapper) o; |
|
1785 |
return (w.listener == listener && w.mbean == mbean |
|
1786 |
&& w.name.equals(name)); |
|
1787 |
/* |
|
1788 |
* We compare all three, in case the same MBean object |
|
1789 |
* gets unregistered and then reregistered under a |
|
1790 |
* different name, or the same name gets assigned to two |
|
1791 |
* different MBean objects at different times. We do the |
|
1792 |
* comparisons in this order to avoid the slow |
|
1793 |
* ObjectName.equals when possible. |
|
1794 |
*/ |
|
1795 |
} |
|
1796 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1797 |
@Override |
2 | 1798 |
public int hashCode() { |
1799 |
return (System.identityHashCode(listener) ^ |
|
1800 |
System.identityHashCode(mbean)); |
|
1801 |
/* |
|
1802 |
* We do not include name.hashCode() in the hash because |
|
1803 |
* computing it is slow and usually we will not have two |
|
1804 |
* instances of ListenerWrapper with the same mbean but |
|
1805 |
* different ObjectNames. That can happen if the MBean is |
|
1806 |
* unregistered from one name and reregistered with |
|
1807 |
* another, and there is no garbage collection between; or |
|
1808 |
* if the same object is registered under two names (which |
|
1809 |
* is not recommended because MBeanRegistration will |
|
1810 |
* break). But even in these unusual cases the hash code |
|
1811 |
* does not have to be unique. |
|
1812 |
*/ |
|
1813 |
} |
|
1814 |
||
1815 |
private NotificationListener listener; |
|
1816 |
private ObjectName name; |
|
1817 |
private Object mbean; |
|
1818 |
} |
|
1819 |
||
1820 |
// SECURITY CHECKS |
|
1821 |
//---------------- |
|
1822 |
||
1823 |
private static String getClassName(DynamicMBean mbean) { |
|
1824 |
if (mbean instanceof DynamicMBean2) |
|
1825 |
return ((DynamicMBean2) mbean).getClassName(); |
|
1826 |
else |
|
1827 |
return mbean.getMBeanInfo().getClassName(); |
|
1828 |
} |
|
1829 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1830 |
private static void checkMBeanPermission(String mbeanServerName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1831 |
DynamicMBean mbean, |
2 | 1832 |
String member, |
1833 |
ObjectName objectName, |
|
1834 |
String actions) { |
|
1835 |
SecurityManager sm = System.getSecurityManager(); |
|
1836 |
if (sm != null) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1837 |
checkMBeanPermission(mbeanServerName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1838 |
safeGetClassName(mbean), |
2 | 1839 |
member, |
1840 |
objectName, |
|
1841 |
actions); |
|
1842 |
} |
|
1843 |
} |
|
1844 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1845 |
private static void checkMBeanPermission(String mbeanServerName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1846 |
String classname, |
2 | 1847 |
String member, |
1848 |
ObjectName objectName, |
|
1849 |
String actions) { |
|
1850 |
SecurityManager sm = System.getSecurityManager(); |
|
1851 |
if (sm != null) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1852 |
Permission perm = new MBeanPermission(mbeanServerName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1853 |
classname, |
2 | 1854 |
member, |
1855 |
objectName, |
|
1856 |
actions); |
|
1857 |
sm.checkPermission(perm); |
|
1858 |
} |
|
1859 |
} |
|
1860 |
||
1861 |
private static void checkMBeanTrustPermission(final Class theClass) |
|
1862 |
throws SecurityException { |
|
1863 |
SecurityManager sm = System.getSecurityManager(); |
|
1864 |
if (sm != null) { |
|
1865 |
Permission perm = new MBeanTrustPermission("register"); |
|
1866 |
PrivilegedAction<ProtectionDomain> act = |
|
1867 |
new PrivilegedAction<ProtectionDomain>() { |
|
1868 |
public ProtectionDomain run() { |
|
1869 |
return theClass.getProtectionDomain(); |
|
1870 |
} |
|
1871 |
}; |
|
1872 |
ProtectionDomain pd = AccessController.doPrivileged(act); |
|
1873 |
AccessControlContext acc = |
|
1874 |
new AccessControlContext(new ProtectionDomain[] { pd }); |
|
1875 |
sm.checkPermission(perm, acc); |
|
1876 |
} |
|
1877 |
} |
|
1878 |
||
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1879 |
// ------------------------------------------------------------------ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1880 |
// |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1881 |
// Dealing with registration of special MBeans in the repository. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1882 |
// |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1883 |
// ------------------------------------------------------------------ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1884 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1885 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1886 |
* A RegistrationContext that makes it possible to perform additional |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1887 |
* post registration actions (or post unregistration actions) outside |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1888 |
* of the repository lock, once postRegister (or postDeregister) has |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1889 |
* been called. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1890 |
* The method {@code done()} will be called in registerMBean or |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1891 |
* unregisterMBean, at the end. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1892 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1893 |
private static interface ResourceContext extends RegistrationContext { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1894 |
public void done(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1895 |
/** An empty ResourceContext which does nothing **/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1896 |
public static final ResourceContext NONE = new ResourceContext() { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1897 |
public void done() {} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1898 |
public void registering() {} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1899 |
public void unregistered() {} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1900 |
}; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1901 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1902 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1903 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1904 |
* Adds a MBean in the repository, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1905 |
* sends MBeanServerNotification.REGISTRATION_NOTIFICATION, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1906 |
* returns ResourceContext for special resources such as ClassLoaders |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1907 |
* or JMXNamespaces. For regular MBean this method returns |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1908 |
* ResourceContext.NONE. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1909 |
* @return a ResourceContext for special resources such as ClassLoaders |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1910 |
* or JMXNamespaces. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1911 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1912 |
private ResourceContext registerWithRepository( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1913 |
final Object resource, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1914 |
final DynamicMBean object, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1915 |
final ObjectName logicalName) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1916 |
throws InstanceAlreadyExistsException, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1917 |
MBeanRegistrationException { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1918 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1919 |
// this will throw an exception if the pair (resource, logicalName) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1920 |
// violates namespace conventions - for instance, if logicalName |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1921 |
// ends with // but resource is not a JMXNamespace. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1922 |
// |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1923 |
checkResourceObjectNameConstraints(resource, logicalName); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1924 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1925 |
// Creates a registration context, if needed. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1926 |
// |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1927 |
final ResourceContext context = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1928 |
makeResourceContextFor(resource, logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1929 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1930 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1931 |
repository.addMBean(object, logicalName, context); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1932 |
// May throw InstanceAlreadyExistsException |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1933 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1934 |
// --------------------- |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1935 |
// Send create event |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1936 |
// --------------------- |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1937 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1938 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1939 |
DefaultMBeanServerInterceptor.class.getName(), |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1940 |
"addObject", "Send create notification of object " + |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1941 |
logicalName.getCanonicalName()); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1942 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1943 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1944 |
sendNotification( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1945 |
MBeanServerNotification.REGISTRATION_NOTIFICATION, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1946 |
logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1947 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1948 |
return context; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1949 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1950 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1951 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1952 |
* Removes a MBean in the repository, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1953 |
* sends MBeanServerNotification.UNREGISTRATION_NOTIFICATION, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1954 |
* returns ResourceContext for special resources such as ClassLoaders |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1955 |
* or JMXNamespaces, or null. For regular MBean this method returns |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1956 |
* ResourceContext.NONE. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1957 |
* |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1958 |
* @return a ResourceContext for special resources such as ClassLoaders |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1959 |
* or JMXNamespaces. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1960 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1961 |
private ResourceContext unregisterFromRepository( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1962 |
final Object resource, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1963 |
final DynamicMBean object, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1964 |
final ObjectName logicalName) |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1965 |
throws InstanceNotFoundException { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1966 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1967 |
// Creates a registration context, if needed. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1968 |
// |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1969 |
final ResourceContext context = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1970 |
makeResourceContextFor(resource, logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1971 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1972 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1973 |
repository.remove(logicalName, context); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1974 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1975 |
// --------------------- |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1976 |
// Send deletion event |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1977 |
// --------------------- |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1978 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1979 |
MBEANSERVER_LOGGER.logp(Level.FINER, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1980 |
DefaultMBeanServerInterceptor.class.getName(), |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1981 |
"unregisterMBean", "Send delete notification of object " + |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1982 |
logicalName.getCanonicalName()); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1983 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1984 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1985 |
sendNotification(MBeanServerNotification.UNREGISTRATION_NOTIFICATION, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1986 |
logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1987 |
return context; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1988 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
1989 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1990 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1991 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1992 |
* Checks that the ObjectName is legal with regards to the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1993 |
* type of the MBean resource. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1994 |
* If the MBean name is domain:type=JMXDomain, the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1995 |
* MBean must be a JMXDomain. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1996 |
* If the MBean name is namespace//:type=JMXNamespace, the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1997 |
* MBean must be a JMXNamespace. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1998 |
* If the MBean is a JMXDomain, its name |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
1999 |
* must be domain:type=JMXDomain. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2000 |
* If the MBean is a JMXNamespace, its name |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2001 |
* must be namespace//:type=JMXNamespace. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2002 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2003 |
private void checkResourceObjectNameConstraints(Object resource, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2004 |
ObjectName logicalName) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2005 |
throws MBeanRegistrationException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2006 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2007 |
dispatcher.checkLocallyRegistrable(resource, logicalName); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2008 |
} catch (Throwable x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2009 |
DefaultMBeanServerInterceptor.throwMBeanRegistrationException(x, "validating ObjectName"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2010 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2011 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2012 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2013 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2014 |
* Registers a JMXNamespace with the dispatcher. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2015 |
* This method is called by the ResourceContext from within the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2016 |
* repository lock. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2017 |
* @param namespace The JMXNamespace |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2018 |
* @param logicalName The JMXNamespaceMBean ObjectName |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2019 |
* @param postQueue A queue that will be processed after postRegister. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2020 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2021 |
private void addJMXNamespace(JMXNamespace namespace, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2022 |
final ObjectName logicalName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2023 |
final Queue<Runnable> postQueue) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2024 |
dispatcher.addNamespace(logicalName, namespace, postQueue); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2025 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2026 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2027 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2028 |
* Unregisters a JMXNamespace from the dispatcher. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2029 |
* This method is called by the ResourceContext from within the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2030 |
* repository lock. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2031 |
* @param namespace The JMXNamespace |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2032 |
* @param logicalName The JMXNamespaceMBean ObjectName |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2033 |
* @param postQueue A queue that will be processed after postDeregister. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2034 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2035 |
private void removeJMXNamespace(JMXNamespace namespace, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2036 |
final ObjectName logicalName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2037 |
final Queue<Runnable> postQueue) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2038 |
dispatcher.removeNamespace(logicalName, namespace, postQueue); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2039 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2040 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2041 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2042 |
* Registers a ClassLoader with the CLR. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2043 |
* This method is called by the ResourceContext from within the |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2044 |
* repository lock. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2045 |
* @param loader The ClassLoader. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2046 |
* @param logicalName The ClassLoader MBean ObjectName. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2047 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2048 |
private void addClassLoader(ClassLoader loader, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2049 |
final ObjectName logicalName) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2050 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2051 |
* Called when the newly registered MBean is a ClassLoader |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2052 |
* If so, tell the ClassLoaderRepository (CLR) about it. We do |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2053 |
* this even if the loader is a PrivateClassLoader. In that |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2054 |
* case, the CLR remembers the loader for use when it is |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2055 |
* explicitly named (e.g. as the loader in createMBean) but |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2056 |
* does not add it to the list that is consulted by |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2057 |
* ClassLoaderRepository.loadClass. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2058 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2059 |
final ModifiableClassLoaderRepository clr = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2060 |
instantiator.getClassLoaderRepository(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2061 |
if (clr == null) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2062 |
final RuntimeException wrapped = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2063 |
new IllegalArgumentException( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2064 |
"Dynamic addition of class loaders" + |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2065 |
" is not supported"); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2066 |
throw new RuntimeOperationsException(wrapped, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2067 |
"Exception occurred trying to register" + |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2068 |
" the MBean as a class loader"); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2069 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2070 |
clr.addClassLoader(logicalName, loader); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2071 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2072 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2073 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2074 |
* Unregisters a ClassLoader from the CLR. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2075 |
* This method is called by the ResourceContext from within the |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2076 |
* repository lock. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2077 |
* @param loader The ClassLoader. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2078 |
* @param logicalName The ClassLoader MBean ObjectName. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2079 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2080 |
private void removeClassLoader(ClassLoader loader, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2081 |
final ObjectName logicalName) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2082 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2083 |
* Removes the MBean from the default loader repository. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2084 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2085 |
if (loader != server.getClass().getClassLoader()) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2086 |
final ModifiableClassLoaderRepository clr = |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2087 |
instantiator.getClassLoaderRepository(); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2088 |
if (clr != null) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2089 |
clr.removeClassLoader(logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2090 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2091 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2092 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2093 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2094 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2095 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2096 |
* Creates a ResourceContext for a JMXNamespace MBean. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2097 |
* The resource context makes it possible to add the JMXNamespace to |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2098 |
* (ResourceContext.registering) or resp. remove the JMXNamespace from |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2099 |
* (ResourceContext.unregistered) the NamespaceDispatchInterceptor |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2100 |
* when the associated MBean is added to or resp. removed from the |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2101 |
* repository. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2102 |
* Note: JMXDomains are special sub classes of JMXNamespaces and |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2103 |
* are also handled by this object. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2104 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2105 |
* @param namespace The JMXNamespace MBean being registered or |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2106 |
* unregistered. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2107 |
* @param logicalName The name of the JMXNamespace MBean. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2108 |
* @return a ResourceContext that takes in charge the addition or removal |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2109 |
* of the namespace to or from the NamespaceDispatchInterceptor. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2110 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2111 |
private ResourceContext createJMXNamespaceContext( |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2112 |
final JMXNamespace namespace, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2113 |
final ObjectName logicalName) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2114 |
final Queue<Runnable> doneTaskQueue = new LinkedList<Runnable>(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2115 |
return new ResourceContext() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2116 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2117 |
public void registering() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2118 |
addJMXNamespace(namespace, logicalName, doneTaskQueue); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2119 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2120 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2121 |
public void unregistered() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2122 |
removeJMXNamespace(namespace, logicalName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2123 |
doneTaskQueue); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2124 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2125 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2126 |
public void done() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2127 |
for (Runnable r : doneTaskQueue) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2128 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2129 |
r.run(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2130 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2131 |
MBEANSERVER_LOGGER.log(Level.FINE, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2132 |
"Failed to process post queue for "+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2133 |
logicalName, x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2134 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2135 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2136 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2137 |
}; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2138 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2139 |
|
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2140 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2141 |
* Creates a ResourceContext for a ClassLoader MBean. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2142 |
* The resource context makes it possible to add the ClassLoader to |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2143 |
* (ResourceContext.registering) or resp. remove the ClassLoader from |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2144 |
* (ResourceContext.unregistered) the CLR |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2145 |
* when the associated MBean is added to or resp. removed from the |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2146 |
* repository. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2147 |
* |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2148 |
* @param loader The ClassLoader MBean being registered or |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2149 |
* unregistered. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2150 |
* @param logicalName The name of the ClassLoader MBean. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2151 |
* @return a ResourceContext that takes in charge the addition or removal |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2152 |
* of the loader to or from the CLR. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2153 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2154 |
private ResourceContext createClassLoaderContext( |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2155 |
final ClassLoader loader, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2156 |
final ObjectName logicalName) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2157 |
return new ResourceContext() { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2158 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2159 |
public void registering() { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2160 |
addClassLoader(loader, logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2161 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2162 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2163 |
public void unregistered() { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2164 |
removeClassLoader(loader, logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2165 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2166 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2167 |
public void done() { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2168 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2169 |
}; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2170 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2171 |
|
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2172 |
/** |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2173 |
* Creates a ResourceContext for the given resource. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2174 |
* If the resource does not need a ResourceContext, returns |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2175 |
* ResourceContext.NONE. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2176 |
* At this time, only JMXNamespaces and ClassLoaders need a |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2177 |
* ResourceContext. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2178 |
* |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2179 |
* @param resource The resource being registered or unregistered. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2180 |
* @param logicalName The name of the associated MBean. |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2181 |
* @return |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2182 |
*/ |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2183 |
private ResourceContext makeResourceContextFor(Object resource, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2184 |
ObjectName logicalName) { |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2185 |
if (resource instanceof JMXNamespace) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2186 |
return createJMXNamespaceContext((JMXNamespace) resource, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2187 |
logicalName); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2188 |
} |
833
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2189 |
if (resource instanceof ClassLoader) { |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2190 |
return createClassLoaderContext((ClassLoader) resource, |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2191 |
logicalName); |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2192 |
} |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2193 |
return ResourceContext.NONE; |
bfa2bef7517c
6323980: Annotations to simplify MBean development
emcmanus
parents:
526
diff
changeset
|
2194 |
} |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2195 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1002
diff
changeset
|
2196 |
|
2 | 2197 |
} |