KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > agent > MEJBUtility


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.agent;
25
26 import java.security.*;
27 import java.rmi.RemoteException JavaDoc;
28 import java.util.*;
29 import java.io.ObjectInputStream JavaDoc;
30 //import javax.ejb.*; //
31
import javax.management.*;
32 import javax.management.j2ee.*;
33 import javax.naming.*;
34 import com.sun.enterprise.management.util.J2EEModuleUtil;
35
36 /**
37  * @ejbHome <{com.sun.enterprise.management.agent.MEJBHome}>
38  * @ejbRemote <{com.sun.enterprise.management.agent.MEJB}>
39  *
40  * @author Hans Hrasna
41  */

42 public class MEJBUtility {
43     private MBeanServer server;
44     private ListenerRegistry listenerRegistry = null;
45     //private com.sun.enterprise.Switch theSwitch =
46
// com.sun.enterprise.Switch.getSwitch(); //TBD SRI
47

48     private static MEJBUtility mejbUtility = null;
49     
50     private MEJBUtility(){
51         ArrayList mbservers = (ArrayList) AccessController.doPrivileged(
52         new PrivilegedAction() {
53                     public java.lang.Object JavaDoc run() {
54                         return MBeanServerFactory.findMBeanServer(null);
55                     }
56                 });
57         if (mbservers.isEmpty()) {
58             server = null;
59         }
60         else {
61             server = (MBeanServer)mbservers.get(0);
62         }
63     }
64     public static MEJBUtility getMEJBUtility(){
65         if(mejbUtility == null){
66             mejbUtility = new MEJBUtility();
67         }
68         return mejbUtility;
69     }
70     /*
71     Set getRemoteMBeanServers() {
72         HashSet hs = new HashSet();
73         InitialContext ic = null;
74         Binding b = null;
75         try {
76             ic = new InitialContext();
77             NamingEnumeration ne = ic.listBindings("ejb/mgmt/rmbs");
78             while (ne.hasMore()) {
79                 b = (Binding)ne.next();
80                 //test binding, check if this IIOPMBeanServer is still valid before adding to the set
81                 IIOPMBeanServer ios = (IIOPMBeanServer)b.getObject();
82                 ios.getDefaultDomain();
83                 hs.add(ios);
84             }
85         } catch (java.rmi.MarshalException me) {
86             try {
87                 javax.naming.CompositeName cn = new javax.naming.CompositeName("ejb/mgmt/rmbs/" + b.getName());
88                 ic.unbind(cn);
89             }
90             catch (Exception e1) {
91                 System.out.println(e1);
92             }
93         } catch (Exception e) {
94         }
95         return hs;
96     }
97
98      */

99     
100     /**
101      * Find the MBean server a managed object is registered with.
102      * @param name The OBJECT_NAME of the managed object
103      * @return An instance of MBeanServer or IIOPMBeanServer.
104      * @exception InstanceNotFoundException Thrown if the managed object is not found on
105      * any of the known MBeanServers.
106      * /
107     Object findServer(ObjectName name) throws InstanceNotFoundException {
108         Iterator servers = getRemoteMBeanServers().iterator();
109         //check local server
110         if (server.isRegistered(name)) {
111             return server;
112         }
113         //check remote servers
114         while (servers.hasNext()) {
115             IIOPMBeanServer iiopserver = (IIOPMBeanServer)servers.next();
116             try {
117                 if (iiopserver.isRegistered(name)) {
118                     return iiopserver;
119                 }
120             } catch (Exception e) {
121             }
122         }
123         throw new InstanceNotFoundException(name.toString());
124     }
125
126     // javax.management.j2ee.Management implementation starts here
127
128     /**
129      * Gets the names of managed objects controlled by the MEJB. This method
130      * enables any of the following to be obtained: The names of all managed objects,
131      * the names of a set of managed objects specified by pattern matching on the
132      * <CODE>ObjectName</CODE> and/or a Query expression, a specific managed object name (equivalent to
133      * testing whether an managed object is registered). When the object name is
134      * null or no domain and key properties are specified, all objects are selected (and filtered if a
135      * query is specified). It returns the set of ObjectNames for the managed objects selected.
136      * @param name The object name pattern identifying the managed objects to be retrieved. If
137      * null or no domain and key properties are specified, all the managed objects registered will be retrieved.
138      * @param query The query expression to be applied for selecting managed objects. If null
139      * no query expression will be applied for selecting managed objects.
140      * @return A set containing the ObjectNames for the managed objects selected.
141      * If no managed object satisfies the query, an empty list is returned.
142      */

143     
144     public Set queryNames(ObjectName name, QueryExp query) throws Exception JavaDoc {
145         /*
146         HashSet names = new HashSet();
147         Iterator servers = getRemoteMBeanServers().iterator();
148         if ((name == null) || (name.isPattern())) {
149             //check remote servers
150             while (servers.hasNext()) {
151                 IIOPMBeanServer iiopserver = (IIOPMBeanServer)servers.next();
152                 try {
153                     names.addAll(iiopserver.queryNames(name, query));
154                 } catch (Exception e) {
155                     System.out.println(this + ": "+ e);
156                 }
157             }
158             //check local server
159             names.addAll(server.queryNames(name, query));
160         } else {
161             try {
162                 Object svr = findServer(name);
163                 if (svr instanceof MBeanServer) {
164                     names.addAll(((MBeanServer)svr).queryNames(name, query));
165                 } else {
166                     names.addAll(((IIOPMBeanServer)svr).queryNames(name, query));
167                 }
168             } catch (InstanceNotFoundException e) {
169                 //System.out.println(this + ": "+ e);
170             } catch (Exception e) {
171                     throw e;
172                 //throw new RemoteException(this.toString() +"::queryNames", e);
173             }
174         }
175         return names;
176          */

177         return server.queryNames(name, query);
178     }
179
180     
181     /**
182      * Checks whether an MBean, identified by its object name, is already registered with the MBean server.
183      * @param name The object name of the MBean to be checked.
184      * @return True if the MBean is already registered in the MBean server, false otherwise.
185      */

186     
187     
188     public boolean isRegistered(ObjectName name) throws Exception JavaDoc {
189         //check remote servers
190
//DON'T EVER call findServer from here!!
191
/*Iterator servers = getRemoteMBeanServers().iterator();
192         while (servers.hasNext()) {
193             IIOPMBeanServer iiopserver = (IIOPMBeanServer)servers.next();
194             if (iiopserver.isRegistered(name)) {
195                 return true;
196             }
197         }*/

198         //check local server
199
return server.isRegistered(name);
200     }
201
202     
203     
204     /** Returns the number of MBeans registered in the MBean server. */
205     
206     public Integer JavaDoc getMBeanCount() throws Exception JavaDoc {
207         /*int i = 0;
208         Iterator servers = getRemoteMBeanServers().iterator();
209         while (servers.hasNext()) {
210             IIOPMBeanServer iiopserver = (IIOPMBeanServer)servers.next();
211             i = i + iiopserver.getMBeanCount().intValue();
212         }
213         //check local server
214         i = i + server.getMBeanCount().intValue();
215         return new Integer(i);
216          */

217         return server.getMBeanCount();
218     }
219
220      
221     
222     /**
223      * This method discovers the attributes and operations that an MBean exposes for management.
224      * @param name The name of the MBean to analyze
225      * @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of all attributes and operations of this MBean.
226      * @exception IntrospectionException An exception occurs during introspection.
227      * @exception InstanceNotFoundException The MBean specified is not found.
228      * @exception ReflectionException An exception occurred when trying to invoke the getMBeanInfo of a Dynamic MBean.
229      */

230     
231     public MBeanInfo getMBeanInfo(ObjectName name) throws javax.management.InstanceNotFoundException JavaDoc,
232         javax.management.IntrospectionException JavaDoc, javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
233         /* MBeanInfo mbi = null;
234         Object svr = findServer(name);
235         if (svr instanceof MBeanServer) {
236             mbi = ((MBeanServer)svr).getMBeanInfo(name);
237         } else {
238             mbi = ((IIOPMBeanServer)svr).getMBeanInfo(name);
239         }
240         return mbi;
241          **/

242         return server.getMBeanInfo(name);
243     }
244      
245
246     /**
247      * Gets the value of a specific attribute of a named MBean. The MBean is identified by its object name.
248      * @param name The object name of the MBean from which the attribute is to be retrieved.
249      * @param attribute A String specifying the name of the attribute to be retrieved.
250      * @return The value of the retrieved attribute.
251      * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
252      * @exception MBeanException Wraps an exception thrown by the MBean's getter.
253      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
254      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown when trying to invoke the setter.
255      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
256      * parameter is null or the attribute in parameter is null.
257      */

258     public Object JavaDoc getAttribute(ObjectName name, String JavaDoc attribute) throws MBeanException,
259         javax.management.AttributeNotFoundException JavaDoc, javax.management.InstanceNotFoundException JavaDoc,
260         javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
261             /*
262         Object svr = findServer(name);
263         if (svr instanceof MBeanServer) {
264             return ((MBeanServer)svr).getAttribute(name, attribute);
265         }
266         return ((IIOPMBeanServer)svr).getAttribute(name, attribute);
267              */

268             return server.getAttribute(name, attribute);
269     }
270
271     /**
272      * Enables the values of several attributes of a named MBean. The MBean is identified by its object name.
273      * @param name The object name of the MBean from which the attributes are retrieved.
274      * @param attributes A list of the attributes to be retrieved.
275      * @return The list of the retrieved attributes.
276      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
277      * @exception ReflectionException An exception occurred when trying to invoke the getAttributes method of a Dynamic MBean.
278      * @exception RuntimeOperationsException Wrap a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
279      * parameter is null or attributes in parameter is null.
280      */

281     public javax.management.AttributeList JavaDoc getAttributes(ObjectName name, String JavaDoc[] attributes)
282         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
283         /*Object svr = findServer(name);
284         if (svr instanceof MBeanServer) {
285             return ((MBeanServer)svr).getAttributes(name, attributes);
286         }
287         return ((IIOPMBeanServer)svr).getAttributes(name, attributes);
288         // return server.getAttributes(name, attributes);
289          **/

290        return server.getAttributes(name, attributes);
291     }
292
293     /**
294      * Sets the value of a specific attribute of a named MBean. The MBean is identified by its object name.
295      * @param name The name of the MBean within which the attribute is to be set.
296      * @param attribute The identification of the attribute to be set and the value it is to be set to.
297      * @return The value of the attribute that has been set.
298      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
299      * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
300      * @exception InvalidAttributeValueException The value specified for the attribute is not valid.
301      * @exception MBeanException Wraps an exception thrown by the MBean's setter.
302      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown when trying to invoke the setter.
303      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
304      * parameter is null or the attribute in parameter is null.
305      */

306     public void setAttribute(ObjectName name, javax.management.Attribute JavaDoc attribute)
307         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.AttributeNotFoundException JavaDoc,
308         javax.management.InvalidAttributeValueException JavaDoc, MBeanException,
309         javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
310         server.setAttribute(name, attribute);
311         /*Object svr = findServer(name);
312         if (svr instanceof MBeanServer) {
313             ((MBeanServer)svr).setAttribute(name, attribute);
314         }else {
315             ((IIOPMBeanServer)svr).setAttribute(name, attribute);
316         }*/

317     }
318
319     /**
320      * Sets the values of several attributes of a named MBean. The MBean is identified by its object name.
321      * @param name The object name of the MBean within which the attributes are to be set.
322      * @param attributes A list of attributes: The identification of the
323      * attributes to be set and the values they are to be set to.
324      * @return The list of attributes that were set, with their new values.
325      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
326      * @exception ReflectionException An exception occurred when trying to invoke the getAttributes method of a Dynamic MBean.
327      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
328      * parameter is null or attributes in parameter is null.
329      */

330     public javax.management.AttributeList JavaDoc setAttributes(ObjectName name, javax.management.AttributeList JavaDoc attributes)
331         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
332         return server.setAttributes(name, attributes);
333         /*Object svr = findServer(name);
334         if (svr instanceof MBeanServer) {
335             return ((MBeanServer)svr).setAttributes(name, attributes);
336         }
337         return ((IIOPMBeanServer)svr).setAttributes(name, attributes);
338          **/

339         
340     }
341
342     /**
343      * Invokes an operation on an MBean.
344      * @param name The object name of the MBean on which the method is to be invoked.
345      * @param operationName The name of the operation to be invoked.
346      * @param params An array containing the parameters to be set when the operation is invoked
347      * @param signature An array containing the signature of the operation. The class objects will
348      * be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.
349      * @return The object returned by the operation, which represents the result ofinvoking the operation
350      * on the MBean specified.
351      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
352      * @exception MBeanException Wraps an exception thrown by the MBean's invoked method.
353      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown while trying to invoke the method.
354      */

355     public Object JavaDoc invoke(ObjectName name, String JavaDoc operationName, Object JavaDoc[] params, String JavaDoc[] signature)
356         throws javax.management.InstanceNotFoundException JavaDoc, MBeanException,
357         javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
358         return server.invoke(name, operationName, params, signature);
359         /*Object svr = findServer(name);
360         if (svr instanceof MBeanServer) {
361             return ((MBeanServer)svr).invoke(name, operationName, params, signature);
362         }
363         return ((IIOPMBeanServer)svr).invoke(name, operationName, params, signature);
364          */

365     }
366
367     /**
368      * Returns the default domain used for naming the managed object.
369      * The default domain name is used as the domain part in the ObjectName
370      * of managed objects if no domain is specified by the user.
371      */

372     public String JavaDoc getDefaultDomain() {
373         return server.getDefaultDomain();
374     }
375
376     /*
377      * returns the ListenerRegistry implementation for this MEJB
378      */

379
380     public ListenerRegistration getListenerRegistry() {
381         if (listenerRegistry == null) {
382             try {
383                 listenerRegistry = new ListenerRegistry(java.net.InetAddress.getLocalHost().getHostAddress());
384             } catch (java.net.UnknownHostException JavaDoc e) {
385                 listenerRegistry = new ListenerRegistry(J2EEModuleUtil.getDomainName());
386             }
387         }
388         return listenerRegistry;
389     }
390
391     /* TBD SRI
392     //called by AppContainer to register an AppClientModule MO if it wasn't registered during deployment
393     public void registerAppClient(com.sun.enterprise.deployment.ApplicationClientDescriptor d) throws RemoteException, java.io.IOException {
394         theSwitch.getManagementObjectManager().registerAppClient(d);
395     }
396
397      */

398     
399     // Additional MBeanServer interface implementation starts here
400

401     /**
402      * Instantiates an object using the list of all class loaders registered
403      * in the MBean server ({@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}).
404      * The object's class should have a public constructor. It returns a reference to the newly created object.
405      * The newly created object is not registered in the MBean server.
406      * @param className The class name of the object to be instantiated.
407      * @return The newly instantiated object.
408      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
409      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
410      * @exception MBeanException The constructor of the object has thrown an exception
411      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
412      * passed in parameter is null.
413      */

414     public Object JavaDoc instantiate(String JavaDoc className) throws javax.management.ReflectionException JavaDoc, MBeanException, RemoteException JavaDoc {
415         return server.instantiate(className);
416     }
417
418     /**
419      * Instantiates an object using the class Loader specified by its <CODE>ObjectName</CODE>.
420      * If the loader name is null, the ClassLoader that loaded the MBean Server will be used.
421      * The object's class should have a public constructor. It returns a reference to the newly created object.
422      * The newly created object is not registered in the MBean server.
423      * @param className The class name of the MBean to be instantiated.
424      * @param loaderName The object name of the class loader to be used.
425      * @return The newly instantiated object.
426      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
427      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
428      * @exception MBeanException The constructor of the object has thrown an exception.
429      * @exception InstanceNotFoundException The specified class loader is not registered in the MBaenServer.
430      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
431      * passed in parameter is null.
432      */

433     public Object JavaDoc instantiate(String JavaDoc className, ObjectName loaderName) throws javax.management.ReflectionException JavaDoc,
434         MBeanException, javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
435             return server.instantiate(className, loaderName);
436     }
437
438     /**
439      * Instantiates an object using the list of all class loaders registered
440      * in the MBean server ({@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}).
441      * The object's class should have a public constructor. The call returns a reference to the newly created object.
442      * The newly created object is not registered in the MBean server.
443      * @param className The class name of the object to be instantiated.
444      * @param params An array containing the parameters of the constructor to be invoked.
445      * @param signature An array containing the signature of the constructor to be invoked.
446      * @return The newly instantiated object.
447      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
448      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
449      * @exception MBeanException The constructor of the object has thrown an exception
450      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
451      * passed in parameter is null.
452      */

453     public Object JavaDoc instantiate(String JavaDoc className, Object JavaDoc[] params, String JavaDoc[] signature) throws javax.management.ReflectionException JavaDoc,
454         MBeanException, RemoteException JavaDoc {
455             return server.instantiate(className, params, signature);
456     }
457
458     /**
459      * Instantiates an object. The class loader to be used is identified by its object
460      * name. If the object name of the loader is null, the ClassLoader that loaded the MBean server will be used.
461      * The object's class should have a public constructor. The call returns a reference to the newly created object.
462      * The newly created object is not registered in the MBean server.
463      * @param className The class name of the object to be instantiated.
464      * @param params An array containing the parameters of the constructor to be invoked.
465      * @param signature An array containing the signature of the constructor to be invoked.
466      * @param loaderName The object name of the class loader to be used.
467      * @return The newly instantiated object.
468      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
469      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
470      * @exception MBeanException The constructor of the object has thrown an exception
471      * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
472      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
473      * passed in parameter is null.
474      */

475     public Object JavaDoc instantiate(String JavaDoc className, ObjectName loaderName, Object JavaDoc[] params, String JavaDoc[] signature)
476         throws javax.management.ReflectionException JavaDoc, MBeanException,
477         javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
478             return server.instantiate(className, loaderName, params, signature);
479     }
480
481     /**
482      * Instantiates and registers an MBean in the MBean server. The MBean server will use the {@link
483      * javax.management.loading.DefaultLoaderRepository Default Loader Repository} to load the class of the MBean.
484      * An object name is associated to the MBean. If the object name given is null, the MBean can automatically provide its
485      * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface. The call returns
486      * an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
487      * @param className The class name of the MBean to be instantiated.
488      * @param name The object name of the MBean. May be null.
489      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
490      * of the newly instantiated MBean.
491      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
492      * <CODE><CODE>java.lang.Exception</CODE></CODE> that occurred when trying to invoke the MBean's constructor.
493      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
494      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method of
495      * the MBean has thrown an exception. The MBean will not be registered.
496      * @exception MBeanException The constructor of the MBean has thrown an exception
497      * @exception NotCompliantMBeanException This class is not a JMX compliant MBean
498      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
499      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
500      * specified for the MBean.
501      */

502     public ObjectInstance createMBean(String JavaDoc className, ObjectName name) throws javax.management.ReflectionException JavaDoc,
503         javax.management.InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException, MBeanException,
504         NotCompliantMBeanException, RemoteException JavaDoc {
505             return server.createMBean(className, name);
506     }
507
508     /**
509      * Instantiates and registers an MBean in the MBean server. The class loader to be used is identified by its object name.
510      * An object name is associated to the MBean. If the object name of the loader is null, the ClassLoader that loaded the
511      * MBean server will be used. If the MBean's object name given is null, the MBean can automatically provide its
512      * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface. The call returns
513      * an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
514      * @param className The class name of the MBean to be instantiated.
515      * @param name The object name of the MBean. May be null.
516      * @param loaderName The object name of the class loader to be used.
517      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
518      * of the newly instantiated MBean.
519      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
520      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
521      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
522      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
523      * of the MBean has thrown an exception. The MBean will not be registered.
524      * @exception MBeanException The constructor of the MBean has thrown an exception
525      * @exception NotCompliantMBeanException This class is not a JMX compliant MBean
526      * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
527      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
528      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
529      * specified for the MBean.
530      */

531     public ObjectInstance createMBean(String JavaDoc className, ObjectName name, ObjectName loaderName)
532         throws javax.management.ReflectionException JavaDoc, javax.management.InstanceAlreadyExistsException JavaDoc,
533         MBeanRegistrationException, MBeanException, NotCompliantMBeanException,
534         javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
535             return server.createMBean(className, name, loaderName);
536     }
537
538     /**
539      * Instantiates and registers an MBean in the MBean server.
540      * The MBean server will use the {@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}
541      * to load the class of the MBean. An object name is associated to the MBean. If the object name given is null, the MBean
542      * can automatically provide its own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration}
543      * interface. The call returns an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
544      * @param className The class name of the MBean to be instantiated.
545      * @param name The object name of the MBean. May be null.
546      * @param params An array containing the parameters of the constructor to be invoked.
547      * @param signature An array containing the signature of the constructor to be invoked.
548      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
549      * of the newly instantiated MBean.
550      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
551      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
552      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
553      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
554      * of the MBean has thrown an exception. The MBean will not be registered.
555      * @exception MBeanException The constructor of the MBean has thrown an exception
556      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
557      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
558      * specified for the MBean.
559      */

560     public ObjectInstance createMBean(String JavaDoc className, ObjectName name, Object JavaDoc[] params, String JavaDoc[] signature)
561         throws javax.management.ReflectionException JavaDoc, javax.management.InstanceAlreadyExistsException JavaDoc,
562         MBeanRegistrationException, MBeanException, NotCompliantMBeanException, RemoteException JavaDoc {
563             return server.createMBean(className, name, params, signature);
564     }
565
566     /**
567      * Instantiates and registers an MBean in the MBean server. The class loader to be used is identified by its object
568      * name. An object name is associated to the MBean. If the object name
569      * of the loader is not specified, the ClassLoader that loaded the MBean server will be used.
570      * If the MBean object name given is null, the MBean can automatically provide its
571      * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface. The call returns
572      * an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
573      * @param className The class name of the MBean to be instantiated.
574      * @param name The object name of the MBean. May be null.
575      * @param params An array containing the parameters of the constructor to be invoked.
576      * @param signature An array containing the signature of the constructor to be invoked.
577      * @param loaderName The object name of the class loader to be used.
578      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
579      * of the newly instantiated MBean.
580      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
581      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
582      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
583      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
584      * of the MBean has thrown an exception. The MBean will not be registered.
585      * @exception MBeanException The constructor of the MBean has thrown an exception
586      * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
587      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
588      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
589      * specified for the MBean.
590      */

591     public ObjectInstance createMBean(String JavaDoc className, ObjectName name, ObjectName loaderName, Object JavaDoc[] params, String JavaDoc[] signature)
592         throws javax.management.ReflectionException JavaDoc, javax.management.InstanceAlreadyExistsException JavaDoc,
593         MBeanRegistrationException, MBeanException, NotCompliantMBeanException,
594         javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
595             return server.createMBean(className, name, loaderName, params, signature);
596     }
597
598     /**
599      * Registers a pre-existing object as an MBean with the MBean server. If the object name given is
600      * null, the MBean may automatically provide its own name by implementing the
601      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
602      * The call returns an <CODE>ObjectInstance</CODE> object representing the registered MBean.
603      * @param object The MBean to be registered as an MBean.
604      * @param name The object name of the MBean. May be null.
605      * @return The <CODE>ObjectInstance</CODE> for the MBean that has been registered.
606      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
607      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
608      * of the MBean has thrown an exception. The MBean will not be registered.
609      * @exception NotCompliantMBeanException This object is not a JMX compliant MBean
610      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object passed in
611      * parameter is null or no object name is specified.
612      */

613     public ObjectInstance registerMBean(Object JavaDoc object, ObjectName name) throws javax.management.InstanceAlreadyExistsException JavaDoc,
614         MBeanRegistrationException, NotCompliantMBeanException, RemoteException JavaDoc {
615             return server.registerMBean(object, name);
616     }
617
618     /**
619      * De-registers an MBean from the MBean server. The MBean is identified by
620      * its object name. Once the method has been invoked, the MBean may no longer be accessed by its object name.
621      * @param name The object name of the MBean to be de-registered.
622      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
623      * @exception MBeanRegistrationException The preDeregister ((<CODE>MBeanRegistration</CODE> interface) method of the MBean
624      * has thrown an exception.
625      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
626      * parameter is null or the MBean you are when trying to de-register is the {@link javax.management.MBeanServerDelegate
627      * MBeanServerDelegate} MBean.
628      */

629     public void unregisterMBean(ObjectName name) throws InstanceNotFoundException,
630         MBeanRegistrationException, RemoteException JavaDoc {
631         /*Object svr = findServer(name);
632         if (svr instanceof MBeanServer) {
633             ((MBeanServer)svr).unregisterMBean(name);
634             return;
635         }
636         ((IIOPMBeanServer)svr).unregisterMBean(name);*/

637         server.unregisterMBean(name);
638     }
639
640     /**
641      * Gets the <CODE>ObjectInstance</CODE> for a given MBean registered with the MBean server.
642      * @param name The object name of the MBean.
643      * @return The <CODE>ObjectInstance</CODE> associated to the MBean specified by <VAR>name</VAR>.
644      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
645      */

646     public ObjectInstance getObjectInstance(ObjectName name)
647         throws javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
648             return server.getObjectInstance(name);
649     }
650
651     /**
652      * Gets MBeans controlled by the MBean server. This method allows any
653      * of the following to be obtained: All MBeans, a set of MBeans specified
654      * by pattern matching on the <CODE>ObjectName</CODE> and/or a Query expression, a
655      * specific MBean. When the object name is null or no domain and key properties are specified, all objects are to be
656      * selected (and filtered if a query is specified). It returns the
657      * set of <CODE>ObjectInstance</CODE> objects (containing the <CODE>ObjectName</CODE> and the Java Class name)
658      * for the selected MBeans.
659      * @param name The object name pattern identifying the MBeans to be retrieved. If
660      * null or no domain and key properties are specified, all the MBeans registered will be retrieved.
661      * @param query The query expression to be applied for selecting MBeans. If null
662      * no query expression will be applied for selecting MBeans.
663      * @return A set containing the <CODE>ObjectInstance</CODE> objects for the selected MBeans.
664      * If no MBean satisfies the query an empty list is returned.
665      */

666     public Set queryMBeans(ObjectName name, QueryExp query) throws RemoteException JavaDoc {
667         return server.queryMBeans(name, query);
668     }
669
670     /**
671      * Returns the default domain used for naming the MBean. The default domain name is used as the domain part in the
672      * ObjectName of MBeans if no domain is specified by the user.
673      */

674     //public String getDefaultDomain() throws RemoteException;
675

676     /**
677      * Enables to add a listener to a registered MBean.
678      * @param name The name of the MBean on which the listener should be added.
679      * @param listener The listener object which will handle the notifications emitted by the registered MBean.
680      * @param filter The filter object. If filter is null, no filtering will be performed before handling notifications.
681      * @param handback The context to be sent to the listener when a notification is emitted.
682      * @exception InstanceNotFoundException The MBean name provided does not match any of the registered MBeans.
683      */

684     public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object JavaDoc handback)
685         throws javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
686             /*
687         Object svr = findServer(name);
688         if (svr instanceof MBeanServer) {
689             if (listener instanceof RemoteListenerConnector) {
690                 ((RemoteListenerConnector)listener).setMBeanServer((MBeanServer)svr);
691             }
692             ((MBeanServer)svr).addNotificationListener(name, listener, filter, handback);;
693             return;
694         }
695         //not yet supported, need to add to IIOPMBeanServer interface/impl
696         //((IIOPMBeanServer)svr).addNotificationListener(name, listener, filter, handback);
697              */

698             server.addNotificationListener(name, listener, filter, handback);
699     }
700
701     /**
702      * Enables to add a listener to a registered MBean.
703      * @param name The name of the MBean on which the listener should be added.
704      * @param listener The object name of the listener which will handle the notifications emitted by the registered MBean.
705      * @param filter The filter object. If filter is null, no filtering will be performed before handling notifications.
706      * @param handback The context to be sent to the listener when a notification is emitted.
707      * @exception InstanceNotFoundException The MBean name of the notification listener or of the notification broadcaster
708      * does not match any of the registered MBeans.
709      */

710     public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object JavaDoc handback)
711         throws javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
712             server.addNotificationListener(name, listener, filter, handback);
713     }
714
715     /**
716      * Enables to remove a listener from a registered MBean.
717      * @param name The name of the MBean on which the listener should be removed.
718      * @param listener The listener object which will handle the notifications emitted by the registered MBean.
719      * This method will remove all the information related to this listener.
720      * @exception InstanceNotFoundException The MBean name provided does not match any of the registered MBeans.
721      * @exception ListenerNotFoundException The listener is not registered in the MBean.
722      */

723     public void removeNotificationListener(ObjectName name, NotificationListener listener)
724         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.ListenerNotFoundException JavaDoc, RemoteException JavaDoc {
725             /*
726         Object svr = findServer(name);
727         if (svr instanceof MBeanServer) {
728             ((MBeanServer)svr).removeNotificationListener(name, listener);
729             return;
730         }
731         //not yet supported, need to add to IIOPMBeanServer interface/impl
732         //((IIOPMBeanServer)svr).removeNotificationListener(name, listener);
733         //server.removeNotificationListener(name, listener);
734              */

735             
736             server.removeNotificationListener(name, listener);
737     }
738
739     /**
740      * Enables to remove a listener from a registered MBean.
741      * @param name The name of the MBean on which the listener should be removed.
742      * @param listener The object name of the listener which will handle the notifications emitted by the registered MBean.
743      * This method will remove all the information related to this listener.
744      * @exception InstanceNotFoundException The MBean name provided does not match any of the registered MBeans.
745      * @exception ListenerNotFoundException The listener is not registered in the MBean.
746      */

747     public void removeNotificationListener(ObjectName name, ObjectName listener) throws javax.management.InstanceNotFoundException JavaDoc,
748         javax.management.ListenerNotFoundException JavaDoc, RemoteException JavaDoc {
749             server.removeNotificationListener(name, listener);
750     }
751
752     /**
753      * Returns true if the MBean specified is an instance of the specified class, false otherwise.
754      * @param name The <CODE>ObjectName</CODE> of the MBean.
755      * @param className The name of the class.
756      * @return true if the MBean specified is an instance of the specified class, false otherwise.
757      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
758      */

759     public boolean isInstanceOf(ObjectName name, String JavaDoc className)
760         throws javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
761             return server.isInstanceOf(name, className);
762     }
763 }
764
Popular Tags