27 |
27 |
28 |
28 |
29 // java import |
29 // java import |
30 import java.io.IOException; |
30 import java.io.IOException; |
31 import java.util.Set; |
31 import java.util.Set; |
32 import javax.management.event.NotificationManager; |
|
33 |
32 |
34 |
33 |
35 /** |
34 /** |
36 * This interface represents a way to talk to an MBean server, whether |
35 * This interface represents a way to talk to an MBean server, whether |
37 * local or remote. The {@link MBeanServer} interface, representing a |
36 * local or remote. The {@link MBeanServer} interface, representing a |
38 * local MBean server, extends this interface. |
37 * local MBean server, extends this interface. |
39 * |
38 * |
40 * |
39 * |
41 * @since 1.5 |
40 * @since 1.5 |
42 */ |
41 */ |
43 public interface MBeanServerConnection extends NotificationManager { |
42 public interface MBeanServerConnection { |
44 /** |
43 /** |
45 * <p>Instantiates and registers an MBean in the MBean server. The |
44 * <p>Instantiates and registers an MBean in the MBean server. The |
46 * MBean server will use its {@link |
45 * MBean server will use its {@link |
47 * javax.management.loading.ClassLoaderRepository Default Loader |
46 * javax.management.loading.ClassLoaderRepository Default Loader |
48 * Repository} to load the class of the MBean. An object name is |
47 * Repository} to load the class of the MBean. An object name is |
49 * associated with the MBean. If the object name given is null, the |
48 * associated with the MBean. If the object name given is null, the |
50 * MBean must provide its own name in one or both of two ways: by implementing the {@link |
49 * MBean must provide its own name by implementing the {@link |
51 * javax.management.MBeanRegistration MBeanRegistration} interface |
50 * javax.management.MBeanRegistration MBeanRegistration} interface |
52 * and returning the name from the {@link |
51 * and returning the name from the {@link |
53 * MBeanRegistration#preRegister preRegister} method; or by defining |
52 * MBeanRegistration#preRegister preRegister} method.</p> |
54 * an {@code objectNameTemplate} field in its {@link Descriptor}, |
|
55 * typically using the {@link ObjectNameTemplate @ObjectNameTemplate} |
|
56 * annotation.</p> |
|
57 * |
53 * |
58 * <p>This method is equivalent to {@link |
54 * <p>This method is equivalent to {@link |
59 * #createMBean(String,ObjectName,Object[],String[]) |
55 * #createMBean(String,ObjectName,Object[],String[]) |
60 * createMBean(className, name, (Object[]) null, (String[]) |
56 * createMBean(className, name, (Object[]) null, (String[]) |
61 * null)}.</p> |
57 * null)}.</p> |
120 /** |
116 /** |
121 * <p>Instantiates and registers an MBean in the MBean server. The |
117 * <p>Instantiates and registers an MBean in the MBean server. The |
122 * class loader to be used is identified by its object name. An |
118 * class loader to be used is identified by its object name. An |
123 * object name is associated with the MBean. If the object name of |
119 * object name is associated with the MBean. If the object name of |
124 * the loader is null, the ClassLoader that loaded the MBean |
120 * the loader is null, the ClassLoader that loaded the MBean |
125 * server will be used. If the object name given is null, the |
121 * server will be used. If the MBean's object name given is null, |
126 * MBean must provide its own name in one or both of two ways: by implementing the {@link |
122 * the MBean must provide its own name by implementing the {@link |
127 * javax.management.MBeanRegistration MBeanRegistration} interface |
123 * javax.management.MBeanRegistration MBeanRegistration} interface |
128 * and returning the name from the {@link |
124 * and returning the name from the {@link |
129 * MBeanRegistration#preRegister preRegister} method; or by defining |
125 * MBeanRegistration#preRegister preRegister} method.</p> |
130 * an {@code objectNameTemplate} field in its {@link Descriptor}, |
|
131 * typically using the {@link ObjectNameTemplate @ObjectNameTemplate} |
|
132 * annotation.</p> |
|
133 * |
126 * |
134 * <p>This method is equivalent to {@link |
127 * <p>This method is equivalent to {@link |
135 * #createMBean(String,ObjectName,ObjectName,Object[],String[]) |
128 * #createMBean(String,ObjectName,ObjectName,Object[],String[]) |
136 * createMBean(className, name, loaderName, (Object[]) null, |
129 * createMBean(className, name, loaderName, (Object[]) null, |
137 * (String[]) null)}.</p> |
130 * (String[]) null)}.</p> |
203 * Instantiates and registers an MBean in the MBean server. The |
196 * Instantiates and registers an MBean in the MBean server. The |
204 * MBean server will use its {@link |
197 * MBean server will use its {@link |
205 * javax.management.loading.ClassLoaderRepository Default Loader |
198 * javax.management.loading.ClassLoaderRepository Default Loader |
206 * Repository} to load the class of the MBean. An object name is |
199 * Repository} to load the class of the MBean. An object name is |
207 * associated with the MBean. If the object name given is null, the |
200 * associated with the MBean. If the object name given is null, the |
208 * MBean must provide its own name in one or both of two ways: by implementing the {@link |
201 * MBean must provide its own name by implementing the {@link |
209 * javax.management.MBeanRegistration MBeanRegistration} interface |
202 * javax.management.MBeanRegistration MBeanRegistration} interface |
210 * and returning the name from the {@link |
203 * and returning the name from the {@link |
211 * MBeanRegistration#preRegister preRegister} method; or by defining |
204 * MBeanRegistration#preRegister preRegister} method. |
212 * an {@code objectNameTemplate} field in its {@link Descriptor}, |
|
213 * typically using the {@link ObjectNameTemplate @ObjectNameTemplate} |
|
214 * annotation.</p> |
|
215 * |
205 * |
216 * @param className The class name of the MBean to be instantiated. |
206 * @param className The class name of the MBean to be instantiated. |
217 * @param name The object name of the MBean. May be null. |
207 * @param name The object name of the MBean. May be null. |
218 * @param params An array containing the parameters of the |
208 * @param params An array containing the parameters of the |
219 * constructor to be invoked. |
209 * constructor to be invoked. |
278 /** |
268 /** |
279 * <p>Instantiates and registers an MBean in the MBean server. The |
269 * <p>Instantiates and registers an MBean in the MBean server. The |
280 * class loader to be used is identified by its object name. An |
270 * class loader to be used is identified by its object name. An |
281 * object name is associated with the MBean. If the object name of |
271 * object name is associated with the MBean. If the object name of |
282 * the loader is not specified, the ClassLoader that loaded the |
272 * the loader is not specified, the ClassLoader that loaded the |
283 * MBean server will be used. If the object name given is null, the |
273 * MBean server will be used. If the MBean object name given is |
284 * MBean must provide its own name in one or both of two ways: by implementing the {@link |
274 * null, the MBean must provide its own name by implementing the |
285 * javax.management.MBeanRegistration MBeanRegistration} interface |
275 * {@link javax.management.MBeanRegistration MBeanRegistration} |
286 * and returning the name from the {@link |
276 * interface and returning the name from the {@link |
287 * MBeanRegistration#preRegister preRegister} method; or by defining |
277 * MBeanRegistration#preRegister preRegister} method. |
288 * an {@code objectNameTemplate} field in its {@link Descriptor}, |
|
289 * typically using the {@link ObjectNameTemplate @ObjectNameTemplate} |
|
290 * annotation.</p> |
|
291 * |
278 * |
292 * @param className The class name of the MBean to be instantiated. |
279 * @param className The class name of the MBean to be instantiated. |
293 * @param name The object name of the MBean. May be null. |
280 * @param name The object name of the MBean. May be null. |
294 * @param params An array containing the parameters of the |
281 * @param params An array containing the parameters of the |
295 * constructor to be invoked. |
282 * constructor to be invoked. |
434 * @param name The object name pattern identifying the MBeans to |
421 * @param name The object name pattern identifying the MBeans to |
435 * be retrieved. If null or no domain and key properties are |
422 * be retrieved. If null or no domain and key properties are |
436 * specified, all the MBeans registered will be retrieved. |
423 * specified, all the MBeans registered will be retrieved. |
437 * @param query The query expression to be applied for selecting |
424 * @param query The query expression to be applied for selecting |
438 * MBeans. If null no query expression will be applied for |
425 * MBeans. If null no query expression will be applied for |
439 * selecting MBeans. ObjectName patterns that may be contained in the |
426 * selecting MBeans. |
440 * query expression will be |
|
441 * <a href="namespace/package-summary.html#NamespaceAndQueries"><!-- |
|
442 * -->evaluated</a> in the context of the |
|
443 * {@link javax.management.namespace namespace} |
|
444 * in which the MBeans selected by {@code name} are registered. |
|
445 * Thus, in the {@code query} parameter, no ObjectName pattern containing a |
|
446 * namespace path can match any of the MBean names selected by {@code name}. |
|
447 * See the |
|
448 * <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!-- |
|
449 * -->namespaces documentation</a> for more details. |
|
450 * |
427 * |
451 * @return A set containing the <CODE>ObjectInstance</CODE> |
428 * @return A set containing the <CODE>ObjectInstance</CODE> |
452 * objects for the selected MBeans. If no MBean satisfies the |
429 * objects for the selected MBeans. If no MBean satisfies the |
453 * query an empty list is returned. |
430 * query an empty list is returned. |
454 * |
431 * |
455 * @exception IOException A communication problem occurred when |
432 * @exception IOException A communication problem occurred when |
456 * talking to the MBean server. |
433 * talking to the MBean server. |
457 * @exception RuntimeOperationsException Wraps a |
|
458 * <CODE>java.lang.IllegalArgumentException</CODE>: The <em>name</em> |
|
459 * parameter contains an invalid pattern. See the |
|
460 * <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!-- |
|
461 * -->namespaces documentation</a> for more details. |
|
462 */ |
434 */ |
463 public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) |
435 public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) |
464 throws IOException; |
436 throws IOException; |
465 |
437 |
466 /** |
438 /** |
477 * @param name The object name pattern identifying the MBean names |
449 * @param name The object name pattern identifying the MBean names |
478 * to be retrieved. If null or no domain and key properties are |
450 * to be retrieved. If null or no domain and key properties are |
479 * specified, the name of all registered MBeans will be retrieved. |
451 * specified, the name of all registered MBeans will be retrieved. |
480 * @param query The query expression to be applied for selecting |
452 * @param query The query expression to be applied for selecting |
481 * MBeans. If null no query expression will be applied for |
453 * MBeans. If null no query expression will be applied for |
482 * selecting MBeans. ObjectName patterns that may be contained in the |
454 * selecting MBeans. |
483 * query expression will be |
|
484 * <a href="namespace/package-summary.html#NamespaceAndQueries"><!-- |
|
485 * -->evaluated</a> in the context of the |
|
486 * {@link javax.management.namespace namespace} |
|
487 * in which the MBeans slected by {@code name} are registered. |
|
488 * Thus, in the {@code query} parameter, no ObjectName pattern containing a |
|
489 * namespace path can match any of the MBean names selected by {@code name}. |
|
490 * See the |
|
491 * <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!-- |
|
492 * -->namespaces documentation</a> for more details. |
|
493 * |
455 * |
494 * @return A set containing the ObjectNames for the MBeans |
456 * @return A set containing the ObjectNames for the MBeans |
495 * selected. If no MBean satisfies the query, an empty list is |
457 * selected. If no MBean satisfies the query, an empty list is |
496 * returned. |
458 * returned. |
497 * |
459 * |
498 * @exception IOException A communication problem occurred when |
460 * @exception IOException A communication problem occurred when |
499 * talking to the MBean server. |
461 * talking to the MBean server. |
500 * @exception RuntimeOperationsException Wraps a |
|
501 * <CODE>java.lang.IllegalArgumentException</CODE>: The <em>name</em> |
|
502 * parameter contains an invalid pattern. See the |
|
503 * <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!-- |
|
504 * -->namespaces documentation</a> for more details. |
|
505 */ |
462 */ |
506 public Set<ObjectName> queryNames(ObjectName name, QueryExp query) |
463 public Set<ObjectName> queryNames(ObjectName name, QueryExp query) |
507 throws IOException; |
464 throws IOException; |
508 |
465 |
509 |
466 |
592 * if (list.size() == attrNames.length) |
549 * if (list.size() == attrNames.length) |
593 * System.out.println("All attributes were retrieved successfully"); |
550 * System.out.println("All attributes were retrieved successfully"); |
594 * else { |
551 * else { |
595 * {@code List<String>} missing = new {@code ArrayList<String>}(<!-- |
552 * {@code List<String>} missing = new {@code ArrayList<String>}(<!-- |
596 * -->{@link java.util.Arrays#asList Arrays.asList}(attrNames)); |
553 * -->{@link java.util.Arrays#asList Arrays.asList}(attrNames)); |
597 * missing.removeAll(list.toMap().keySet()); |
554 * for (Attribute a : list.asList()) |
|
555 * missing.remove(a.getName()); |
598 * System.out.println("Did not retrieve: " + missing); |
556 * System.out.println("Did not retrieve: " + missing); |
599 * } |
557 * } |
600 * </pre> |
558 * </pre> |
601 * |
559 * |
602 * @param name The object name of the MBean from which the |
560 * @param name The object name of the MBean from which the |
679 * AttributeList outputAttrs = mbeanServerConnection.setAttributes(<!-- |
637 * AttributeList outputAttrs = mbeanServerConnection.setAttributes(<!-- |
680 * -->objectName, inputAttrs); |
638 * -->objectName, inputAttrs); |
681 * if (inputAttrs.size() == outputAttrs.size()) |
639 * if (inputAttrs.size() == outputAttrs.size()) |
682 * System.out.println("All attributes were set successfully"); |
640 * System.out.println("All attributes were set successfully"); |
683 * else { |
641 * else { |
684 * {@code List<String>} missing = new {@code ArrayList<String>}(<!-- |
642 * {@code List<String>} missing = new {@code ArrayList<String>}(); |
685 * -->inputAttrs.toMap().keySet()); |
643 * for (Attribute a : inputAttrs.asList()) |
686 * missing.removeAll(outputAttrs.toMap().keySet()); |
644 * missing.add(a.getName()); |
|
645 * for (Attribute a : outputAttrs.asList()) |
|
646 * missing.remove(a.getName()); |
687 * System.out.println("Did not set: " + missing); |
647 * System.out.println("Did not set: " + missing); |
688 * } |
648 * } |
689 * </pre> |
649 * </pre> |
690 * |
650 * |
691 * @param name The object name of the MBean within which the |
651 * @param name The object name of the MBean within which the |
807 * |
767 * |
808 */ |
768 */ |
809 public String[] getDomains() |
769 public String[] getDomains() |
810 throws IOException; |
770 throws IOException; |
811 |
771 |
812 // doc inherited from NotificationManager |
772 /** |
|
773 * <p>Adds a listener to a registered MBean. |
|
774 * Notifications emitted by the MBean will be forwarded to the listener.</p> |
|
775 * |
|
776 * @param name The name of the MBean on which the listener should |
|
777 * be added. |
|
778 * @param listener The listener object which will handle the |
|
779 * notifications emitted by the registered MBean. |
|
780 * @param filter The filter object. If filter is null, no |
|
781 * filtering will be performed before handling notifications. |
|
782 * @param handback The context to be sent to the listener when a |
|
783 * notification is emitted. |
|
784 * |
|
785 * @exception InstanceNotFoundException The MBean name provided |
|
786 * does not match any of the registered MBeans. |
|
787 * @exception IOException A communication problem occurred when |
|
788 * talking to the MBean server. |
|
789 * |
|
790 * @see #removeNotificationListener(ObjectName, NotificationListener) |
|
791 * @see #removeNotificationListener(ObjectName, NotificationListener, |
|
792 * NotificationFilter, Object) |
|
793 */ |
813 public void addNotificationListener(ObjectName name, |
794 public void addNotificationListener(ObjectName name, |
814 NotificationListener listener, |
795 NotificationListener listener, |
815 NotificationFilter filter, |
796 NotificationFilter filter, |
816 Object handback) |
797 Object handback) |
817 throws InstanceNotFoundException, IOException; |
798 throws InstanceNotFoundException, IOException; |
924 NotificationFilter filter, |
905 NotificationFilter filter, |
925 Object handback) |
906 Object handback) |
926 throws InstanceNotFoundException, ListenerNotFoundException, |
907 throws InstanceNotFoundException, ListenerNotFoundException, |
927 IOException; |
908 IOException; |
928 |
909 |
929 // doc inherited from NotificationManager |
910 |
|
911 /** |
|
912 * <p>Removes a listener from a registered MBean.</p> |
|
913 * |
|
914 * <P> If the listener is registered more than once, perhaps with |
|
915 * different filters or callbacks, this method will remove all |
|
916 * those registrations. |
|
917 * |
|
918 * @param name The name of the MBean on which the listener should |
|
919 * be removed. |
|
920 * @param listener The listener to be removed. |
|
921 * |
|
922 * @exception InstanceNotFoundException The MBean name provided |
|
923 * does not match any of the registered MBeans. |
|
924 * @exception ListenerNotFoundException The listener is not |
|
925 * registered in the MBean. |
|
926 * @exception IOException A communication problem occurred when |
|
927 * talking to the MBean server. |
|
928 * |
|
929 * @see #addNotificationListener(ObjectName, NotificationListener, |
|
930 * NotificationFilter, Object) |
|
931 */ |
930 public void removeNotificationListener(ObjectName name, |
932 public void removeNotificationListener(ObjectName name, |
931 NotificationListener listener) |
933 NotificationListener listener) |
932 throws InstanceNotFoundException, ListenerNotFoundException, |
934 throws InstanceNotFoundException, ListenerNotFoundException, |
933 IOException; |
935 IOException; |
934 |
936 |
935 // doc inherited from NotificationManager |
937 /** |
|
938 * <p>Removes a listener from a registered MBean.</p> |
|
939 * |
|
940 * <p>The MBean must have a listener that exactly matches the |
|
941 * given <code>listener</code>, <code>filter</code>, and |
|
942 * <code>handback</code> parameters. If there is more than one |
|
943 * such listener, only one is removed.</p> |
|
944 * |
|
945 * <p>The <code>filter</code> and <code>handback</code> parameters |
|
946 * may be null if and only if they are null in a listener to be |
|
947 * removed.</p> |
|
948 * |
|
949 * @param name The name of the MBean on which the listener should |
|
950 * be removed. |
|
951 * @param listener The listener to be removed. |
|
952 * @param filter The filter that was specified when the listener |
|
953 * was added. |
|
954 * @param handback The handback that was specified when the |
|
955 * listener was added. |
|
956 * |
|
957 * @exception InstanceNotFoundException The MBean name provided |
|
958 * does not match any of the registered MBeans. |
|
959 * @exception ListenerNotFoundException The listener is not |
|
960 * registered in the MBean, or it is not registered with the given |
|
961 * filter and handback. |
|
962 * @exception IOException A communication problem occurred when |
|
963 * talking to the MBean server. |
|
964 * |
|
965 * @see #addNotificationListener(ObjectName, NotificationListener, |
|
966 * NotificationFilter, Object) |
|
967 * |
|
968 */ |
936 public void removeNotificationListener(ObjectName name, |
969 public void removeNotificationListener(ObjectName name, |
937 NotificationListener listener, |
970 NotificationListener listener, |
938 NotificationFilter filter, |
971 NotificationFilter filter, |
939 Object handback) |
972 Object handback) |
940 throws InstanceNotFoundException, ListenerNotFoundException, |
973 throws InstanceNotFoundException, ListenerNotFoundException, |
984 * <code>className</code>, and the second class is assignable from |
1017 * <code>className</code>, and the second class is assignable from |
985 * the first, the result is true.</p> |
1018 * the first, the result is true.</p> |
986 * |
1019 * |
987 * <p>Otherwise, the result is false.</p> |
1020 * <p>Otherwise, the result is false.</p> |
988 * |
1021 * |
989 * <p>If the MBean implements the {@link DynamicWrapperMBean} |
|
990 * interface, then in the above rules X is the result of the MBean's {@link |
|
991 * DynamicWrapperMBean#getWrappedObject() getWrappedObject()} method and L |
|
992 * is the result of its {@link DynamicWrapperMBean#getWrappedClassLoader() |
|
993 * getWrappedClassLoader()} method. |
|
994 * |
|
995 * @param name The <CODE>ObjectName</CODE> of the MBean. |
1022 * @param name The <CODE>ObjectName</CODE> of the MBean. |
996 * @param className The name of the class. |
1023 * @param className The name of the class. |
997 * |
1024 * |
998 * @return true if the MBean specified is an instance of the |
1025 * @return true if the MBean specified is an instance of the |
999 * specified class according to the rules above, false otherwise. |
1026 * specified class according to the rules above, false otherwise. |