author | rgoel |
Fri, 04 May 2018 15:44:24 +0530 | |
changeset 49983 | 41069c4fad29 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21656
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.management; |
|
27 |
||
28 |
||
29 |
/** |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
30 |
* Represents a notification emitted by the MBean Server through the MBeanServerDelegate MBean. |
2 | 31 |
* The MBean Server emits the following types of notifications: MBean registration, MBean |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
32 |
* unregistration. |
2 | 33 |
* <P> |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
34 |
* To receive MBeanServerNotifications, you need to register a listener with |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
35 |
* the {@link MBeanServerDelegate MBeanServerDelegate} MBean |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
36 |
* that represents the MBeanServer. The ObjectName of the MBeanServerDelegate is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
37 |
* {@link MBeanServerDelegate#DELEGATE_NAME}, which is |
2 | 38 |
* <CODE>JMImplementation:type=MBeanServerDelegate</CODE>. |
39 |
* |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
40 |
* <p>The following code prints a message every time an MBean is registered |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
41 |
* or unregistered in the MBean Server {@code mbeanServer}:</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
42 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
43 |
* <pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
44 |
* private static final NotificationListener printListener = new NotificationListener() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
45 |
* public void handleNotification(Notification n, Object handback) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
46 |
* if (!(n instanceof MBeanServerNotification)) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
47 |
* System.out.println("Ignored notification of class " + n.getClass().getName()); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
48 |
* return; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
49 |
* } |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
50 |
* MBeanServerNotification mbsn = (MBeanServerNotification) n; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
51 |
* String what; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
52 |
* if (n.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
53 |
* what = "MBean registered"; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
54 |
* else if (n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
55 |
* what = "MBean unregistered"; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
56 |
* else |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
57 |
* what = "Unknown type " + n.getType(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
58 |
* System.out.println("Received MBean Server notification: " + what + ": " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
59 |
* mbsn.getMBeanName()); |
1693
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
60 |
* } |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
61 |
* }; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
62 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
63 |
* ... |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
64 |
* mbeanServer.addNotificationListener( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
65 |
* MBeanServerDelegate.DELEGATE_NAME, printListener, null, null); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1247
diff
changeset
|
66 |
* </pre> |
4156 | 67 |
* |
1693
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
68 |
* <p id="group"> |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
69 |
* An MBean which is not an {@link MBeanServerDelegate} may also emit |
4156 | 70 |
* MBeanServerNotifications. In particular, there is a convention for |
71 |
* MBeans to emit an MBeanServerNotification for a group of MBeans.</p> |
|
72 |
* |
|
73 |
* <p>An MBeanServerNotification emitted to denote the registration or |
|
1693
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
74 |
* unregistration of a group of MBeans has the following characteristics: |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
75 |
* <ul><li>Its {@linkplain Notification#getType() notification type} is |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
76 |
* {@code "JMX.mbean.registered.group"} or |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
77 |
* {@code "JMX.mbean.unregistered.group"}, which can also be written {@link |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
78 |
* MBeanServerNotification#REGISTRATION_NOTIFICATION}{@code + ".group"} or |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
79 |
* {@link |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
80 |
* MBeanServerNotification#UNREGISTRATION_NOTIFICATION}{@code + ".group"}. |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
81 |
* </li> |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
82 |
* <li>Its {@linkplain #getMBeanName() MBean name} is an ObjectName pattern |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
83 |
* that selects the set (or a superset) of the MBeans being registered |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
84 |
* or unregistered</li> |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
85 |
* <li>Its {@linkplain Notification#getUserData() user data} can optionally |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
86 |
* be set to an array of ObjectNames containing the names of all MBeans |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
87 |
* being registered or unregistered.</li> |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
88 |
* </ul> |
21656
d4c777ccb1db
8028014: Doclint warning/error cleanup in javax.management
rriggs
parents:
5506
diff
changeset
|
89 |
* |
1693
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
90 |
* <p> |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
91 |
* MBeans which emit these group registration/unregistration notifications will |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
92 |
* declare them in their {@link MBeanInfo#getNotifications() |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
93 |
* MBeanNotificationInfo}. |
f99cde90680f
6319823: new mbean register/unregister notification for groups of mbeans
dfuchs
parents:
1571
diff
changeset
|
94 |
* </p> |
1571
421ef5172dd3
6336968: Methods to convert AttributeList to/from Map
emcmanus
parents:
1570
diff
changeset
|
95 |
* |
2 | 96 |
* @since 1.5 |
97 |
*/ |
|
1003 | 98 |
public class MBeanServerNotification extends Notification { |
2 | 99 |
|
100 |
||
1003 | 101 |
/* Serial version */ |
102 |
private static final long serialVersionUID = 2876477500475969677L; |
|
103 |
/** |
|
104 |
* Notification type denoting that an MBean has been registered. |
|
105 |
* Value is "JMX.mbean.registered". |
|
106 |
*/ |
|
107 |
public static final String REGISTRATION_NOTIFICATION = |
|
108 |
"JMX.mbean.registered"; |
|
109 |
/** |
|
110 |
* Notification type denoting that an MBean has been unregistered. |
|
111 |
* Value is "JMX.mbean.unregistered". |
|
112 |
*/ |
|
113 |
public static final String UNREGISTRATION_NOTIFICATION = |
|
114 |
"JMX.mbean.unregistered"; |
|
115 |
/** |
|
116 |
* @serial The object names of the MBeans concerned by this notification |
|
117 |
*/ |
|
118 |
private final ObjectName objectName; |
|
2 | 119 |
|
1003 | 120 |
/** |
121 |
* Creates an MBeanServerNotification object specifying object names of |
|
122 |
* the MBeans that caused the notification and the specified notification |
|
123 |
* type. |
|
124 |
* |
|
125 |
* @param type A string denoting the type of the |
|
126 |
* notification. Set it to one these values: {@link |
|
127 |
* #REGISTRATION_NOTIFICATION}, {@link |
|
128 |
* #UNREGISTRATION_NOTIFICATION}. |
|
129 |
* @param source The MBeanServerNotification object responsible |
|
130 |
* for forwarding MBean server notification. |
|
131 |
* @param sequenceNumber A sequence number that can be used to order |
|
132 |
* received notifications. |
|
133 |
* @param objectName The object name of the MBean that caused the |
|
134 |
* notification. |
|
135 |
* |
|
136 |
*/ |
|
137 |
public MBeanServerNotification(String type, Object source, |
|
138 |
long sequenceNumber, ObjectName objectName) { |
|
139 |
super(type, source, sequenceNumber); |
|
140 |
this.objectName = objectName; |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Returns the object name of the MBean that caused the notification. |
|
145 |
* |
|
146 |
* @return the object name of the MBean that caused the notification. |
|
147 |
*/ |
|
148 |
public ObjectName getMBeanName() { |
|
149 |
return objectName; |
|
150 |
} |
|
151 |
||
152 |
@Override |
|
153 |
public String toString() { |
|
154 |
return super.toString() + "[mbeanName=" + objectName + "]"; |
|
155 |
||
156 |
} |
|
2 | 157 |
|
158 |
} |