KickJava   Java API By Example, From Geeks To Geeks.

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


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
35 /**
36  * @ejbHome <{com.sun.enterprise.management.agent.MEJBHome}>
37  * @ejbRemote <{com.sun.enterprise.management.agent.MEJB}>
38  *
39  * @author Hans Hrasna
40  */

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

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

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

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

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

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

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

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

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

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

253     public Object JavaDoc getAttribute(ObjectName name, String JavaDoc attribute) throws MBeanException,
254         javax.management.AttributeNotFoundException JavaDoc, javax.management.InstanceNotFoundException JavaDoc,
255         javax.management.ReflectionException JavaDoc, RemoteException JavaDoc {
256             /*
257         Object svr = findServer(name);
258         if (svr instanceof MBeanServer) {
259             return ((MBeanServer)svr).getAttribute(name, attribute);
260         }
261         return ((IIOPMBeanServer)svr).getAttribute(name, attribute);
262              */

263             return server.getAttribute(name, attribute);
264     }
265
266     /**
267      * Enables the values of several attributes of a named MBean. The MBean is identified by its object name.
268      * @param name The object name of the MBean from which the attributes are retrieved.
269      * @param attributes A list of the attributes to be retrieved.
270      * @return The list of the retrieved attributes.
271      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
272      * @exception ReflectionException An exception occurred when trying to invoke the getAttributes method of a Dynamic MBean.
273      * @exception RuntimeOperationsException Wrap a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
274      * parameter is null or attributes in parameter is null.
275      * /
276     public javax.management.AttributeList getAttributes(ObjectName name, String[] attributes)
277         throws javax.management.InstanceNotFoundException, javax.management.ReflectionException, RemoteException {
278         Object svr = findServer(name);
279         if (svr instanceof MBeanServer) {
280             return ((MBeanServer)svr).getAttributes(name, attributes);
281         }
282         return ((IIOPMBeanServer)svr).getAttributes(name, attributes);
283         // return server.getAttributes(name, attributes);
284     }
285
286     /**
287      * Sets the value of a specific attribute of a named MBean. The MBean is identified by its object name.
288      * @param name The name of the MBean within which the attribute is to be set.
289      * @param attribute The identification of the attribute to be set and the value it is to be set to.
290      * @return The value of the attribute that has been set.
291      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
292      * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
293      * @exception InvalidAttributeValueException The value specified for the attribute is not valid.
294      * @exception MBeanException Wraps an exception thrown by the MBean's setter.
295      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown when trying to invoke the setter.
296      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
297      * parameter is null or the attribute in parameter is null.
298      * /
299     public void setAttribute(ObjectName name, javax.management.Attribute attribute)
300         throws javax.management.InstanceNotFoundException, javax.management.AttributeNotFoundException,
301         javax.management.InvalidAttributeValueException, MBeanException,
302         javax.management.ReflectionException, RemoteException {
303         //server.setAttribute(name, attribute);
304         Object svr = findServer(name);
305         if (svr instanceof MBeanServer) {
306             ((MBeanServer)svr).setAttribute(name, attribute);
307         }else {
308             ((IIOPMBeanServer)svr).setAttribute(name, attribute);
309         }
310     }
311
312     /**
313      * Sets the values of several attributes of a named MBean. The MBean is identified by its object name.
314      * @param name The object name of the MBean within which the attributes are to be set.
315      * @param attributes A list of attributes: The identification of the
316      * attributes to be set and the values they are to be set to.
317      * @return The list of attributes that were set, with their new values.
318      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
319      * @exception ReflectionException An exception occurred when trying to invoke the getAttributes method of a Dynamic MBean.
320      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
321      * parameter is null or attributes in parameter is null.
322      * /
323     public javax.management.AttributeList setAttributes(ObjectName name, javax.management.AttributeList attributes)
324         throws javax.management.InstanceNotFoundException, javax.management.ReflectionException, RemoteException {
325         //return server.setAttributes(name, attributes);
326         Object svr = findServer(name);
327         if (svr instanceof MBeanServer) {
328             return ((MBeanServer)svr).setAttributes(name, attributes);
329         }
330         return ((IIOPMBeanServer)svr).setAttributes(name, attributes);
331     }
332
333     /**
334      * Invokes an operation on an MBean.
335      * @param name The object name of the MBean on which the method is to be invoked.
336      * @param operationName The name of the operation to be invoked.
337      * @param params An array containing the parameters to be set when the operation is invoked
338      * @param signature An array containing the signature of the operation. The class objects will
339      * be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.
340      * @return The object returned by the operation, which represents the result ofinvoking the operation
341      * on the MBean specified.
342      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
343      * @exception MBeanException Wraps an exception thrown by the MBean's invoked method.
344      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown while trying to invoke the method.
345      * /
346     public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
347         throws javax.management.InstanceNotFoundException, MBeanException,
348         javax.management.ReflectionException, RemoteException {
349         //return server.invoke(name, operationName, params, signature);
350         Object svr = findServer(name);
351         if (svr instanceof MBeanServer) {
352             return ((MBeanServer)svr).invoke(name, operationName, params, signature);
353         }
354         return ((IIOPMBeanServer)svr).invoke(name, operationName, params, signature);
355     }
356
357     /**
358      * Returns the default domain used for naming the managed object.
359      * The default domain name is used as the domain part in the ObjectName
360      * of managed objects if no domain is specified by the user.
361      * /
362     public String getDefaultDomain() {
363         return server.getDefaultDomain();
364     }
365
366     /*
367      * returns the ListenerRegistry implementation for this MEJB
368      */

369
370     public ListenerRegistration getListenerRegistry() {
371         if (listenerRegistry == null) {
372             try {
373                 listenerRegistry = new ListenerRegistry(java.net.InetAddress.getLocalHost().getHostAddress());
374             } catch (java.net.UnknownHostException JavaDoc e) {
375                 listenerRegistry = new ListenerRegistry(com.sun.enterprise.management.model.J2EEDomainMdl.DOMAINNAME);
376             }
377         }
378         return listenerRegistry;
379     }
380
381     /* TBD SRI
382     //called by AppContainer to register an AppClientModule MO if it wasn't registered during deployment
383     public void registerAppClient(com.sun.enterprise.deployment.ApplicationClientDescriptor d) throws RemoteException, java.io.IOException {
384         theSwitch.getManagementObjectManager().registerAppClient(d);
385     }
386
387      */

388     
389     // Additional MBeanServer interface implementation starts here
390

391     /**
392      * Instantiates an object using the list of all class loaders registered
393      * in the MBean server ({@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}).
394      * The object's class should have a public constructor. It returns a reference to the newly created object.
395      * The newly created object is not registered in the MBean server.
396      * @param className The class name of the object to be instantiated.
397      * @return The newly instantiated object.
398      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
399      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
400      * @exception MBeanException The constructor of the object has thrown an exception
401      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
402      * passed in parameter is null.
403      * /
404     public Object instantiate(String className) throws javax.management.ReflectionException, MBeanException, RemoteException {
405         return server.instantiate(className);
406     }
407
408     /**
409      * Instantiates an object using the class Loader specified by its <CODE>ObjectName</CODE>.
410      * If the loader name is null, the ClassLoader that loaded the MBean Server will be used.
411      * The object's class should have a public constructor. It returns a reference to the newly created object.
412      * The newly created object is not registered in the MBean server.
413      * @param className The class name of the MBean to be instantiated.
414      * @param loaderName The object name of the class loader to be used.
415      * @return The newly instantiated object.
416      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
417      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
418      * @exception MBeanException The constructor of the object has thrown an exception.
419      * @exception InstanceNotFoundException The specified class loader is not registered in the MBaenServer.
420      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
421      * passed in parameter is null.
422      * /
423     public Object instantiate(String className, ObjectName loaderName) throws javax.management.ReflectionException,
424         MBeanException, javax.management.InstanceNotFoundException, RemoteException {
425             return server.instantiate(className, loaderName);
426     }
427
428     /**
429      * Instantiates an object using the list of all class loaders registered
430      * in the MBean server ({@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}).
431      * The object's class should have a public constructor. The call returns a reference to the newly created object.
432      * The newly created object is not registered in the MBean server.
433      * @param className The class name of the object to be instantiated.
434      * @param params An array containing the parameters of the constructor to be invoked.
435      * @param signature An array containing the signature of the constructor to be invoked.
436      * @return The newly instantiated object.
437      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
438      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
439      * @exception MBeanException The constructor of the object has thrown an exception
440      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
441      * passed in parameter is null.
442      * /
443     public Object instantiate(String className, Object[] params, String[] signature) throws javax.management.ReflectionException,
444         MBeanException, RemoteException {
445             return server.instantiate(className, params, signature);
446     }
447
448     /**
449      * Instantiates an object. The class loader to be used is identified by its object
450      * name. If the object name of the loader is null, the ClassLoader that loaded the MBean server will be used.
451      * The object's class should have a public constructor. The call returns a reference to the newly created object.
452      * The newly created object is not registered in the MBean server.
453      * @param className The class name of the object to be instantiated.
454      * @param params An array containing the parameters of the constructor to be invoked.
455      * @param signature An array containing the signature of the constructor to be invoked.
456      * @param loaderName The object name of the class loader to be used.
457      * @return The newly instantiated object.
458      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the
459      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the object's constructor.
460      * @exception MBeanException The constructor of the object has thrown an exception
461      * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
462      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className
463      * passed in parameter is null.
464      * /
465     public Object instantiate(String className, ObjectName loaderName, Object[] params, String[] signature)
466         throws javax.management.ReflectionException, MBeanException,
467         javax.management.InstanceNotFoundException, RemoteException {
468             return server.instantiate(className, loaderName, params, signature);
469     }
470
471     /**
472      * Instantiates and registers an MBean in the MBean server. The MBean server will use the {@link
473      * javax.management.loading.DefaultLoaderRepository Default Loader Repository} to load the class of the MBean.
474      * An object name is associated to the MBean. If the object name given is null, the MBean can automatically provide its
475      * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface. The call returns
476      * an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
477      * @param className The class name of the MBean to be instantiated.
478      * @param name The object name of the MBean. May be null.
479      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
480      * of the newly instantiated MBean.
481      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
482      * <CODE><CODE>java.lang.Exception</CODE></CODE> that occurred when trying to invoke the MBean's constructor.
483      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
484      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method of
485      * the MBean has thrown an exception. The MBean will not be registered.
486      * @exception MBeanException The constructor of the MBean has thrown an exception
487      * @exception NotCompliantMBeanException This class is not a JMX compliant MBean
488      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
489      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
490      * specified for the MBean.
491      * /
492     public ObjectInstance createMBean(String className, ObjectName name) throws javax.management.ReflectionException,
493         javax.management.InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
494         NotCompliantMBeanException, RemoteException {
495             return server.createMBean(className, name);
496     }
497
498     /**
499      * Instantiates and registers an MBean in the MBean server. The class loader to be used is identified by its object name.
500      * An object name is associated to the MBean. If the object name of the loader is null, the ClassLoader that loaded the
501      * MBean server will be used. If the MBean's object name given is null, the MBean can automatically provide its
502      * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface. The call returns
503      * an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
504      * @param className The class name of the MBean to be instantiated.
505      * @param name The object name of the MBean. May be null.
506      * @param loaderName The object name of the class loader to be used.
507      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
508      * of the newly instantiated MBean.
509      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
510      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
511      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
512      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
513      * of the MBean has thrown an exception. The MBean will not be registered.
514      * @exception MBeanException The constructor of the MBean has thrown an exception
515      * @exception NotCompliantMBeanException This class is not a JMX compliant MBean
516      * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
517      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
518      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
519      * specified for the MBean.
520      * /
521     public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName)
522         throws javax.management.ReflectionException, javax.management.InstanceAlreadyExistsException,
523         MBeanRegistrationException, MBeanException, NotCompliantMBeanException,
524         javax.management.InstanceNotFoundException, RemoteException {
525             return server.createMBean(className, name, loaderName);
526     }
527
528     /**
529      * Instantiates and registers an MBean in the MBean server.
530      * The MBean server will use the {@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}
531      * to load the class of the MBean. An object name is associated to the MBean. If the object name given is null, the MBean
532      * can automatically provide its own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration}
533      * interface. The call returns an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
534      * @param className The class name of the MBean to be instantiated.
535      * @param name The object name of the MBean. May be null.
536      * @param params An array containing the parameters of the constructor to be invoked.
537      * @param signature An array containing the signature of the constructor to be invoked.
538      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
539      * of the newly instantiated MBean.
540      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
541      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
542      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
543      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
544      * of the MBean has thrown an exception. The MBean will not be registered.
545      * @exception MBeanException The constructor of the MBean has thrown an exception
546      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
547      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
548      * specified for the MBean.
549      * /
550     public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature)
551         throws javax.management.ReflectionException, javax.management.InstanceAlreadyExistsException,
552         MBeanRegistrationException, MBeanException, NotCompliantMBeanException, RemoteException {
553             return server.createMBean(className, name, params, signature);
554     }
555
556     /**
557      * Instantiates and registers an MBean in the MBean server. The class loader to be used is identified by its object
558      * name. An object name is associated to the MBean. If the object name
559      * of the loader is not specified, the ClassLoader that loaded the MBean server will be used.
560      * If the MBean object name given is null, the MBean can automatically provide its
561      * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface. The call returns
562      * an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
563      * @param className The class name of the MBean to be instantiated.
564      * @param name The object name of the MBean. May be null.
565      * @param params An array containing the parameters of the constructor to be invoked.
566      * @param signature An array containing the signature of the constructor to be invoked.
567      * @param loaderName The object name of the class loader to be used.
568      * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
569      * of the newly instantiated MBean.
570      * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a
571      * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
572      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
573      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
574      * of the MBean has thrown an exception. The MBean will not be registered.
575      * @exception MBeanException The constructor of the MBean has thrown an exception
576      * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
577      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in
578      * parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is
579      * specified for the MBean.
580      * /
581     public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature)
582         throws javax.management.ReflectionException, javax.management.InstanceAlreadyExistsException,
583         MBeanRegistrationException, MBeanException, NotCompliantMBeanException,
584         javax.management.InstanceNotFoundException, RemoteException {
585             return server.createMBean(className, name, loaderName, params, signature);
586     }
587
588     /**
589      * Registers a pre-existing object as an MBean with the MBean server. If the object name given is
590      * null, the MBean may automatically provide its own name by implementing the
591      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
592      * The call returns an <CODE>ObjectInstance</CODE> object representing the registered MBean.
593      * @param object The MBean to be registered as an MBean.
594      * @param name The object name of the MBean. May be null.
595      * @return The <CODE>ObjectInstance</CODE> for the MBean that has been registered.
596      * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
597      * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method
598      * of the MBean has thrown an exception. The MBean will not be registered.
599      * @exception NotCompliantMBeanException This object is not a JMX compliant MBean
600      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object passed in
601      * parameter is null or no object name is specified.
602      * /
603     public ObjectInstance registerMBean(Object object, ObjectName name) throws javax.management.InstanceAlreadyExistsException,
604         MBeanRegistrationException, NotCompliantMBeanException, RemoteException {
605             return server.registerMBean(object, name);
606     }
607
608     /**
609      * De-registers an MBean from the MBean server. The MBean is identified by
610      * its object name. Once the method has been invoked, the MBean may no longer be accessed by its object name.
611      * @param name The object name of the MBean to be de-registered.
612      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
613      * @exception MBeanRegistrationException The preDeregister ((<CODE>MBeanRegistration</CODE> interface) method of the MBean
614      * has thrown an exception.
615      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
616      * parameter is null or the MBean you are when trying to de-register is the {@link javax.management.MBeanServerDelegate
617      * MBeanServerDelegate} MBean.
618      * /
619     public void unregisterMBean(ObjectName name) throws InstanceNotFoundException,
620         MBeanRegistrationException, RemoteException {
621         Object svr = findServer(name);
622         if (svr instanceof MBeanServer) {
623             ((MBeanServer)svr).unregisterMBean(name);
624             return;
625         }
626         ((IIOPMBeanServer)svr).unregisterMBean(name);
627     }
628
629     /**
630      * Gets the <CODE>ObjectInstance</CODE> for a given MBean registered with the MBean server.
631      * @param name The object name of the MBean.
632      * @return The <CODE>ObjectInstance</CODE> associated to the MBean specified by <VAR>name</VAR>.
633      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
634      * /
635     public ObjectInstance getObjectInstance(ObjectName name)
636         throws javax.management.InstanceNotFoundException, RemoteException {
637             return server.getObjectInstance(name);
638     }
639
640     /**
641      * Gets MBeans controlled by the MBean server. This method allows any
642      * of the following to be obtained: All MBeans, a set of MBeans specified
643      * by pattern matching on the <CODE>ObjectName</CODE> and/or a Query expression, a
644      * specific MBean. When the object name is null or no domain and key properties are specified, all objects are to be
645      * selected (and filtered if a query is specified). It returns the
646      * set of <CODE>ObjectInstance</CODE> objects (containing the <CODE>ObjectName</CODE> and the Java Class name)
647      * for the selected MBeans.
648      * @param name The object name pattern identifying the MBeans to be retrieved. If
649      * null or no domain and key properties are specified, all the MBeans registered will be retrieved.
650      * @param query The query expression to be applied for selecting MBeans. If null
651      * no query expression will be applied for selecting MBeans.
652      * @return A set containing the <CODE>ObjectInstance</CODE> objects for the selected MBeans.
653      * If no MBean satisfies the query an empty list is returned.
654      * /
655     public Set queryMBeans(ObjectName name, QueryExp query) throws RemoteException {
656         return server.queryMBeans(name, query);
657     }
658
659     /**
660      * Returns the default domain used for naming the MBean. The default domain name is used as the domain part in the
661      * ObjectName of MBeans if no domain is specified by the user.
662      */

663     //public String getDefaultDomain() throws RemoteException;
664

665     /**
666      * Enables to add a listener to a registered MBean.
667      * @param name The name of the MBean on which the listener should be added.
668      * @param listener The listener object which will handle the notifications emitted by the registered MBean.
669      * @param filter The filter object. If filter is null, no filtering will be performed before handling notifications.
670      * @param handback The context to be sent to the listener when a notification is emitted.
671      * @exception InstanceNotFoundException The MBean name provided does not match any of the registered MBeans.
672      */

673     public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object JavaDoc handback)
674         throws javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
675             /*
676         Object svr = findServer(name);
677         if (svr instanceof MBeanServer) {
678             if (listener instanceof RemoteListenerConnector) {
679                 ((RemoteListenerConnector)listener).setMBeanServer((MBeanServer)svr);
680             }
681             ((MBeanServer)svr).addNotificationListener(name, listener, filter, handback);;
682             return;
683         }
684         //not yet supported, need to add to IIOPMBeanServer interface/impl
685         //((IIOPMBeanServer)svr).addNotificationListener(name, listener, filter, handback);
686              */

687             server.addNotificationListener(name, listener, filter, handback);
688     }
689
690     /**
691      * Enables to add a listener to a registered MBean.
692      * @param name The name of the MBean on which the listener should be added.
693      * @param listener The object name of the listener which will handle the notifications emitted by the registered MBean.
694      * @param filter The filter object. If filter is null, no filtering will be performed before handling notifications.
695      * @param handback The context to be sent to the listener when a notification is emitted.
696      * @exception InstanceNotFoundException The MBean name of the notification listener or of the notification broadcaster
697      * does not match any of the registered MBeans.
698      */

699     public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object JavaDoc handback)
700         throws javax.management.InstanceNotFoundException JavaDoc, RemoteException JavaDoc {
701             server.addNotificationListener(name, listener, filter, handback);
702     }
703
704     /**
705      * Enables to remove a listener from a registered MBean.
706      * @param name The name of the MBean on which the listener should be removed.
707      * @param listener The listener object which will handle the notifications emitted by the registered MBean.
708      * This method will remove all the information related to this listener.
709      * @exception InstanceNotFoundException The MBean name provided does not match any of the registered MBeans.
710      * @exception ListenerNotFoundException The listener is not registered in the MBean.
711      */

712     public void removeNotificationListener(ObjectName name, NotificationListener listener)
713         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.ListenerNotFoundException JavaDoc, RemoteException JavaDoc {
714             /*
715         Object svr = findServer(name);
716         if (svr instanceof MBeanServer) {
717             ((MBeanServer)svr).removeNotificationListener(name, listener);
718             return;
719         }
720         //not yet supported, need to add to IIOPMBeanServer interface/impl
721         //((IIOPMBeanServer)svr).removeNotificationListener(name, listener);
722         //server.removeNotificationListener(name, listener);
723              */

724             
725             server.removeNotificationListener(name, listener);
726     }
727
728     /**
729      * Enables to remove a listener from a registered MBean.
730      * @param name The name of the MBean on which the listener should be removed.
731      * @param listener The object name of the listener which will handle the notifications emitted by the registered MBean.
732      * This method will remove all the information related to this listener.
733      * @exception InstanceNotFoundException The MBean name provided does not match any of the registered MBeans.
734      * @exception ListenerNotFoundException The listener is not registered in the MBean.
735      */

736     public void removeNotificationListener(ObjectName name, ObjectName listener) throws javax.management.InstanceNotFoundException JavaDoc,
737         javax.management.ListenerNotFoundException JavaDoc, RemoteException JavaDoc {
738             server.removeNotificationListener(name, listener);
739     }
740
741     /**
742      * Returns true if the MBean specified is an instance of the specified class, false otherwise.
743      * @param name The <CODE>ObjectName</CODE> of the MBean.
744      * @param className The name of the class.
745      * @return true if the MBean specified is an instance of the specified class, false otherwise.
746      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
747      * /
748     public boolean isInstanceOf(ObjectName name, String className)
749         throws javax.management.InstanceNotFoundException, RemoteException {
750             return server.isInstanceOf(name, className);
751     }
752      */

753 }
754
Popular Tags