author | dfuchs |
Thu, 04 Sep 2008 14:46:36 +0200 | |
changeset 1156 | bbc2d15aaf7a |
parent 2 | 90ce3da70b43 |
child 1510 | e747d3193ef2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
2 |
* Copyright 1999-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.mbeanserver; |
|
27 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
28 |
import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
29 |
import com.sun.jmx.interceptor.NamespaceDispatchInterceptor; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
30 |
|
2 | 31 |
import java.io.ObjectInputStream; |
32 |
import java.security.AccessController; |
|
33 |
import java.security.Permission; |
|
34 |
import java.security.PrivilegedExceptionAction; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
35 |
import java.util.Iterator; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
36 |
import java.util.Set; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
37 |
import java.util.logging.Level; |
2 | 38 |
|
39 |
import javax.management.Attribute; |
|
40 |
import javax.management.AttributeList; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
41 |
import javax.management.AttributeNotFoundException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
42 |
import javax.management.InstanceAlreadyExistsException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
43 |
import javax.management.InstanceNotFoundException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
44 |
import javax.management.IntrospectionException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
45 |
import javax.management.InvalidAttributeValueException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
46 |
import javax.management.ListenerNotFoundException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
47 |
import javax.management.MBeanException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
48 |
import javax.management.MBeanInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
49 |
import javax.management.MBeanPermission; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
50 |
import javax.management.MBeanRegistrationException; |
2 | 51 |
import javax.management.MBeanServer; |
52 |
import javax.management.MBeanServerDelegate; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
53 |
import javax.management.NotCompliantMBeanException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
54 |
import javax.management.NotificationFilter; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
55 |
import javax.management.NotificationListener; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
56 |
import javax.management.ObjectInstance; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
57 |
import javax.management.ObjectName; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
58 |
import javax.management.OperationsException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
59 |
import javax.management.QueryExp; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
60 |
import javax.management.ReflectionException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
61 |
import javax.management.RuntimeOperationsException; |
2 | 62 |
import javax.management.loading.ClassLoaderRepository; |
63 |
||
64 |
/** |
|
65 |
* This is the base class for MBean manipulation on the agent side. It |
|
66 |
* contains the methods necessary for the creation, registration, and |
|
67 |
* deletion of MBeans as well as the access methods for registered MBeans. |
|
68 |
* This is the core component of the JMX infrastructure. |
|
69 |
* <P> |
|
70 |
* Every MBean which is added to the MBean server becomes manageable: |
|
71 |
* its attributes and operations become remotely accessible through |
|
72 |
* the connectors/adaptors connected to that MBean server. |
|
73 |
* A Java object cannot be registered in the MBean server unless it is a |
|
74 |
* JMX compliant MBean. |
|
75 |
* <P> |
|
76 |
* When an MBean is registered or unregistered in the MBean server an |
|
77 |
* {@link javax.management.MBeanServerNotification MBeanServerNotification} |
|
78 |
* Notification is emitted. To register an object as listener to |
|
79 |
* MBeanServerNotifications you should call the MBean server method |
|
80 |
* {@link #addNotificationListener addNotificationListener} with |
|
81 |
* the <CODE>ObjectName</CODE> of the |
|
82 |
* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}. |
|
83 |
* This <CODE>ObjectName</CODE> is: |
|
84 |
* <BR> |
|
85 |
* <CODE>JMImplementation:type=MBeanServerDelegate</CODE>. |
|
86 |
* |
|
87 |
* @since 1.5 |
|
88 |
*/ |
|
89 |
public final class JmxMBeanServer |
|
90 |
implements SunJmxMBeanServer { |
|
91 |
||
92 |
/** Control the default locking policy of the repository. |
|
93 |
* By default, we will be using a fair locking policy. |
|
94 |
**/ |
|
95 |
public static final boolean DEFAULT_FAIR_LOCK_POLICY = true; |
|
96 |
||
97 |
private final MBeanInstantiator instantiator; |
|
98 |
private final SecureClassLoaderRepository secureClr; |
|
99 |
||
100 |
/** true if interceptors are enabled **/ |
|
101 |
private final boolean interceptorsEnabled; |
|
102 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
103 |
private final MBeanServer outerShell; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
104 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
105 |
private volatile MBeanServer mbsInterceptor = null; |
2 | 106 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
107 |
/** The MBeanServerDelegate object representing the MBean Server */ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
108 |
private final MBeanServerDelegate mBeanServerDelegateObject; |
2 | 109 |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
110 |
private final String mbeanServerName; |
2 | 111 |
|
112 |
/** |
|
113 |
* <b>Package:</b> Creates an MBeanServer with the |
|
114 |
* specified default domain name, outer interface, and delegate. |
|
115 |
* <p>The default domain name is used as the domain part in the ObjectName |
|
116 |
* of MBeans if no domain is specified by the user. |
|
117 |
* <ul><b>Note:</b>Using this constructor directly is strongly |
|
118 |
* discouraged. You should use |
|
119 |
* {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} |
|
120 |
* or |
|
121 |
* {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} |
|
122 |
* instead. |
|
123 |
* <p> |
|
124 |
* By default, {@link MBeanServerInterceptor} are disabled. Use |
|
125 |
* {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them. |
|
126 |
* </ul> |
|
127 |
* @param domain The default domain name used by this MBeanServer. |
|
128 |
* @param outer A pointer to the MBeanServer object that must be |
|
129 |
* passed to the MBeans when invoking their |
|
130 |
* {@link javax.management.MBeanRegistration} interface. |
|
131 |
* @param delegate A pointer to the MBeanServerDelegate associated |
|
132 |
* with the new MBeanServer. The new MBeanServer must register |
|
133 |
* this MBean in its MBean repository. |
|
134 |
* @exception IllegalArgumentException if the instantiator is null. |
|
135 |
*/ |
|
136 |
JmxMBeanServer(String domain, MBeanServer outer, |
|
137 |
MBeanServerDelegate delegate) { |
|
138 |
this(domain,outer,delegate,null,false); |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* <b>Package:</b> Creates an MBeanServer with the |
|
143 |
* specified default domain name, outer interface, and delegate. |
|
144 |
* <p>The default domain name is used as the domain part in the ObjectName |
|
145 |
* of MBeans if no domain is specified by the user. |
|
146 |
* <ul><b>Note:</b>Using this constructor directly is strongly |
|
147 |
* discouraged. You should use |
|
148 |
* {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} |
|
149 |
* or |
|
150 |
* {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} |
|
151 |
* instead. |
|
152 |
* </ul> |
|
153 |
* @param domain The default domain name used by this MBeanServer. |
|
154 |
* @param outer A pointer to the MBeanServer object that must be |
|
155 |
* passed to the MBeans when invoking their |
|
156 |
* {@link javax.management.MBeanRegistration} interface. |
|
157 |
* @param delegate A pointer to the MBeanServerDelegate associated |
|
158 |
* with the new MBeanServer. The new MBeanServer must register |
|
159 |
* this MBean in its MBean repository. |
|
160 |
* @param interceptors If <code>true</code>, |
|
161 |
* {@link MBeanServerInterceptor} will be enabled (default is |
|
162 |
* <code>false</code>) |
|
163 |
* Note: this parameter is not taken into account by this |
|
164 |
* implementation - the default value <code>false</code> is |
|
165 |
* always used. |
|
166 |
* @exception IllegalArgumentException if the instantiator is null. |
|
167 |
*/ |
|
168 |
JmxMBeanServer(String domain, MBeanServer outer, |
|
169 |
MBeanServerDelegate delegate, boolean interceptors) { |
|
170 |
this(domain,outer,delegate,null,false); |
|
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* <b>Package:</b> Creates an MBeanServer. |
|
175 |
* @param domain The default domain name used by this MBeanServer. |
|
176 |
* @param outer A pointer to the MBeanServer object that must be |
|
177 |
* passed to the MBeans when invoking their |
|
178 |
* {@link javax.management.MBeanRegistration} interface. |
|
179 |
* @param delegate A pointer to the MBeanServerDelegate associated |
|
180 |
* with the new MBeanServer. The new MBeanServer must register |
|
181 |
* this MBean in its MBean repository. |
|
182 |
* @param instantiator The MBeanInstantiator that will be used to |
|
183 |
* instantiate MBeans and take care of class loading issues. |
|
184 |
* @param metadata The MetaData object that will be used by the |
|
185 |
* MBean server in order to invoke the MBean interface of |
|
186 |
* the registered MBeans. |
|
187 |
* @param interceptors If <code>true</code>, |
|
188 |
* {@link MBeanServerInterceptor} will be enabled (default is |
|
189 |
* <code>false</code>). |
|
190 |
*/ |
|
191 |
JmxMBeanServer(String domain, MBeanServer outer, |
|
192 |
MBeanServerDelegate delegate, |
|
193 |
MBeanInstantiator instantiator, |
|
194 |
boolean interceptors) { |
|
195 |
this(domain,outer,delegate,instantiator,interceptors,true); |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* <b>Package:</b> Creates an MBeanServer. |
|
200 |
* @param domain The default domain name used by this MBeanServer. |
|
201 |
* @param outer A pointer to the MBeanServer object that must be |
|
202 |
* passed to the MBeans when invoking their |
|
203 |
* {@link javax.management.MBeanRegistration} interface. |
|
204 |
* @param delegate A pointer to the MBeanServerDelegate associated |
|
205 |
* with the new MBeanServer. The new MBeanServer must register |
|
206 |
* this MBean in its MBean repository. |
|
207 |
* @param instantiator The MBeanInstantiator that will be used to |
|
208 |
* instantiate MBeans and take care of class loading issues. |
|
209 |
* @param metadata The MetaData object that will be used by the |
|
210 |
* MBean server in order to invoke the MBean interface of |
|
211 |
* the registered MBeans. |
|
212 |
* @param interceptors If <code>true</code>, |
|
213 |
* {@link MBeanServerInterceptor} will be enabled (default is |
|
214 |
* <code>false</code>). |
|
215 |
* @param fairLock If {@code true}, the MBean repository will use a {@link |
|
216 |
* java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean) |
|
217 |
* fair locking} policy. |
|
218 |
*/ |
|
219 |
JmxMBeanServer(String domain, MBeanServer outer, |
|
220 |
MBeanServerDelegate delegate, |
|
221 |
MBeanInstantiator instantiator, |
|
222 |
boolean interceptors, |
|
223 |
boolean fairLock) { |
|
224 |
||
225 |
if (instantiator == null) { |
|
226 |
final ModifiableClassLoaderRepository |
|
227 |
clr = new ClassLoaderRepositorySupport(); |
|
228 |
instantiator = new MBeanInstantiator(clr); |
|
229 |
} |
|
230 |
this.secureClr = new |
|
231 |
SecureClassLoaderRepository(instantiator.getClassLoaderRepository()); |
|
232 |
if (delegate == null) |
|
233 |
delegate = new MBeanServerDelegateImpl(); |
|
234 |
if (outer == null) |
|
235 |
outer = this; |
|
236 |
||
237 |
this.instantiator = instantiator; |
|
238 |
this.mBeanServerDelegateObject = delegate; |
|
239 |
this.outerShell = outer; |
|
240 |
||
241 |
final Repository repository = new Repository(domain,fairLock); |
|
242 |
this.mbsInterceptor = |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
243 |
new NamespaceDispatchInterceptor(outer, delegate, instantiator, |
2 | 244 |
repository); |
245 |
this.interceptorsEnabled = interceptors; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
246 |
this.mbeanServerName = Util.getMBeanServerSecurityName(delegate); |
2 | 247 |
initialize(); |
248 |
} |
|
249 |
||
250 |
/** |
|
251 |
* Tell whether {@link MBeanServerInterceptor}s are enabled on this |
|
252 |
* object. |
|
253 |
* @return <code>true</code> if {@link MBeanServerInterceptor}s are |
|
254 |
* enabled. |
|
255 |
* @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean) |
|
256 |
**/ |
|
257 |
public boolean interceptorsEnabled() { |
|
258 |
return interceptorsEnabled; |
|
259 |
} |
|
260 |
||
261 |
/** |
|
262 |
* Return the MBeanInstantiator associated to this MBeanServer. |
|
263 |
* @exception UnsupportedOperationException if |
|
264 |
* {@link MBeanServerInterceptor}s |
|
265 |
* are not enabled on this object. |
|
266 |
* @see #interceptorsEnabled |
|
267 |
**/ |
|
268 |
public MBeanInstantiator getMBeanInstantiator() { |
|
269 |
if (interceptorsEnabled) return instantiator; |
|
270 |
else throw new UnsupportedOperationException( |
|
271 |
"MBeanServerInterceptors are disabled."); |
|
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* Instantiates and registers an MBean in the MBean server. |
|
276 |
* The MBean server will use its |
|
277 |
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} |
|
278 |
* to load the class of the MBean. |
|
279 |
* An object name is associated to the MBean. |
|
280 |
* If the object name given is null, the MBean can automatically |
|
281 |
* provide its own name by implementing the |
|
282 |
* {@link javax.management.MBeanRegistration MBeanRegistration} interface. |
|
283 |
* The call returns an <CODE>ObjectInstance</CODE> object representing |
|
284 |
* the newly created MBean. |
|
285 |
* |
|
286 |
* @param className The class name of the MBean to be instantiated. |
|
287 |
* @param name The object name of the MBean. May be null. |
|
288 |
* |
|
289 |
* @return An <CODE>ObjectInstance</CODE>, containing the |
|
290 |
* <CODE>ObjectName</CODE> and the Java class name of the newly |
|
291 |
* instantiated MBean. |
|
292 |
* |
|
293 |
* @exception ReflectionException Wraps an |
|
294 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an |
|
295 |
* <CODE>{@link java.lang.Exception}</CODE> that occurred |
|
296 |
* when trying to invoke the MBean's constructor. |
|
297 |
* @exception InstanceAlreadyExistsException The MBean is already |
|
298 |
* under the control of the MBean server. |
|
299 |
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE> |
|
300 |
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean |
|
301 |
* has thrown an exception. The MBean will not be registered. |
|
302 |
* @exception MBeanException The constructor of the MBean has thrown |
|
303 |
* an exception. |
|
304 |
* @exception NotCompliantMBeanException This class is not a JMX |
|
305 |
* compliant MBean. |
|
306 |
* @exception RuntimeOperationsException Wraps an |
|
307 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: |
|
308 |
* The className passed in parameter is null, the |
|
309 |
* <CODE>ObjectName</CODE> passed in parameter contains a pattern |
|
310 |
* or no <CODE>ObjectName</CODE> is specified for the MBean. |
|
311 |
* |
|
312 |
*/ |
|
313 |
public ObjectInstance createMBean(String className, ObjectName name) |
|
314 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
315 |
MBeanRegistrationException, MBeanException, |
|
316 |
NotCompliantMBeanException { |
|
317 |
||
318 |
return mbsInterceptor.createMBean(className, |
|
319 |
cloneObjectName(name), |
|
320 |
(Object[]) null, |
|
321 |
(String[]) null); |
|
322 |
} |
|
323 |
||
324 |
/** |
|
325 |
* Instantiates and registers an MBean in the MBean server. |
|
326 |
* The class loader to be used is identified by its object name. |
|
327 |
* An object name is associated to the MBean. |
|
328 |
* If the object name of the loader is null, the ClassLoader that |
|
329 |
* loaded the MBean server will be used. |
|
330 |
* If the MBean's object name given is null, the MBean can |
|
331 |
* automatically provide its own name by implementing the |
|
332 |
* {@link javax.management.MBeanRegistration MBeanRegistration} interface. |
|
333 |
* The call returns an <CODE>ObjectInstance</CODE> object representing |
|
334 |
* the newly created MBean. |
|
335 |
* |
|
336 |
* @param className The class name of the MBean to be instantiated. |
|
337 |
* @param name The object name of the MBean. May be null. |
|
338 |
* @param loaderName The object name of the class loader to be used. |
|
339 |
* |
|
340 |
* @return An <CODE>ObjectInstance</CODE>, containing the |
|
341 |
* <CODE>ObjectName</CODE> and the Java class name |
|
342 |
* of the newly instantiated MBean. |
|
343 |
* |
|
344 |
* @exception ReflectionException Wraps an |
|
345 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an |
|
346 |
* <CODE>{@link java.lang.Exception}</CODE> that occurred when trying |
|
347 |
* to invoke the MBean's constructor. |
|
348 |
* @exception InstanceAlreadyExistsException The MBean is already |
|
349 |
* under the control of the MBean server. |
|
350 |
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE> |
|
351 |
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean |
|
352 |
* has thrown an exception. The MBean will not be registered. |
|
353 |
* @exception MBeanException The constructor of the MBean has thrown |
|
354 |
* an exception |
|
355 |
* @exception NotCompliantMBeanException This class is not a JMX |
|
356 |
* compliant MBean. |
|
357 |
* @exception InstanceNotFoundException The specified class loader |
|
358 |
* is not registered in the MBean server. |
|
359 |
* @exception RuntimeOperationsException Wraps an |
|
360 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
361 |
* className passed in parameter is null, the <CODE>ObjectName</CODE> |
|
362 |
* passed in parameter contains a pattern or no |
|
363 |
* <CODE>ObjectName</CODE> is specified for the MBean. |
|
364 |
*/ |
|
365 |
public ObjectInstance createMBean(String className, ObjectName name, |
|
366 |
ObjectName loaderName) |
|
367 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
368 |
MBeanRegistrationException, MBeanException, |
|
369 |
NotCompliantMBeanException, InstanceNotFoundException { |
|
370 |
||
371 |
return mbsInterceptor.createMBean(className, |
|
372 |
cloneObjectName(name), |
|
373 |
loaderName, |
|
374 |
(Object[]) null, |
|
375 |
(String[]) null); |
|
376 |
} |
|
377 |
||
378 |
/** |
|
379 |
* Instantiates and registers an MBean in the MBean server. |
|
380 |
* The MBean server will use its |
|
381 |
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} |
|
382 |
* to load the class of the MBean. |
|
383 |
* An object name is associated to the MBean. |
|
384 |
* If the object name given is null, the MBean can automatically |
|
385 |
* provide its own name by implementing the |
|
386 |
* {@link javax.management.MBeanRegistration MBeanRegistration} interface. |
|
387 |
* The call returns an <CODE>ObjectInstance</CODE> object representing |
|
388 |
* the newly created MBean. |
|
389 |
* |
|
390 |
* @param className The class name of the MBean to be instantiated. |
|
391 |
* @param name The object name of the MBean. May be null. |
|
392 |
* @param params An array containing the parameters of the constructor |
|
393 |
* to be invoked. |
|
394 |
* @param signature An array containing the signature of the |
|
395 |
* constructor to be invoked. |
|
396 |
* |
|
397 |
* @return An <CODE>ObjectInstance</CODE>, containing the |
|
398 |
* <CODE>ObjectName</CODE> and the Java class name |
|
399 |
* of the newly instantiated MBean. |
|
400 |
* |
|
401 |
* @exception ReflectionException Wraps a |
|
402 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an |
|
403 |
* <CODE>{@link java.lang.Exception}</CODE> that occurred |
|
404 |
* when trying to invoke the MBean's constructor. |
|
405 |
* @exception InstanceAlreadyExistsException The MBean is already |
|
406 |
* under the control of the MBean server. |
|
407 |
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE> |
|
408 |
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean |
|
409 |
* has thrown an exception. The MBean will not be registered. |
|
410 |
* @exception MBeanException The constructor of the MBean has |
|
411 |
* thrown an exception. |
|
412 |
* @exception RuntimeOperationsException Wraps an |
|
413 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
414 |
* className passed in parameter is null, the <CODE>ObjectName</CODE> |
|
415 |
* passed in parameter contains a pattern or no |
|
416 |
* <CODE>ObjectName</CODE> is specified for the MBean. |
|
417 |
* |
|
418 |
*/ |
|
419 |
public ObjectInstance createMBean(String className, ObjectName name, |
|
420 |
Object params[], String signature[]) |
|
421 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
422 |
MBeanRegistrationException, MBeanException, |
|
423 |
NotCompliantMBeanException { |
|
424 |
||
425 |
return mbsInterceptor.createMBean(className, cloneObjectName(name), |
|
426 |
params, signature); |
|
427 |
} |
|
428 |
||
429 |
/** |
|
430 |
* Instantiates and registers an MBean in the MBean server. |
|
431 |
* The class loader to be used is identified by its object name. |
|
432 |
* An object name is associated to the MBean. If the object name |
|
433 |
* of the loader is not specified, the ClassLoader that loaded the |
|
434 |
* MBean server will be used. |
|
435 |
* If the MBean object name given is null, the MBean can automatically |
|
436 |
* provide its own name by implementing the |
|
437 |
* {@link javax.management.MBeanRegistration MBeanRegistration} interface. |
|
438 |
* The call returns an <CODE>ObjectInstance</CODE> object representing |
|
439 |
* the newly created MBean. |
|
440 |
* |
|
441 |
* @param className The class name of the MBean to be instantiated. |
|
442 |
* @param name The object name of the MBean. May be null. |
|
443 |
* @param params An array containing the parameters of the constructor |
|
444 |
* to be invoked. |
|
445 |
* @param signature An array containing the signature of the |
|
446 |
* constructor to be invoked. |
|
447 |
* @param loaderName The object name of the class loader to be used. |
|
448 |
* |
|
449 |
* @return An <CODE>ObjectInstance</CODE>, containing the |
|
450 |
* <CODE>ObjectName</CODE> and the Java class name of the newly |
|
451 |
* instantiated MBean. |
|
452 |
* |
|
453 |
* @exception ReflectionException Wraps a |
|
454 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an |
|
455 |
* <CODE>{@link java.lang.Exception}</CODE> |
|
456 |
* that occurred when trying to invoke the MBean's constructor. |
|
457 |
* @exception InstanceAlreadyExistsException The MBean is already |
|
458 |
* under the control of the MBean server. |
|
459 |
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE> |
|
460 |
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean |
|
461 |
* has thrown an exception. The MBean will not be registered. |
|
462 |
* @exception MBeanException The constructor of the MBean has |
|
463 |
* thrown an exception |
|
464 |
* @exception InstanceNotFoundException The specified class loader is |
|
465 |
* not registered in the MBean server. |
|
466 |
* @exception RuntimeOperationsException Wraps an |
|
467 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
468 |
* className passed in parameter is null, the <CODE>ObjectName</CODE> |
|
469 |
* passed in parameter contains a pattern or no |
|
470 |
* <CODE>ObjectName</CODE> is specified for the MBean. |
|
471 |
* |
|
472 |
*/ |
|
473 |
public ObjectInstance createMBean(String className, ObjectName name, |
|
474 |
ObjectName loaderName, Object params[], |
|
475 |
String signature[]) |
|
476 |
throws ReflectionException, InstanceAlreadyExistsException, |
|
477 |
MBeanRegistrationException, MBeanException, |
|
478 |
NotCompliantMBeanException, InstanceNotFoundException { |
|
479 |
||
480 |
return mbsInterceptor.createMBean(className, cloneObjectName(name), |
|
481 |
loaderName, params, signature); |
|
482 |
} |
|
483 |
||
484 |
/** |
|
485 |
* Registers a pre-existing object as an MBean with the MBean server. |
|
486 |
* If the object name given is null, the MBean may automatically |
|
487 |
* provide its own name by implementing the |
|
488 |
* {@link javax.management.MBeanRegistration MBeanRegistration} interface. |
|
489 |
* The call returns an <CODE>ObjectInstance</CODE> object representing |
|
490 |
* the registered MBean. |
|
491 |
* |
|
492 |
* @param object The MBean to be registered as an MBean. |
|
493 |
* @param name The object name of the MBean. May be null. |
|
494 |
* |
|
495 |
* @return The <CODE>ObjectInstance</CODE> for the MBean that has been |
|
496 |
* registered. |
|
497 |
* |
|
498 |
* @exception InstanceAlreadyExistsException The MBean is already |
|
499 |
* under the control of the MBean server. |
|
500 |
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE> |
|
501 |
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean |
|
502 |
* has thrown an exception. The MBean will not be registered. |
|
503 |
* @exception NotCompliantMBeanException This object is not a JMX |
|
504 |
* compliant MBean |
|
505 |
* @exception RuntimeOperationsException Wraps an |
|
506 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
507 |
* object passed in parameter is null or no object name is specified. |
|
508 |
* |
|
509 |
*/ |
|
510 |
public ObjectInstance registerMBean(Object object, ObjectName name) |
|
511 |
throws InstanceAlreadyExistsException, MBeanRegistrationException, |
|
512 |
NotCompliantMBeanException { |
|
513 |
||
514 |
return mbsInterceptor.registerMBean(object, cloneObjectName(name)); |
|
515 |
} |
|
516 |
||
517 |
/** |
|
518 |
* De-registers an MBean from the MBean server. The MBean is identified by |
|
519 |
* its object name. Once the method has been invoked, the MBean may |
|
520 |
* no longer be accessed by its object name. |
|
521 |
* |
|
522 |
* @param name The object name of the MBean to be de-registered. |
|
523 |
* |
|
524 |
* @exception InstanceNotFoundException The MBean specified is not |
|
525 |
* registered in the MBean server. |
|
526 |
* @exception MBeanRegistrationException The <code>preDeregister()</code> |
|
527 |
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean |
|
528 |
* has thrown an exception. |
|
529 |
* @exception RuntimeOperationsException Wraps an |
|
530 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
531 |
* object name in parameter is null or the MBean you are when |
|
532 |
* trying to de-register is the |
|
533 |
* {@link javax.management.MBeanServerDelegate MBeanServerDelegate} |
|
534 |
* MBean. |
|
535 |
**/ |
|
536 |
public void unregisterMBean(ObjectName name) |
|
537 |
throws InstanceNotFoundException, MBeanRegistrationException { |
|
538 |
mbsInterceptor.unregisterMBean(cloneObjectName(name)); |
|
539 |
} |
|
540 |
||
541 |
/** |
|
542 |
* Gets the <CODE>ObjectInstance</CODE> for a given MBean registered |
|
543 |
* with the MBean server. |
|
544 |
* |
|
545 |
* @param name The object name of the MBean. |
|
546 |
* |
|
547 |
* @return The <CODE>ObjectInstance</CODE> associated to the MBean |
|
548 |
* specified by <VAR>name</VAR>. |
|
549 |
* |
|
550 |
* @exception InstanceNotFoundException The MBean specified is not |
|
551 |
* registered in the MBean server. |
|
552 |
*/ |
|
553 |
public ObjectInstance getObjectInstance(ObjectName name) |
|
554 |
throws InstanceNotFoundException { |
|
555 |
||
556 |
return mbsInterceptor.getObjectInstance(cloneObjectName(name)); |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Gets MBeans controlled by the MBean server. This method allows any |
|
561 |
* of the following to be obtained: All MBeans, a set of MBeans specified |
|
562 |
* by pattern matching on the <CODE>ObjectName</CODE> and/or a Query |
|
563 |
* expression, a specific MBean. When the object name is null or no |
|
564 |
* domain and key properties are specified, all objects are to be |
|
565 |
* selected (and filtered if a query is specified). It returns the |
|
566 |
* set of <CODE>ObjectInstance</CODE> objects (containing the |
|
567 |
* <CODE>ObjectName</CODE> and the Java Class name) for |
|
568 |
* the selected MBeans. |
|
569 |
* |
|
570 |
* @param name The object name pattern identifying the MBeans to |
|
571 |
* be retrieved. If null or or no domain and key properties |
|
572 |
* are specified, all the MBeans registered will be retrieved. |
|
573 |
* @param query The query expression to be applied for selecting |
|
574 |
* MBeans. If null no query expression will be applied for |
|
575 |
* selecting MBeans. |
|
576 |
* |
|
577 |
* @return A set containing the <CODE>ObjectInstance</CODE> objects |
|
578 |
* for the selected MBeans. |
|
579 |
* If no MBean satisfies the query an empty list is returned. |
|
580 |
* |
|
581 |
*/ |
|
582 |
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) { |
|
583 |
||
584 |
return mbsInterceptor.queryMBeans(cloneObjectName(name), query); |
|
585 |
} |
|
586 |
||
587 |
/** |
|
588 |
* Gets the names of MBeans controlled by the MBean server. This method |
|
589 |
* enables any of the following to be obtained: The names of all MBeans, |
|
590 |
* the names of a set of MBeans specified by pattern matching on the |
|
591 |
* <CODE>ObjectName</CODE> and/or a Query expression, a specific |
|
592 |
* MBean name (equivalent to testing whether an MBean is registered). |
|
593 |
* When the object name is null or or no domain and key properties are |
|
594 |
* specified, all objects are selected (and filtered if a query is |
|
595 |
* specified). It returns the set of ObjectNames for the MBeans |
|
596 |
* selected. |
|
597 |
* |
|
598 |
* @param name The object name pattern identifying the MBeans to be |
|
599 |
* retrieved. If null or no domain and key properties are |
|
600 |
* specified, all the MBeans registered will be retrieved. |
|
601 |
* @param query The query expression to be applied for selecting |
|
602 |
* MBeans. If null no query expression will be applied for |
|
603 |
* selecting MBeans. |
|
604 |
* |
|
605 |
* @return A set containing the ObjectNames for the MBeans selected. |
|
606 |
* If no MBean satisfies the query, an empty list is returned. |
|
607 |
* |
|
608 |
*/ |
|
609 |
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) { |
|
610 |
||
611 |
return mbsInterceptor.queryNames(cloneObjectName(name), query); |
|
612 |
} |
|
613 |
||
614 |
/** |
|
615 |
* Checks whether an MBean, identified by its object name, is already |
|
616 |
* registered with the MBean server. |
|
617 |
* |
|
618 |
* @param name The object name of the MBean to be checked. |
|
619 |
* |
|
620 |
* @return True if the MBean is already registered in the MBean server, |
|
621 |
* false otherwise. |
|
622 |
* |
|
623 |
* @exception RuntimeOperationsException Wraps an |
|
624 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The object |
|
625 |
* name in parameter is null. |
|
626 |
* |
|
627 |
*/ |
|
628 |
public boolean isRegistered(ObjectName name) { |
|
629 |
||
630 |
return mbsInterceptor.isRegistered(name); |
|
631 |
} |
|
632 |
||
633 |
/** |
|
634 |
* Returns the number of MBeans registered in the MBean server. |
|
635 |
*/ |
|
636 |
public Integer getMBeanCount() { |
|
637 |
||
638 |
return mbsInterceptor.getMBeanCount(); |
|
639 |
} |
|
640 |
||
641 |
/** |
|
642 |
* Gets the value of a specific attribute of a named MBean. The MBean |
|
643 |
* is identified by its object name. |
|
644 |
* |
|
645 |
* @param name The object name of the MBean from which the attribute |
|
646 |
* is to be retrieved. |
|
647 |
* @param attribute A String specifying the name of the attribute to be |
|
648 |
* retrieved. |
|
649 |
* |
|
650 |
* @return The value of the retrieved attribute. |
|
651 |
* |
|
652 |
* @exception AttributeNotFoundException The attribute specified |
|
653 |
* is not accessible in the MBean. |
|
654 |
* @exception MBeanException Wraps an exception thrown by the |
|
655 |
* MBean's getter. |
|
656 |
* @exception InstanceNotFoundException The MBean specified is not |
|
657 |
* registered in the MBean server. |
|
658 |
* @exception ReflectionException Wraps an |
|
659 |
* <CODE>{@link java.lang.Exception}</CODE> thrown when trying to |
|
660 |
* invoke the setter. |
|
661 |
* @exception RuntimeOperationsException Wraps an |
|
662 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: |
|
663 |
* The object name in parameter is null or the attribute in |
|
664 |
* parameter is null. |
|
665 |
*/ |
|
666 |
public Object getAttribute(ObjectName name, String attribute) |
|
667 |
throws MBeanException, AttributeNotFoundException, |
|
668 |
InstanceNotFoundException, ReflectionException { |
|
669 |
||
670 |
return mbsInterceptor.getAttribute(cloneObjectName(name), attribute); |
|
671 |
} |
|
672 |
||
673 |
||
674 |
/** |
|
675 |
* Enables the values of several attributes of a named MBean. The MBean |
|
676 |
* is identified by its object name. |
|
677 |
* |
|
678 |
* @param name The object name of the MBean from which the attributes are |
|
679 |
* retrieved. |
|
680 |
* @param attributes A list of the attributes to be retrieved. |
|
681 |
* |
|
682 |
* @return The list of the retrieved attributes. |
|
683 |
* |
|
684 |
* @exception InstanceNotFoundException The MBean specified is not |
|
685 |
* registered in the MBean server. |
|
686 |
* @exception ReflectionException An exception occurred when trying |
|
687 |
* to invoke the getAttributes method of a Dynamic MBean. |
|
688 |
* @exception RuntimeOperationsException Wrap an |
|
689 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
690 |
* object name in parameter is null or attributes in parameter |
|
691 |
* is null. |
|
692 |
* |
|
693 |
*/ |
|
694 |
public AttributeList getAttributes(ObjectName name, String[] attributes) |
|
695 |
throws InstanceNotFoundException, ReflectionException { |
|
696 |
||
697 |
return mbsInterceptor.getAttributes(cloneObjectName(name), attributes); |
|
698 |
||
699 |
} |
|
700 |
||
701 |
/** |
|
702 |
* Sets the value of a specific attribute of a named MBean. The MBean |
|
703 |
* is identified by its object name. |
|
704 |
* |
|
705 |
* @param name The name of the MBean within which the attribute is |
|
706 |
* to be set. |
|
707 |
* @param attribute The identification of the attribute to be set |
|
708 |
* and the value it is to be set to. |
|
709 |
* |
|
710 |
* @exception InstanceNotFoundException The MBean specified is |
|
711 |
* not registered in the MBean server. |
|
712 |
* @exception AttributeNotFoundException The attribute specified is |
|
713 |
* not accessible in the MBean. |
|
714 |
* @exception InvalidAttributeValueException The value specified for |
|
715 |
* the attribute is not valid. |
|
716 |
* @exception MBeanException Wraps an exception thrown by the |
|
717 |
* MBean's setter. |
|
718 |
* @exception ReflectionException Wraps an |
|
719 |
* <CODE>{@link java.lang.Exception}</CODE> thrown when trying |
|
720 |
* to invoke the setter. |
|
721 |
* @exception RuntimeOperationsException Wraps an |
|
722 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
723 |
* object name in parameter is null or the attribute in parameter |
|
724 |
* is null. |
|
725 |
*/ |
|
726 |
public void setAttribute(ObjectName name, Attribute attribute) |
|
727 |
throws InstanceNotFoundException, AttributeNotFoundException, |
|
728 |
InvalidAttributeValueException, MBeanException, |
|
729 |
ReflectionException { |
|
730 |
||
731 |
mbsInterceptor.setAttribute(cloneObjectName(name), |
|
732 |
cloneAttribute(attribute)); |
|
733 |
} |
|
734 |
||
735 |
/** |
|
736 |
* Sets the values of several attributes of a named MBean. The MBean is |
|
737 |
* identified by its object name. |
|
738 |
* |
|
739 |
* @param name The object name of the MBean within which the |
|
740 |
* attributes are to be set. |
|
741 |
* @param attributes A list of attributes: The identification of the |
|
742 |
* attributes to be set and the values they are to be set to. |
|
743 |
* |
|
744 |
* @return The list of attributes that were set, with their new values. |
|
745 |
* |
|
746 |
* @exception InstanceNotFoundException The MBean specified is not |
|
747 |
* registered in the MBean server. |
|
748 |
* @exception ReflectionException An exception occurred when trying |
|
749 |
* to invoke the getAttributes method of a Dynamic MBean. |
|
750 |
* @exception RuntimeOperationsException Wraps an |
|
751 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: |
|
752 |
* The object name in parameter is null or attributes in |
|
753 |
* parameter is null. |
|
754 |
* |
|
755 |
*/ |
|
756 |
public AttributeList setAttributes(ObjectName name, |
|
757 |
AttributeList attributes) |
|
758 |
throws InstanceNotFoundException, ReflectionException { |
|
759 |
||
760 |
return mbsInterceptor.setAttributes(cloneObjectName(name), |
|
761 |
cloneAttributeList(attributes)); |
|
762 |
} |
|
763 |
||
764 |
/** |
|
765 |
* Invokes an operation on an MBean. |
|
766 |
* |
|
767 |
* @param name The object name of the MBean on which the method is to be |
|
768 |
* invoked. |
|
769 |
* @param operationName The name of the operation to be invoked. |
|
770 |
* @param params An array containing the parameters to be set when |
|
771 |
* the operation is invoked |
|
772 |
* @param signature An array containing the signature of the operation. |
|
773 |
* The class objects will be loaded using the same class loader as |
|
774 |
* the one used for loading the MBean on which the operation was |
|
775 |
* invoked. |
|
776 |
* |
|
777 |
* @return The object returned by the operation, which represents the |
|
778 |
* result ofinvoking the operation on the MBean specified. |
|
779 |
* |
|
780 |
* @exception InstanceNotFoundException The MBean specified is not |
|
781 |
* registered in the MBean server. |
|
782 |
* @exception MBeanException Wraps an exception thrown by the MBean's |
|
783 |
* invoked method. |
|
784 |
* @exception ReflectionException Wraps an |
|
785 |
* <CODE>{@link java.lang.Exception}</CODE> thrown while trying |
|
786 |
* to invoke the method. |
|
787 |
* |
|
788 |
*/ |
|
789 |
public Object invoke(ObjectName name, String operationName, |
|
790 |
Object params[], String signature[]) |
|
791 |
throws InstanceNotFoundException, MBeanException, |
|
792 |
ReflectionException { |
|
793 |
return mbsInterceptor.invoke(cloneObjectName(name), operationName, |
|
794 |
params, signature); |
|
795 |
} |
|
796 |
||
797 |
/** |
|
798 |
* Returns the default domain used for naming the MBean. |
|
799 |
* The default domain name is used as the domain part in the ObjectName |
|
800 |
* of MBeans if no domain is specified by the user. |
|
801 |
*/ |
|
802 |
public String getDefaultDomain() { |
|
803 |
return mbsInterceptor.getDefaultDomain(); |
|
804 |
} |
|
805 |
||
806 |
// From MBeanServer |
|
807 |
public String[] getDomains() { |
|
808 |
return mbsInterceptor.getDomains(); |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Adds a listener to a registered MBean. |
|
813 |
* |
|
814 |
* @param name The name of the MBean on which the listener should be added. |
|
815 |
* @param listener The listener object which will handle the |
|
816 |
* notifications emitted by the registered MBean. |
|
817 |
* @param filter The filter object. If filter is null, no filtering |
|
818 |
* will be performed before handling notifications. |
|
819 |
* @param handback The context to be sent to the listener when a |
|
820 |
* notification is emitted. |
|
821 |
* |
|
822 |
* @exception InstanceNotFoundException The MBean name provided does |
|
823 |
* not match any of the registered MBeans. |
|
824 |
*/ |
|
825 |
public void addNotificationListener(ObjectName name, |
|
826 |
NotificationListener listener, |
|
827 |
NotificationFilter filter, |
|
828 |
Object handback) |
|
829 |
throws InstanceNotFoundException { |
|
830 |
||
831 |
mbsInterceptor.addNotificationListener(cloneObjectName(name), listener, |
|
832 |
filter, handback); |
|
833 |
} |
|
834 |
||
835 |
/** |
|
836 |
* Adds a listener to a registered MBean. |
|
837 |
* |
|
838 |
* @param name The name of the MBean on which the listener should be added. |
|
839 |
* @param listener The object name of the listener which will handle the |
|
840 |
* notifications emitted by the registered MBean. |
|
841 |
* @param filter The filter object. If filter is null, no filtering will |
|
842 |
* be performed before handling notifications. |
|
843 |
* @param handback The context to be sent to the listener when a |
|
844 |
* notification is emitted. |
|
845 |
* |
|
846 |
* @exception InstanceNotFoundException The MBean name of the |
|
847 |
* notification listener or of the notification broadcaster |
|
848 |
* does not match any of the registered MBeans. |
|
849 |
*/ |
|
850 |
public void addNotificationListener(ObjectName name, ObjectName listener, |
|
851 |
NotificationFilter filter, Object handback) |
|
852 |
throws InstanceNotFoundException { |
|
853 |
||
854 |
mbsInterceptor.addNotificationListener(cloneObjectName(name), listener, |
|
855 |
filter, handback); |
|
856 |
} |
|
857 |
||
858 |
public void removeNotificationListener(ObjectName name, |
|
859 |
NotificationListener listener) |
|
860 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
861 |
||
862 |
mbsInterceptor.removeNotificationListener(cloneObjectName(name), |
|
863 |
listener); |
|
864 |
} |
|
865 |
||
866 |
public void removeNotificationListener(ObjectName name, |
|
867 |
NotificationListener listener, |
|
868 |
NotificationFilter filter, |
|
869 |
Object handback) |
|
870 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
871 |
||
872 |
mbsInterceptor.removeNotificationListener(cloneObjectName(name), |
|
873 |
listener, filter, handback); |
|
874 |
} |
|
875 |
||
876 |
public void removeNotificationListener(ObjectName name, |
|
877 |
ObjectName listener) |
|
878 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
879 |
||
880 |
mbsInterceptor.removeNotificationListener(cloneObjectName(name), |
|
881 |
listener); |
|
882 |
} |
|
883 |
||
884 |
public void removeNotificationListener(ObjectName name, |
|
885 |
ObjectName listener, |
|
886 |
NotificationFilter filter, |
|
887 |
Object handback) |
|
888 |
throws InstanceNotFoundException, ListenerNotFoundException { |
|
889 |
||
890 |
mbsInterceptor.removeNotificationListener(cloneObjectName(name), |
|
891 |
listener, filter, handback); |
|
892 |
} |
|
893 |
||
894 |
/** |
|
895 |
* This method discovers the attributes and operations that an MBean exposes |
|
896 |
* for management. |
|
897 |
* |
|
898 |
* @param name The name of the MBean to analyze |
|
899 |
* |
|
900 |
* @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of |
|
901 |
* all attributes and operations of this MBean. |
|
902 |
* |
|
903 |
* @exception IntrospectionException An exception occurs during |
|
904 |
* introspection. |
|
905 |
* @exception InstanceNotFoundException The MBean specified is not found. |
|
906 |
* @exception ReflectionException An exception occurred when trying to |
|
907 |
* invoke the getMBeanInfo of a Dynamic MBean. |
|
908 |
*/ |
|
909 |
public MBeanInfo getMBeanInfo(ObjectName name) throws |
|
910 |
InstanceNotFoundException, IntrospectionException, ReflectionException { |
|
911 |
||
912 |
return mbsInterceptor.getMBeanInfo(cloneObjectName(name)); |
|
913 |
} |
|
914 |
||
915 |
/** |
|
916 |
* Instantiates an object using the list of all class loaders registered |
|
917 |
* in the MBean server (using its |
|
918 |
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}). |
|
919 |
* The object's class should have a public constructor. |
|
920 |
* It returns a reference to the newly created object. |
|
921 |
* The newly created object is not registered in the MBean server. |
|
922 |
* |
|
923 |
* @param className The class name of the object to be instantiated. |
|
924 |
* |
|
925 |
* @return The newly instantiated object. |
|
926 |
* |
|
927 |
* @exception ReflectionException Wraps the |
|
928 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the |
|
929 |
* <CODE>{@link java.lang.Exception}</CODE> that |
|
930 |
* occurred when trying to invoke the object's constructor. |
|
931 |
* @exception MBeanException The constructor of the object has thrown |
|
932 |
* an exception. |
|
933 |
* @exception RuntimeOperationsException Wraps an |
|
934 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: |
|
935 |
* The className passed in parameter is null. |
|
936 |
* |
|
937 |
*/ |
|
938 |
public Object instantiate(String className) |
|
939 |
throws ReflectionException, MBeanException { |
|
940 |
||
941 |
/* Permission check */ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
942 |
checkMBeanPermission(mbeanServerName, className, null, null, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
943 |
"instantiate"); |
2 | 944 |
|
945 |
return instantiator.instantiate(className); |
|
946 |
} |
|
947 |
||
948 |
/** |
|
949 |
* Instantiates an object using the class Loader specified by its |
|
950 |
* <CODE>ObjectName</CODE>. |
|
951 |
* If the loader name is null, the ClassLoader that loaded the |
|
952 |
* MBean Server will be used. |
|
953 |
* The object's class should have a public constructor. |
|
954 |
* It returns a reference to the newly created object. |
|
955 |
* The newly created object is not registered in the MBean server. |
|
956 |
* |
|
957 |
* @param className The class name of the MBean to be instantiated. |
|
958 |
* @param loaderName The object name of the class loader to be used. |
|
959 |
* |
|
960 |
* @return The newly instantiated object. |
|
961 |
* |
|
962 |
* @exception ReflectionException Wraps the |
|
963 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the |
|
964 |
* <CODE>{@link java.lang.Exception}</CODE> that |
|
965 |
* occurred when trying to invoke the object's constructor. |
|
966 |
* @exception MBeanException The constructor of the object has thrown |
|
967 |
* an exception. |
|
968 |
* @exception InstanceNotFoundException The specified class loader |
|
969 |
* is not registered in the MBaenServer. |
|
970 |
* @exception RuntimeOperationsException Wraps an |
|
971 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The |
|
972 |
* className passed in parameter is null. |
|
973 |
* |
|
974 |
*/ |
|
975 |
public Object instantiate(String className, ObjectName loaderName) |
|
976 |
throws ReflectionException, MBeanException, |
|
977 |
InstanceNotFoundException { |
|
978 |
||
979 |
/* Permission check */ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
980 |
checkMBeanPermission(mbeanServerName, className, null, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
981 |
null, "instantiate"); |
2 | 982 |
|
983 |
ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
|
984 |
return instantiator.instantiate(className, loaderName, myLoader); |
|
985 |
} |
|
986 |
||
987 |
/** |
|
988 |
* Instantiates an object using the list of all class loaders registered |
|
989 |
* in the MBean server (using its |
|
990 |
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}). |
|
991 |
* The object's class should have a public constructor. |
|
992 |
* The call returns a reference to the newly created object. |
|
993 |
* The newly created object is not registered in the MBean server. |
|
994 |
* |
|
995 |
* @param className The class name of the object to be instantiated. |
|
996 |
* @param params An array containing the parameters of the constructor |
|
997 |
* to be invoked. |
|
998 |
* @param signature An array containing the signature of the |
|
999 |
* constructor to be invoked. |
|
1000 |
* |
|
1001 |
* @return The newly instantiated object. |
|
1002 |
* |
|
1003 |
* @exception ReflectionException Wraps the |
|
1004 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the |
|
1005 |
* <CODE>{@link java.lang.Exception}</CODE> that |
|
1006 |
* occurred when trying to invoke the object's constructor. |
|
1007 |
* @exception MBeanException The constructor of the object has thrown |
|
1008 |
* an exception. |
|
1009 |
* @exception RuntimeOperationsException Wraps an |
|
1010 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: |
|
1011 |
* The className passed in parameter is null. |
|
1012 |
* |
|
1013 |
*/ |
|
1014 |
public Object instantiate(String className, Object params[], |
|
1015 |
String signature[]) |
|
1016 |
throws ReflectionException, MBeanException { |
|
1017 |
||
1018 |
/* Permission check */ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1019 |
checkMBeanPermission(mbeanServerName, className, null, null, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1020 |
"instantiate"); |
2 | 1021 |
|
1022 |
ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
|
1023 |
return instantiator.instantiate(className, params, signature, |
|
1024 |
myLoader); |
|
1025 |
} |
|
1026 |
||
1027 |
/** |
|
1028 |
* Instantiates an object. The class loader to be used is identified |
|
1029 |
* by its object name. If the object name of the loader is null, |
|
1030 |
* the ClassLoader that loaded the MBean server will be used. |
|
1031 |
* The object's class should have a public constructor. |
|
1032 |
* The call returns a reference to the newly created object. |
|
1033 |
* The newly created object is not registered in the MBean server. |
|
1034 |
* |
|
1035 |
* @param className The class name of the object to be instantiated. |
|
1036 |
* @param params An array containing the parameters of the constructor |
|
1037 |
* to be invoked. |
|
1038 |
* @param signature An array containing the signature of the constructor |
|
1039 |
* to be invoked. |
|
1040 |
* @param loaderName The object name of the class loader to be used. |
|
1041 |
* |
|
1042 |
* @return The newly instantiated object. |
|
1043 |
* |
|
1044 |
* @exception ReflectionException Wraps the |
|
1045 |
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the |
|
1046 |
* <CODE>{@link java.lang.Exception}</CODE> that |
|
1047 |
* occurred when trying to invoke the object's constructor. |
|
1048 |
* @exception MBeanException The constructor of the object has thrown |
|
1049 |
* an exception. |
|
1050 |
* @exception InstanceNotFoundException The specified class loader |
|
1051 |
* is not registered in the MBean server. |
|
1052 |
* @exception RuntimeOperationsException Wraps an |
|
1053 |
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: |
|
1054 |
* The className passed in parameter is null. |
|
1055 |
* |
|
1056 |
*/ |
|
1057 |
public Object instantiate(String className, ObjectName loaderName, |
|
1058 |
Object params[], String signature[]) |
|
1059 |
throws ReflectionException, MBeanException, |
|
1060 |
InstanceNotFoundException { |
|
1061 |
||
1062 |
/* Permission check */ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1063 |
checkMBeanPermission(mbeanServerName, className, null, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1064 |
null, "instantiate"); |
2 | 1065 |
|
1066 |
ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
|
1067 |
return instantiator.instantiate(className,loaderName,params,signature, |
|
1068 |
myLoader); |
|
1069 |
} |
|
1070 |
||
1071 |
/** |
|
1072 |
* Returns true if the MBean specified is an instance of the specified |
|
1073 |
* class, false otherwise. |
|
1074 |
* |
|
1075 |
* @param name The <CODE>ObjectName</CODE> of the MBean. |
|
1076 |
* @param className The name of the class. |
|
1077 |
* |
|
1078 |
* @return true if the MBean specified is an instance of the specified |
|
1079 |
* class, false otherwise. |
|
1080 |
* |
|
1081 |
* @exception InstanceNotFoundException The MBean specified is not |
|
1082 |
* registered in the MBean server. |
|
1083 |
*/ |
|
1084 |
public boolean isInstanceOf(ObjectName name, String className) |
|
1085 |
throws InstanceNotFoundException { |
|
1086 |
||
1087 |
return mbsInterceptor.isInstanceOf(cloneObjectName(name), className); |
|
1088 |
} |
|
1089 |
||
1090 |
/** |
|
1091 |
* De-serializes a byte array in the context of the class loader |
|
1092 |
* of an MBean. |
|
1093 |
* |
|
1094 |
* @param name The name of the MBean whose class loader should |
|
1095 |
* be used for the de-serialization. |
|
1096 |
* @param data The byte array to be de-sererialized. |
|
1097 |
* |
|
1098 |
* @return The de-serialized object stream. |
|
1099 |
* |
|
1100 |
* @exception InstanceNotFoundException The MBean specified is not |
|
1101 |
* found. |
|
1102 |
* @exception OperationsException Any of the usual Input/Output |
|
1103 |
* related exceptions. |
|
1104 |
* |
|
1105 |
*/ |
|
1106 |
@Deprecated |
|
1107 |
public ObjectInputStream deserialize(ObjectName name, byte[] data) |
|
1108 |
throws InstanceNotFoundException, OperationsException { |
|
1109 |
||
1110 |
/* Permission check */ |
|
1111 |
// This call requires MBeanPermission 'getClassLoaderFor' |
|
1112 |
final ClassLoader loader = getClassLoaderFor(name); |
|
1113 |
||
1114 |
return instantiator.deserialize(loader, data); |
|
1115 |
} |
|
1116 |
||
1117 |
/** |
|
1118 |
* De-serializes a byte array in the context of a given MBean class loader. |
|
1119 |
* The class loader is the one that loaded the class with name "className". |
|
1120 |
* |
|
1121 |
* @param className The name of the class whose class loader should be |
|
1122 |
* used for the de-serialization. |
|
1123 |
* @param data The byte array to be de-sererialized. |
|
1124 |
* |
|
1125 |
* @return The de-serialized object stream. |
|
1126 |
* |
|
1127 |
* @exception OperationsException Any of the usual Input/Output |
|
1128 |
* related exceptions. |
|
1129 |
* @exception ReflectionException The specified class could not be |
|
1130 |
* loaded by the default loader repository |
|
1131 |
* |
|
1132 |
*/ |
|
1133 |
@Deprecated |
|
1134 |
public ObjectInputStream deserialize(String className, byte[] data) |
|
1135 |
throws OperationsException, ReflectionException { |
|
1136 |
||
1137 |
if (className == null) { |
|
1138 |
throw new RuntimeOperationsException( |
|
1139 |
new IllegalArgumentException(), |
|
1140 |
"Null className passed in parameter"); |
|
1141 |
} |
|
1142 |
||
1143 |
/* Permission check */ |
|
1144 |
// This call requires MBeanPermission 'getClassLoaderRepository' |
|
1145 |
final ClassLoaderRepository clr = getClassLoaderRepository(); |
|
1146 |
||
1147 |
Class theClass; |
|
1148 |
try { |
|
1149 |
if (clr == null) throw new ClassNotFoundException(className); |
|
1150 |
theClass = clr.loadClass(className); |
|
1151 |
} catch (ClassNotFoundException e) { |
|
1152 |
throw new ReflectionException(e, |
|
1153 |
"The given class could not be " + |
|
1154 |
"loaded by the default loader " + |
|
1155 |
"repository"); |
|
1156 |
} |
|
1157 |
||
1158 |
return instantiator.deserialize(theClass.getClassLoader(), data); |
|
1159 |
} |
|
1160 |
||
1161 |
/** |
|
1162 |
* De-serializes a byte array in the context of a given MBean class loader. |
|
1163 |
* The class loader is the one that loaded the class with name "className". |
|
1164 |
* The name of the class loader to be used for loading the specified |
|
1165 |
* class is specified. |
|
1166 |
* If null, the MBean Server's class loader will be used. |
|
1167 |
* |
|
1168 |
* @param className The name of the class whose class loader should be |
|
1169 |
* used for the de-serialization. |
|
1170 |
* @param data The byte array to be de-sererialized. |
|
1171 |
* @param loaderName The name of the class loader to be used for |
|
1172 |
* loading the specified class. |
|
1173 |
* If null, the MBean Server's class loader will be used. |
|
1174 |
* |
|
1175 |
* @return The de-serialized object stream. |
|
1176 |
* |
|
1177 |
* @exception InstanceNotFoundException The specified class loader |
|
1178 |
* MBean is not found. |
|
1179 |
* @exception OperationsException Any of the usual Input/Output |
|
1180 |
* related exceptions. |
|
1181 |
* @exception ReflectionException The specified class could not |
|
1182 |
* be loaded by the specified class loader. |
|
1183 |
* |
|
1184 |
*/ |
|
1185 |
@Deprecated |
|
1186 |
public ObjectInputStream deserialize(String className, |
|
1187 |
ObjectName loaderName, |
|
1188 |
byte[] data) throws |
|
1189 |
InstanceNotFoundException, OperationsException, ReflectionException { |
|
1190 |
||
1191 |
// Clone ObjectName |
|
1192 |
// |
|
1193 |
loaderName = cloneObjectName(loaderName); |
|
1194 |
||
1195 |
/* Permission check */ |
|
1196 |
// Make this call just to force the 'getClassLoader' |
|
1197 |
// permission check |
|
1198 |
try { |
|
1199 |
getClassLoader(loaderName); |
|
1200 |
} catch (SecurityException e) { |
|
1201 |
throw e; |
|
1202 |
} catch (Exception e) { |
|
1203 |
} |
|
1204 |
||
1205 |
ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
|
1206 |
return instantiator.deserialize(className, loaderName, data, myLoader); |
|
1207 |
} |
|
1208 |
||
1209 |
/** |
|
1210 |
* Initializes this MBeanServer, registering the MBeanServerDelegate. |
|
1211 |
* <p>This method must be called once, before using the MBeanServer. |
|
1212 |
**/ |
|
1213 |
private void initialize() { |
|
1214 |
if (instantiator == null) throw new |
|
1215 |
IllegalStateException("instantiator must not be null."); |
|
1216 |
||
1217 |
// Registers the MBeanServer identification MBean |
|
1218 |
try { |
|
1219 |
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { |
|
1220 |
public Object run() throws Exception { |
|
1221 |
mbsInterceptor.registerMBean( |
|
1222 |
mBeanServerDelegateObject, |
|
1223 |
MBeanServerDelegate.DELEGATE_NAME); |
|
1224 |
return null; |
|
1225 |
} |
|
1226 |
}); |
|
1227 |
} catch (SecurityException e) { |
|
1228 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) { |
|
1229 |
MBEANSERVER_LOGGER.logp(Level.FINEST, |
|
1230 |
JmxMBeanServer.class.getName(), "initialize", |
|
1231 |
"Unexpected security exception occurred", e); |
|
1232 |
} |
|
1233 |
throw e; |
|
1234 |
} catch (Exception e) { |
|
1235 |
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) { |
|
1236 |
MBEANSERVER_LOGGER.logp(Level.FINEST, |
|
1237 |
JmxMBeanServer.class.getName(), "initialize", |
|
1238 |
"Unexpected exception occurred", e); |
|
1239 |
} |
|
1240 |
throw new |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1241 |
IllegalStateException("Can't register delegate.",e); |
2 | 1242 |
} |
1243 |
||
1244 |
||
1245 |
/* Add my class loader to the repository |
|
1246 |
This can be null if my class loader is the bootstrap |
|
1247 |
class loader. The ClassLoaderRepository knows how |
|
1248 |
to handle that case. */ |
|
1249 |
ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
|
1250 |
final ModifiableClassLoaderRepository loaders = |
|
1251 |
instantiator.getClassLoaderRepository(); |
|
1252 |
if (loaders != null) { |
|
1253 |
loaders.addClassLoader(myLoader); |
|
1254 |
||
1255 |
/* Add the system class loader, so that if the MBean server is |
|
1256 |
loaded by the bootstrap class loader we can still load |
|
1257 |
MBeans from the classpath using |
|
1258 |
createMBean(className, objectName). |
|
1259 |
||
1260 |
If this class (JmxMBeanServer) was not loaded by the |
|
1261 |
system class loader or a parent of it, then the caller |
|
1262 |
must have RuntimePermission("getClassLoader") for the |
|
1263 |
getSystemClassLoader() call to succeed. If the caller |
|
1264 |
does not have that permission, any call to |
|
1265 |
Class.getClassLoader() will fail. Since there are lots |
|
1266 |
of those in JMX, we better throw the exception now. |
|
1267 |
||
1268 |
This permission question is irrelevant when JMX is part |
|
1269 |
of J2SE (as of 1.5). */ |
|
1270 |
ClassLoader systemLoader = ClassLoader.getSystemClassLoader(); |
|
1271 |
if (systemLoader != myLoader) |
|
1272 |
loaders.addClassLoader(systemLoader); |
|
1273 |
} |
|
1274 |
} |
|
1275 |
||
1276 |
/** |
|
1277 |
* Return the MBeanServerInterceptor. |
|
1278 |
* @exception UnsupportedOperationException if |
|
1279 |
* {@link MBeanServerInterceptor}s |
|
1280 |
* are not enabled on this object. |
|
1281 |
* @see #interceptorsEnabled |
|
1282 |
**/ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1283 |
public synchronized MBeanServer getMBeanServerInterceptor() { |
2 | 1284 |
if (interceptorsEnabled) return mbsInterceptor; |
1285 |
else throw new UnsupportedOperationException( |
|
1286 |
"MBeanServerInterceptors are disabled."); |
|
1287 |
} |
|
1288 |
||
1289 |
/** |
|
1290 |
* Set the MBeanServerInterceptor. |
|
1291 |
* @exception UnsupportedOperationException if |
|
1292 |
* {@link MBeanServerInterceptor}s |
|
1293 |
* are not enabled on this object. |
|
1294 |
* @see #interceptorsEnabled |
|
1295 |
**/ |
|
1296 |
public synchronized void |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1297 |
setMBeanServerInterceptor(MBeanServer interceptor) { |
2 | 1298 |
if (!interceptorsEnabled) throw new UnsupportedOperationException( |
1299 |
"MBeanServerInterceptors are disabled."); |
|
1300 |
if (interceptor == null) throw new |
|
1301 |
IllegalArgumentException("MBeanServerInterceptor is null"); |
|
1302 |
mbsInterceptor = interceptor; |
|
1303 |
} |
|
1304 |
||
1305 |
/** |
|
1306 |
* <p>Return the {@link java.lang.ClassLoader} that was used for |
|
1307 |
* loading the class of the named MBean. |
|
1308 |
* @param mbeanName The ObjectName of the MBean. |
|
1309 |
* @return The ClassLoader used for that MBean. |
|
1310 |
* @exception InstanceNotFoundException if the named MBean is not found. |
|
1311 |
*/ |
|
1312 |
public ClassLoader getClassLoaderFor(ObjectName mbeanName) |
|
1313 |
throws InstanceNotFoundException { |
|
1314 |
return mbsInterceptor.getClassLoaderFor(cloneObjectName(mbeanName)); |
|
1315 |
} |
|
1316 |
||
1317 |
/** |
|
1318 |
* <p>Return the named {@link java.lang.ClassLoader}. |
|
1319 |
* @param loaderName The ObjectName of the ClassLoader. |
|
1320 |
* @return The named ClassLoader. |
|
1321 |
* @exception InstanceNotFoundException if the named ClassLoader |
|
1322 |
* is not found. |
|
1323 |
*/ |
|
1324 |
public ClassLoader getClassLoader(ObjectName loaderName) |
|
1325 |
throws InstanceNotFoundException { |
|
1326 |
return mbsInterceptor.getClassLoader(cloneObjectName(loaderName)); |
|
1327 |
} |
|
1328 |
||
1329 |
/** |
|
1330 |
* <p>Return the ClassLoaderRepository for that MBeanServer. |
|
1331 |
* @return The ClassLoaderRepository for that MBeanServer. |
|
1332 |
**/ |
|
1333 |
public ClassLoaderRepository getClassLoaderRepository() { |
|
1334 |
/* Permission check */ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1335 |
checkMBeanPermission(mbeanServerName, null, null, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1336 |
null, "getClassLoaderRepository"); |
2 | 1337 |
return secureClr; |
1338 |
} |
|
1339 |
||
1340 |
public MBeanServerDelegate getMBeanServerDelegate() { |
|
1341 |
if (!interceptorsEnabled) throw new UnsupportedOperationException( |
|
1342 |
"MBeanServerInterceptors are disabled."); |
|
1343 |
return mBeanServerDelegateObject; |
|
1344 |
} |
|
1345 |
||
1346 |
// These methods are called by the JMX MBeanServerBuilder. |
|
1347 |
||
1348 |
/** |
|
1349 |
* This method creates a new MBeanServerDelegate for a new MBeanServer. |
|
1350 |
* When creating a new MBeanServer the |
|
1351 |
* {@link javax.management.MBeanServerBuilder} first calls this method |
|
1352 |
* in order to create a new MBeanServerDelegate. |
|
1353 |
* <br>Then it calls |
|
1354 |
* <code>newMBeanServer(defaultDomain,outer,delegate,interceptors)</code> |
|
1355 |
* passing the <var>delegate</var> that should be used by the MBeanServer |
|
1356 |
* implementation. |
|
1357 |
* <p>Note that the passed <var>delegate</var> might not be directly the |
|
1358 |
* MBeanServerDelegate that was returned by this method. It could |
|
1359 |
* be, for instance, a new object wrapping the previously |
|
1360 |
* returned object. |
|
1361 |
* |
|
1362 |
* @return A new {@link javax.management.MBeanServerDelegate}. |
|
1363 |
**/ |
|
1364 |
public static MBeanServerDelegate newMBeanServerDelegate() { |
|
1365 |
return new MBeanServerDelegateImpl(); |
|
1366 |
} |
|
1367 |
||
1368 |
/** |
|
1369 |
* This method creates a new MBeanServer implementation object. |
|
1370 |
* When creating a new MBeanServer the |
|
1371 |
* {@link javax.management.MBeanServerBuilder} first calls |
|
1372 |
* <code>newMBeanServerDelegate()</code> in order to obtain a new |
|
1373 |
* {@link javax.management.MBeanServerDelegate} for the new |
|
1374 |
* MBeanServer. Then it calls |
|
1375 |
* <code>newMBeanServer(defaultDomain,outer,delegate)</code> |
|
1376 |
* passing the <var>delegate</var> that should be used by the |
|
1377 |
* MBeanServer implementation. |
|
1378 |
* <p>Note that the passed <var>delegate</var> might not be directly the |
|
1379 |
* MBeanServerDelegate that was returned by this implementation. It could |
|
1380 |
* be, for instance, a new object wrapping the previously |
|
1381 |
* returned delegate. |
|
1382 |
* <p>The <var>outer</var> parameter is a pointer to the MBeanServer that |
|
1383 |
* should be passed to the {@link javax.management.MBeanRegistration} |
|
1384 |
* interface when registering MBeans inside the MBeanServer. |
|
1385 |
* If <var>outer</var> is <code>null</code>, then the MBeanServer |
|
1386 |
* implementation is free to use its own <code>this</code> pointer when |
|
1387 |
* invoking the {@link javax.management.MBeanRegistration} interface. |
|
1388 |
* <p>This makes it possible for a MBeanServer implementation to wrap |
|
1389 |
* another MBeanServer implementation, in order to implement, e.g, |
|
1390 |
* security checks, or to prevent access to the actual MBeanServer |
|
1391 |
* implementation by returning a pointer to a wrapping object. |
|
1392 |
* |
|
1393 |
* @param defaultDomain Default domain of the new MBeanServer. |
|
1394 |
* @param outer A pointer to the MBeanServer object that must be |
|
1395 |
* passed to the MBeans when invoking their |
|
1396 |
* {@link javax.management.MBeanRegistration} interface. |
|
1397 |
* @param delegate A pointer to the MBeanServerDelegate associated |
|
1398 |
* with the new MBeanServer. The new MBeanServer must register |
|
1399 |
* this MBean in its MBean repository. |
|
1400 |
* @param interceptors If <code>true</code>, |
|
1401 |
* {@link MBeanServerInterceptor}s will be enabled (default is |
|
1402 |
* <code>false</code>). |
|
1403 |
* Note: this parameter is not taken into account by this |
|
1404 |
* implementation - the default value <code>false</code> is |
|
1405 |
* always used. |
|
1406 |
* @return A new private implementation of an MBeanServer. |
|
1407 |
* @see #interceptorsEnabled |
|
1408 |
* @see javax.management.MBeanServerBuilder |
|
1409 |
* @see com.sun.jmx.mbeanserver.JmxMBeanServerBuilder |
|
1410 |
**/ |
|
1411 |
public static MBeanServer newMBeanServer(String defaultDomain, |
|
1412 |
MBeanServer outer, |
|
1413 |
MBeanServerDelegate delegate, |
|
1414 |
boolean interceptors) { |
|
1415 |
// Determine whether to use fair locking for the repository. |
|
1416 |
// Default is true. |
|
1417 |
final boolean fairLock = DEFAULT_FAIR_LOCK_POLICY; |
|
1418 |
||
1419 |
// This constructor happens to disregard the value of the interceptors |
|
1420 |
// flag - that is, it always uses the default value - false. |
|
1421 |
// This is admitedly a bug, but we chose not to fix it for now |
|
1422 |
// since we would rather not have anybody depending on the Sun private |
|
1423 |
// interceptor APIs - which is most probably going to be removed and |
|
1424 |
// replaced by a public (javax) feature in the future. |
|
1425 |
// |
|
1426 |
return new JmxMBeanServer(defaultDomain,outer,delegate,null, |
|
1427 |
interceptors,fairLock); |
|
1428 |
} |
|
1429 |
||
1430 |
// JMX OBJECT CLONING |
|
1431 |
//------------------- |
|
1432 |
||
1433 |
/** |
|
1434 |
* Clone object name. |
|
1435 |
*/ |
|
1436 |
private ObjectName cloneObjectName(ObjectName name) { |
|
1437 |
if (name != null) { |
|
1438 |
return ObjectName.getInstance(name); |
|
1439 |
} |
|
1440 |
return name; |
|
1441 |
} |
|
1442 |
||
1443 |
/** |
|
1444 |
* Clone attribute. |
|
1445 |
*/ |
|
1446 |
private Attribute cloneAttribute(Attribute attribute) { |
|
1447 |
if (attribute != null) { |
|
1448 |
if (!attribute.getClass().equals(Attribute.class)) { |
|
1449 |
return new Attribute(attribute.getName(), attribute.getValue()); |
|
1450 |
} |
|
1451 |
} |
|
1452 |
return attribute; |
|
1453 |
} |
|
1454 |
||
1455 |
/** |
|
1456 |
* Clone attribute list. |
|
1457 |
*/ |
|
1458 |
private AttributeList cloneAttributeList(AttributeList list) { |
|
1459 |
if (list != null) { |
|
1460 |
if (!list.getClass().equals(AttributeList.class)) { |
|
1461 |
// Create new attribute list |
|
1462 |
// |
|
1463 |
AttributeList newList = new AttributeList(list.size()); |
|
1464 |
||
1465 |
// Iterate through list and replace non JMX attributes |
|
1466 |
// |
|
1467 |
for (Iterator i = list.iterator(); i.hasNext(); ) { |
|
1468 |
Attribute attribute = (Attribute) i.next(); |
|
1469 |
newList.add(cloneAttribute(attribute)); |
|
1470 |
} |
|
1471 |
return newList; |
|
1472 |
} else { |
|
1473 |
// Iterate through list and replace non JMX attributes |
|
1474 |
// |
|
1475 |
for (int i = 0; i < list.size(); i++) { |
|
1476 |
Attribute attribute = (Attribute) list.get(i); |
|
1477 |
if (!attribute.getClass().equals(Attribute.class)) { |
|
1478 |
list.set(i, cloneAttribute(attribute)); |
|
1479 |
} |
|
1480 |
} |
|
1481 |
return list; |
|
1482 |
} |
|
1483 |
} |
|
1484 |
return list; |
|
1485 |
} |
|
1486 |
||
1487 |
// SECURITY CHECKS |
|
1488 |
//---------------- |
|
1489 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1490 |
private static void checkMBeanPermission(String serverName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1491 |
String classname, |
2 | 1492 |
String member, |
1493 |
ObjectName objectName, |
|
1494 |
String actions) |
|
1495 |
throws SecurityException { |
|
1496 |
SecurityManager sm = System.getSecurityManager(); |
|
1497 |
if (sm != null) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1498 |
Permission perm = new MBeanPermission(serverName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
2
diff
changeset
|
1499 |
classname, |
2 | 1500 |
member, |
1501 |
objectName, |
|
1502 |
actions); |
|
1503 |
sm.checkPermission(perm); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
} |