KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > rmi > ClientMBeanServerConnection


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.mx.remoting.rmi;
8
9 import java.io.IOException JavaDoc;
10 import java.io.NotSerializableException JavaDoc;
11 import java.rmi.MarshalledObject JavaDoc;
12 import java.util.Set JavaDoc;
13 import javax.management.Attribute JavaDoc;
14 import javax.management.AttributeList JavaDoc;
15 import javax.management.AttributeNotFoundException JavaDoc;
16 import javax.management.InstanceAlreadyExistsException JavaDoc;
17 import javax.management.InstanceNotFoundException JavaDoc;
18 import javax.management.IntrospectionException JavaDoc;
19 import javax.management.InvalidAttributeValueException JavaDoc;
20 import javax.management.ListenerNotFoundException JavaDoc;
21 import javax.management.MBeanException JavaDoc;
22 import javax.management.MBeanInfo JavaDoc;
23 import javax.management.MBeanRegistrationException JavaDoc;
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.NotCompliantMBeanException JavaDoc;
26 import javax.management.NotificationFilter JavaDoc;
27 import javax.management.NotificationListener JavaDoc;
28 import javax.management.ObjectInstance JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.QueryExp JavaDoc;
31 import javax.management.ReflectionException JavaDoc;
32 import javax.management.remote.rmi.RMIConnection JavaDoc;
33 import javax.security.auth.Subject JavaDoc;
34
35 /**
36  * This is the class that is passed to the client and is called
37  * on by the client to make the remote MBeanServer calls. This
38  * is really just a delegate to the rmi connection.
39  *
40  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
41  */

42 public class ClientMBeanServerConnection implements MBeanServerConnection JavaDoc
43 {
44    private RMIConnection JavaDoc connection = null;
45    private Subject JavaDoc subject = null;
46    private transient ClassLoader JavaDoc defaultClassLoader = null;
47    private ClientNotifier clientNotifier = null;
48
49
50    public ClientMBeanServerConnection(RMIConnection JavaDoc rmiConnection, ClientNotifier clientNotifier,
51                                       ClassLoader JavaDoc classLoader, Subject JavaDoc subject)
52    {
53       this.connection = rmiConnection;
54       this.clientNotifier = clientNotifier;
55       this.defaultClassLoader = classLoader;
56       this.subject = subject;
57    }
58
59    private ClassLoader JavaDoc activateDefaultClassLoader()
60    {
61       final ClassLoader JavaDoc current = Thread.currentThread().getContextClassLoader();
62       Thread.currentThread().setContextClassLoader(defaultClassLoader);
63       return current;
64    }
65
66    private void deActivateDefaultClassLoader(ClassLoader JavaDoc previousClassLoader)
67    {
68       Thread.currentThread().setContextClassLoader(previousClassLoader);
69    }
70
71    /**
72     * Create an MBean registered using the given object name.<p>
73     * <p/>
74     * Uses the default contructor.
75     *
76     * @param className the class name of the mbean
77     * @param name the object name for registration, can be null
78     * @return an ObjectInstance describing the registration
79     * @throws javax.management.ReflectionException
80     * for class not found or an exception
81     * invoking the contructor
82     * @throws javax.management.InstanceAlreadyExistsException
83     * for an MBean already registered
84     * with the passed or generated ObjectName
85     * @throws javax.management.MBeanRegistrationException
86     * for any exception thrown by the
87     * MBean's preRegister
88     * @throws javax.management.MBeanException
89     * for any exception thrown by the MBean's constructor
90     * @throws javax.management.NotCompliantMBeanException
91     * if the class name does not correspond to
92     * a valid MBean
93     * @throws javax.management.RuntimeOperationsException
94     * wrapping an IllegalArgumentException for a
95     * null class name, the ObjectName could not be determined or it is a pattern
96     * @throws java.io.IOException for a communication problem during this operation
97     */

98    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name)
99          throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
100                 MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, IOException JavaDoc
101    {
102       final ClassLoader JavaDoc current = activateDefaultClassLoader();
103
104       try
105       {
106          return connection.createMBean(className, name, subject);
107       }
108       finally
109       {
110          deActivateDefaultClassLoader(current);
111       }
112    }
113
114    /**
115     * Create an MBean registered using the given object name.<p>
116     * <p/>
117     * The MBean is loaded using the passed classloader. Uses the default contructor.
118     *
119     * @param className the class name of the mbean
120     * @param loaderName an MBean that implements a classloader
121     * @param name the object name for registration, can be null
122     * @return an ObjectInstance describing the registration
123     * @throws javax.management.ReflectionException
124     * for class not found or an exception
125     * invoking the contructor
126     * @throws javax.management.InstanceAlreadyExistsException
127     * for an MBean already registered
128     * with the passed or generated ObjectName
129     * @throws javax.management.MBeanRegistrationException
130     * for any exception thrown by the
131     * MBean's preRegister
132     * @throws javax.management.MBeanException
133     * for any exception thrown by the MBean's constructor
134     * @throws javax.management.InstanceNotFoundException
135     * if the loaderName is not a classloader registered
136     * in the MBeanServer
137     * @throws javax.management.NotCompliantMBeanException
138     * if the class name does not correspond to
139     * a valid MBean
140     * @throws javax.management.RuntimeOperationsException
141     * wrapping an IllegalArgumentException for a
142     * null class name, the ObjectName could not be determined or it is a pattern
143     * @throws java.io.IOException for a communication problem during this operation
144     */

145    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name, ObjectName JavaDoc loaderName)
146          throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
147                 MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc, IOException JavaDoc
148    {
149       final ClassLoader JavaDoc current = activateDefaultClassLoader();
150
151       try
152       {
153          return connection.createMBean(className, name, loaderName, subject);
154       }
155       finally
156       {
157          deActivateDefaultClassLoader(current);
158       }
159
160    }
161
162    /**
163     * Create an MBean registered using the given object name.<p>
164     * <p/>
165     * Uses the specified constructor.
166     *
167     * @param className the class name of the mbean
168     * @param name the object name for registration, can be null
169     * @param params the parameters for the constructor
170     * @param signature the signature of the constructor
171     * @return an ObjectInstance describing the registration
172     * @throws javax.management.ReflectionException
173     * for class not found or an exception
174     * invoking the contructor
175     * @throws javax.management.InstanceAlreadyExistsException
176     * for an MBean already registered
177     * with the passed or generated ObjectName
178     * @throws javax.management.MBeanRegistrationException
179     * for any exception thrown by the
180     * MBean's preRegister
181     * @throws javax.management.MBeanException
182     * for any exception thrown by the MBean's constructor
183     * @throws javax.management.NotCompliantMBeanException
184     * if the class name does not correspond to
185     * a valid MBean
186     * @throws javax.management.RuntimeOperationsException
187     * wrapping an IllegalArgumentException for a
188     * null class name, the ObjectName could not be determined or it is a pattern
189     * @throws java.io.IOException for a communication problem during this operation
190     */

191    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name, Object JavaDoc[] params, String JavaDoc[] signature)
192          throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
193                 MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, IOException JavaDoc
194    {
195       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(params);
196       final ClassLoader JavaDoc current = activateDefaultClassLoader();
197
198       try
199       {
200          return connection.createMBean(className, name, args, signature, subject);
201       }
202       finally
203       {
204          deActivateDefaultClassLoader(current);
205       }
206    }
207
208    /**
209     * Create an MBean registered using the given object name.<p>
210     * <p/>
211     * The MBean is loaded using the passed classloader. Uses the specified constructor.
212     *
213     * @param className the class name of the mbean
214     * @param loaderName an MBean that implements a classloader
215     * @param name the object name for registration, can be null
216     * @param params the parameters for the constructor
217     * @param signature the signature of the constructor
218     * @return an ObjectInstance describing the registration
219     * @throws javax.management.ReflectionException
220     * for class not found or an exception
221     * invoking the contructor
222     * @throws javax.management.InstanceAlreadyExistsException
223     * for an MBean already registered
224     * with the passed or generated ObjectName
225     * @throws javax.management.MBeanRegistrationException
226     * for any exception thrown by the
227     * MBean's preRegister
228     * @throws javax.management.MBeanException
229     * for any exception thrown by the MBean's constructor
230     * @throws javax.management.InstanceNotFoundException
231     * if the loaderName is not a classloader registered
232     * in the MBeanServer
233     * @throws javax.management.NotCompliantMBeanException
234     * if the class name does not correspond to
235     * a valid MBean
236     * @throws javax.management.RuntimeOperationsException
237     * wrapping an IllegalArgumentException for a
238     * null class name, the ObjectName could not be determined or it is a pattern
239     * @throws java.io.IOException for a communication problem during this operation
240     */

241    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name, ObjectName JavaDoc loaderName,
242                                      Object JavaDoc[] params, String JavaDoc[] signature)
243          throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
244                 MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc, IOException JavaDoc
245    {
246       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(params);
247       final ClassLoader JavaDoc current = activateDefaultClassLoader();
248
249       try
250       {
251          return connection.createMBean(className, name, loaderName, args, signature, subject);
252       }
253       finally
254       {
255          deActivateDefaultClassLoader(current);
256       }
257    }
258
259    /**
260     * Unregisters an mbean.
261     *
262     * @param name the object name of the mbean to unregister
263     * @throws javax.management.InstanceNotFoundException
264     * if the mbean is not registered
265     * in the MBeanServer
266     * @throws javax.management.MBeanRegistrationException
267     * for any exception thrown by the
268     * MBean's preDeregister
269     * @throws javax.management.RuntimeOperationsException
270     * wrapping an IllegalArgumentException for a
271     * null name, or trying to unregister a JMX implementation MBean
272     * @throws java.io.IOException for a communication problem during this operation
273     */

274    public void unregisterMBean(ObjectName JavaDoc name) throws InstanceNotFoundException JavaDoc, MBeanRegistrationException JavaDoc, IOException JavaDoc
275    {
276       final ClassLoader JavaDoc current = activateDefaultClassLoader();
277
278       try
279       {
280          connection.unregisterMBean(name, subject);
281       }
282       finally
283       {
284          deActivateDefaultClassLoader(current);
285       }
286    }
287
288    /**
289     * Retrieve an MBean's registration information.
290     *
291     * @param name the object name of the mbean
292     * @throws javax.management.InstanceNotFoundException
293     * if the mbean is not registered
294     * in the MBeanServer
295     * @throws java.io.IOException for a communication problem during this operation
296     */

297    public ObjectInstance JavaDoc getObjectInstance(ObjectName JavaDoc name) throws InstanceNotFoundException JavaDoc, IOException JavaDoc
298    {
299       final ClassLoader JavaDoc current = activateDefaultClassLoader();
300
301       try
302       {
303          return connection.getObjectInstance(name, subject);
304       }
305       finally
306       {
307          deActivateDefaultClassLoader(current);
308       }
309    }
310
311    /**
312     * Retrieve a set of Object instances
313     *
314     * @param name an ObjectName pattern, can be null for all mbeans
315     * @param query a query expression to further filter the mbeans, can be null
316     * for no query
317     * @throws java.io.IOException for a communication problem during this operation
318     */

319    public Set JavaDoc queryMBeans(ObjectName JavaDoc name, QueryExp JavaDoc query) throws IOException JavaDoc
320    {
321       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(query);
322       final ClassLoader JavaDoc current = activateDefaultClassLoader();
323
324       try
325       {
326          return connection.queryMBeans(name, args, subject);
327       }
328       finally
329       {
330          deActivateDefaultClassLoader(current);
331       }
332    }
333
334    /**
335     * Retrieve a set of Object names
336     *
337     * @param name an ObjectName pattern, can be null for all mbeans
338     * @param query a query expression to further filter the mbeans, can be null
339     * for no query
340     * @throws java.io.IOException for a communication problem during this operation
341     */

342    public Set JavaDoc queryNames(ObjectName JavaDoc name, QueryExp JavaDoc query) throws IOException JavaDoc
343    {
344       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(query);
345       final ClassLoader JavaDoc current = activateDefaultClassLoader();
346
347       try
348       {
349          return connection.queryNames(name, args, subject);
350       }
351       finally
352       {
353          deActivateDefaultClassLoader(current);
354       }
355    }
356
357    /**
358     * Test whether an mbean is registered.
359     *
360     * @param name the object name of the mbean
361     * @return true when the mbean is registered, false otherwise
362     * @throws javax.management.RuntimeOperationsException
363     * wrapping an IllegalArgumentException for a
364     * null name
365     * @throws java.io.IOException for a communication problem during this operation
366     */

367    public boolean isRegistered(ObjectName JavaDoc name) throws IOException JavaDoc
368    {
369       final ClassLoader JavaDoc current = activateDefaultClassLoader();
370
371       try
372       {
373          return connection.isRegistered(name, subject);
374       }
375       finally
376       {
377          deActivateDefaultClassLoader(current);
378       }
379    }
380
381    /**
382     * Retrieve the number of mbeans registered in the server.
383     *
384     * @return true the number of registered mbeans
385     * @throws java.io.IOException for a communication problem during this operation
386     */

387    public Integer JavaDoc getMBeanCount() throws IOException JavaDoc
388    {
389       final ClassLoader JavaDoc current = activateDefaultClassLoader();
390
391       try
392       {
393          return connection.getMBeanCount(subject);
394       }
395       finally
396       {
397          deActivateDefaultClassLoader(current);
398       }
399    }
400
401    /**
402     * Retrieve a value from an MBean.
403     *
404     * @param name the object name of the mbean
405     * @param attribute the attribute name of the value to retrieve
406     * @return the value
407     * @throws javax.management.ReflectionException
408     * for an exception invoking the mbean
409     * @throws javax.management.MBeanException
410     * for any exception thrown by the mbean
411     * @throws javax.management.InstanceNotFoundException
412     * if the mbean is not registered
413     * @throws javax.management.AttributeNotFoundException
414     * if the mbean has no such attribute
415     * @throws javax.management.RuntimeOperationsException
416     * wrapping an IllegalArgumentException for a
417     * null name or attribute
418     * @throws java.io.IOException for a communication problem during this operation
419     */

420    public Object JavaDoc getAttribute(ObjectName JavaDoc name, String JavaDoc attribute)
421          throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc
422    {
423       final ClassLoader JavaDoc current = activateDefaultClassLoader();
424
425       try
426       {
427          return connection.getAttribute(name, attribute, subject);
428       }
429       finally
430       {
431          deActivateDefaultClassLoader(current);
432       }
433    }
434
435    /**
436     * Retrieve a list of values from an MBean.
437     *
438     * @param name the object name of the mbean
439     * @param attributes the attribute names of the values to retrieve
440     * @return the list of values, attributes with errors are ignored
441     * @throws javax.management.ReflectionException
442     * for an exception invoking the mbean
443     * @throws javax.management.InstanceNotFoundException
444     * if the mbean is not registered
445     * @throws javax.management.RuntimeOperationsException
446     * wrapping an IllegalArgumentException for a
447     * null name or attributes
448     * @throws java.io.IOException for a communication problem during this operation
449     */

450    public AttributeList JavaDoc getAttributes(ObjectName JavaDoc name, String JavaDoc[] attributes)
451          throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc
452    {
453       final ClassLoader JavaDoc current = activateDefaultClassLoader();
454
455       try
456       {
457          return connection.getAttributes(name, attributes, subject);
458       }
459       finally
460       {
461          deActivateDefaultClassLoader(current);
462       }
463    }
464
465    /**
466     * Set a value for an MBean.
467     *
468     * @param name the object name of the mbean
469     * @param attribute the attribute name and value to set
470     * @throws javax.management.ReflectionException
471     * for an exception invoking the mbean
472     * @throws javax.management.MBeanException
473     * for any exception thrown by the mbean
474     * @throws javax.management.InstanceNotFoundException
475     * if the mbean is not registered
476     * @throws javax.management.AttributeNotFoundException
477     * if the mbean has no such attribute
478     * @throws javax.management.InvalidAttributeValueException
479     * if the new value has an incorrect type
480     * @throws javax.management.RuntimeOperationsException
481     * wrapping an IllegalArgumentException for a
482     * null name or attribute
483     * @throws java.io.IOException for a communication problem during this operation
484     */

485    public void setAttribute(ObjectName JavaDoc name, Attribute JavaDoc attribute)
486          throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc,
487                 InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc
488    {
489       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(attribute);
490       final ClassLoader JavaDoc current = activateDefaultClassLoader();
491
492       try
493       {
494          connection.setAttribute(name, args, subject);
495       }
496       finally
497       {
498          deActivateDefaultClassLoader(current);
499       }
500    }
501
502    /**
503     * Set a list of values for an MBean.
504     *
505     * @param name the object name of the mbean
506     * @param attributes the attribute names and values to set
507     * @return the list of values, attributes with errors are ignored
508     * @throws javax.management.ReflectionException
509     * for an exception invoking the mbean
510     * @throws javax.management.InstanceNotFoundException
511     * if the mbean is not registered
512     * @throws javax.management.RuntimeOperationsException
513     * wrapping an IllegalArgumentException for a
514     * null name or attributes
515     * @throws java.io.IOException for a communication problem during this operation
516     */

517    public AttributeList JavaDoc setAttributes(ObjectName JavaDoc name, AttributeList JavaDoc attributes)
518          throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc
519    {
520       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(attributes);
521       final ClassLoader JavaDoc current = activateDefaultClassLoader();
522
523       try
524       {
525          return connection.setAttributes(name, args, subject);
526       }
527       finally
528       {
529          deActivateDefaultClassLoader(current);
530       }
531
532    }
533
534    /**
535     * Invokes an operation on an mbean.
536     *
537     * @param name the object name of the mbean
538     * @param operationName the operation to perform
539     * @param params the parameters
540     * @param signature the signature of the operation
541     * @return any result of the operation
542     * @throws javax.management.ReflectionException
543     * for an exception invoking the mbean
544     * @throws javax.management.MBeanException
545     * for any exception thrown by the mbean
546     * @throws javax.management.InstanceNotFoundException
547     * if the mbean is not registered
548     * @throws java.io.IOException for a communication problem during this operation
549     */

550    public Object JavaDoc invoke(ObjectName JavaDoc name, String JavaDoc operationName, Object JavaDoc[] params, String JavaDoc[] signature)
551          throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc
552    {
553       MarshalledObject JavaDoc args = new MarshalledObject JavaDoc(params);
554       final ClassLoader JavaDoc current = activateDefaultClassLoader();
555
556       try
557       {
558          return connection.invoke(name, operationName, args, signature, subject);
559       }
560       finally
561       {
562          deActivateDefaultClassLoader(current);
563       }
564
565    }
566
567    /**
568     * Retrieve the default domain of the mbeanserver.
569     *
570     * @return the default domain
571     * @throws java.io.IOException for a communication problem during this operation
572     */

573    public String JavaDoc getDefaultDomain() throws IOException JavaDoc
574    {
575       final ClassLoader JavaDoc current = activateDefaultClassLoader();
576
577       try
578       {
579          return connection.getDefaultDomain(subject);
580       }
581       finally
582       {
583          deActivateDefaultClassLoader(current);
584       }
585    }
586
587    /**
588     * Retrieve the domains of the mbeanserver.
589     *
590     * @return the domains
591     * @throws java.io.IOException for a communication problem during this operation
592     */

593    public String JavaDoc[] getDomains() throws IOException JavaDoc
594    {
595       final ClassLoader JavaDoc current = activateDefaultClassLoader();
596
597       try
598       {
599          return connection.getDomains(subject);
600       }
601       finally
602       {
603          deActivateDefaultClassLoader(current);
604       }
605    }
606
607    /**
608     * Add a notification listener to an MBean.
609     *
610     * @param name the name of the MBean broadcasting notifications
611     * @param listener the listener to add
612     * @param filter a filter to preprocess notifications
613     * @param handback a object to add to any notifications
614     * @throws javax.management.InstanceNotFoundException
615     * if the broadcaster is not registered
616     * @throws java.io.IOException for a communication problem during this operation
617     */

618    public void addNotificationListener(ObjectName JavaDoc name, NotificationListener JavaDoc listener,
619                                        NotificationFilter JavaDoc filter, Object JavaDoc handback)
620          throws InstanceNotFoundException JavaDoc, IOException JavaDoc
621    {
622       ClientListenerHolder holder = new ClientListenerHolder(name, listener, filter, handback);
623       // if this listener already exists within the ClientNotifier, then assume has already been
624
// properly registered as a listener and can ignore call
625
if(clientNotifier.exists(holder))
626       {
627          return;
628       }
629       else
630       {
631          MarshalledObject JavaDoc marshalledFilter = null;
632
633          if(filter != null)
634          {
635             try
636             {
637                marshalledFilter = new MarshalledObject JavaDoc(filter);
638             }
639             catch(IOException JavaDoc e)
640             {
641                holder.setFilterOnClient(true);
642             }
643          }
644
645          Integer JavaDoc[] listenerIDs = connection.addNotificationListeners(new ObjectName JavaDoc[] {name}, new MarshalledObject JavaDoc[]{marshalledFilter},
646                                                                     new Subject JavaDoc[]{subject});
647           clientNotifier.addNotificationListener(listenerIDs[0], holder);
648       }
649
650    }
651
652    /**
653     * Add a notification listener to an MBean.
654     *
655     * @param name the name of the MBean broadcasting notifications
656     * @param listener the object name listener to add
657     * @param filter a filter to preprocess notifications
658     * @param handback a object to add to any notifications
659     * @throws javax.management.InstanceNotFoundException
660     * if the broadcaster or listener is not registered
661     * @throws javax.management.RuntimeOperationsException
662     * wrapping an IllegalArgumentException for a
663     * null listener or the listener does not implement the Notification Listener interface
664     * @throws java.io.IOException for a communication problem during this operation
665     */

666    public void addNotificationListener(ObjectName JavaDoc name, ObjectName JavaDoc listener,
667                                        NotificationFilter JavaDoc filter, Object JavaDoc handback)
668          throws InstanceNotFoundException JavaDoc, IOException JavaDoc
669    {
670       MarshalledObject JavaDoc marshalledFilter = filter != null ? new MarshalledObject JavaDoc(filter) : null;
671       MarshalledObject JavaDoc marshalledHandback = handback != null ? new MarshalledObject JavaDoc(handback) : null;
672       connection.addNotificationListener(name, listener, marshalledFilter, marshalledHandback, subject);
673    }
674
675    /**
676     * Removes a listener from an mbean.<p>
677     * <p/>
678     * All registrations of the listener are removed.
679     *
680     * @param name the name of the MBean broadcasting notifications
681     * @param listener the object name of the listener to remove
682     * @throws javax.management.InstanceNotFoundException
683     * if the broadcaster or listener is not registered
684     * @throws javax.management.ListenerNotFoundException
685     * if the listener is not registered against the broadcaster
686     * @throws java.io.IOException for a communication problem during this operation
687     */

688    public void removeNotificationListener(ObjectName JavaDoc name, ObjectName JavaDoc listener)
689          throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc, IOException JavaDoc
690    {
691       connection.removeNotificationListener(name, listener, subject);
692    }
693
694    /**
695     * Removes a listener from an mbean.<p>
696     * <p/>
697     * Only the listener that was registered with the same filter and handback is removed.
698     *
699     * @param name the name of the MBean broadcasting notifications
700     * @param listener the object name of listener to remove
701     * @param filter the filter of the listener to remove
702     * @throws javax.management.InstanceNotFoundException
703     * if the broadcaster or listener is not registered
704     * @throws javax.management.ListenerNotFoundException
705     * if the listener, filter, handback
706     * is not registered against the broadcaster
707     * @throws java.io.IOException for a communication problem during this operation
708     */

709    public void removeNotificationListener(ObjectName JavaDoc name, ObjectName JavaDoc listener,
710                                           NotificationFilter JavaDoc filter, Object JavaDoc handback)
711          throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc, IOException JavaDoc
712    {
713       MarshalledObject JavaDoc marshalledFilter = filter != null ? new MarshalledObject JavaDoc(filter) : null;
714       MarshalledObject JavaDoc marshalledHandback = handback != null ? new MarshalledObject JavaDoc(handback) : null;
715       connection.removeNotificationListener(name, listener, marshalledFilter, marshalledHandback, subject);
716    }
717
718    /**
719     * Removes a listener from an mbean.<p>
720     * <p/>
721     * All registrations of the listener are removed.
722     *
723     * @param name the name of the MBean broadcasting notifications
724     * @param listener the listener to remove
725     * @throws javax.management.InstanceNotFoundException
726     * if the broadcaster is not registered
727     * @throws javax.management.ListenerNotFoundException
728     * if the listener is not registered against the broadcaster
729     * @throws java.io.IOException for a communication problem during this operation
730     */

731    public void removeNotificationListener(ObjectName JavaDoc name, NotificationListener JavaDoc listener)
732          throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc, IOException JavaDoc
733    {
734       Integer JavaDoc[] ids = clientNotifier.getListeners(name, listener);
735       if(ids == null || ids.length == 0)
736       {
737          throw new ListenerNotFoundException JavaDoc("Listener (" + listener + ") not found as a registered listener.");
738       }
739       connection.removeNotificationListeners(name, ids, subject);
740       clientNotifier.removeListeners(ids);
741    }
742
743    /**
744     * Removes a listener from an mbean.<p>
745     * <p/>
746     * Only the listener that was registered with the same filter and handback is removed.
747     *
748     * @param name the name of the MBean broadcasting notifications
749     * @param listener the listener to remove
750     * @param filter the filter of the listener to remove
751     * @throws javax.management.InstanceNotFoundException
752     * if the broadcaster is not registered
753     * @throws javax.management.ListenerNotFoundException
754     * if the listener, filter, handback
755     * is not registered against the broadcaster
756     * @throws java.io.IOException for a communication problem during this operation
757     */

758    public void removeNotificationListener(ObjectName JavaDoc name, NotificationListener JavaDoc listener,
759                                           NotificationFilter JavaDoc filter, Object JavaDoc handback)
760          throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc, IOException JavaDoc
761    {
762       Integer JavaDoc id = clientNotifier.getListener(new ClientListenerHolder(name, listener, filter, handback));
763       if(id == null)
764       {
765          throw new ListenerNotFoundException JavaDoc("Listener (" + listener + ") could not be found as registered listener.");
766       }
767
768       Integer JavaDoc[] ids = new Integer JavaDoc[]{id};
769       connection.removeNotificationListeners(name, ids, subject);
770       clientNotifier.removeListeners(ids);
771    }
772
773    /**
774     * Retrieves the jmx metadata for an mbean
775     *
776     * @param name the name of the mbean
777     * @return the metadata
778     * @throws javax.management.IntrospectionException
779     * for any error during instrospection
780     * @throws javax.management.InstanceNotFoundException
781     * if the mbean is not registered
782     * @throws javax.management.ReflectionException
783     * for any error trying to invoke the operation on the mbean
784     * @throws java.io.IOException for a communication problem during this operation
785     */

786    public MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc name) throws InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc
787    {
788       final ClassLoader JavaDoc current = activateDefaultClassLoader();
789
790       try
791       {
792          return connection.getMBeanInfo(name, subject);
793       }
794       finally
795       {
796          deActivateDefaultClassLoader(current);
797       }
798
799    }
800
801    /**
802     * Tests whether an mbean can be cast to the given type
803     *
804     * @param name the name of the mbean
805     * @param className the class name to check
806     * @return true when it is of that type, false otherwise
807     * @throws javax.management.InstanceNotFoundException
808     * if the mbean is not registered
809     * @throws java.io.IOException for a communication problem during this operation
810     */

811    public boolean isInstanceOf(ObjectName JavaDoc name, String JavaDoc className) throws InstanceNotFoundException JavaDoc, IOException JavaDoc
812    {
813       final ClassLoader JavaDoc current = activateDefaultClassLoader();
814
815       try
816       {
817          return connection.isInstanceOf(name, className, subject);
818       }
819       finally
820       {
821          deActivateDefaultClassLoader(current);
822       }
823    }
824 }
Popular Tags