Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/management/MBeanServerDelegate.java
38829 views
1
/*
2
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package javax.management;
27
28
import com.sun.jmx.defaults.JmxProperties;
29
import com.sun.jmx.defaults.ServiceName;
30
import com.sun.jmx.mbeanserver.Util;
31
32
/**
33
* Represents the MBean server from the management point of view.
34
* The MBeanServerDelegate MBean emits the MBeanServerNotifications when
35
* an MBean is registered/unregistered in the MBean server.
36
*
37
* @since 1.5
38
*/
39
public class MBeanServerDelegate implements MBeanServerDelegateMBean,
40
NotificationEmitter {
41
42
/** The MBean server agent identification.*/
43
private String mbeanServerId ;
44
45
/** The NotificationBroadcasterSupport object that sends the
46
notifications */
47
private final NotificationBroadcasterSupport broadcaster;
48
49
private static long oldStamp = 0;
50
private final long stamp;
51
private long sequenceNumber = 1;
52
53
private static final MBeanNotificationInfo[] notifsInfo;
54
55
static {
56
final String[] types = {
57
MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
58
MBeanServerNotification.REGISTRATION_NOTIFICATION
59
};
60
notifsInfo = new MBeanNotificationInfo[1];
61
notifsInfo[0] =
62
new MBeanNotificationInfo(types,
63
"javax.management.MBeanServerNotification",
64
"Notifications sent by the MBeanServerDelegate MBean");
65
}
66
67
/**
68
* Create a MBeanServerDelegate object.
69
*/
70
public MBeanServerDelegate () {
71
stamp = getStamp();
72
broadcaster = new NotificationBroadcasterSupport() ;
73
}
74
75
76
/**
77
* Returns the MBean server agent identity.
78
*
79
* @return the identity.
80
*/
81
public synchronized String getMBeanServerId() {
82
if (mbeanServerId == null) {
83
String localHost;
84
try {
85
localHost = java.net.InetAddress.getLocalHost().getHostName();
86
} catch (java.net.UnknownHostException e) {
87
JmxProperties.MISC_LOGGER.finest("Can't get local host name, " +
88
"using \"localhost\" instead. Cause is: "+e);
89
localHost = "localhost";
90
}
91
mbeanServerId = localHost + "_" + stamp;
92
}
93
return mbeanServerId;
94
}
95
96
/**
97
* Returns the full name of the JMX specification implemented
98
* by this product.
99
*
100
* @return the specification name.
101
*/
102
public String getSpecificationName() {
103
return ServiceName.JMX_SPEC_NAME;
104
}
105
106
/**
107
* Returns the version of the JMX specification implemented
108
* by this product.
109
*
110
* @return the specification version.
111
*/
112
public String getSpecificationVersion() {
113
return ServiceName.JMX_SPEC_VERSION;
114
}
115
116
/**
117
* Returns the vendor of the JMX specification implemented
118
* by this product.
119
*
120
* @return the specification vendor.
121
*/
122
public String getSpecificationVendor() {
123
return ServiceName.JMX_SPEC_VENDOR;
124
}
125
126
/**
127
* Returns the JMX implementation name (the name of this product).
128
*
129
* @return the implementation name.
130
*/
131
public String getImplementationName() {
132
return ServiceName.JMX_IMPL_NAME;
133
}
134
135
/**
136
* Returns the JMX implementation version (the version of this product).
137
*
138
* @return the implementation version.
139
*/
140
public String getImplementationVersion() {
141
try {
142
return System.getProperty("java.runtime.version");
143
} catch (SecurityException e) {
144
return "";
145
}
146
}
147
148
/**
149
* Returns the JMX implementation vendor (the vendor of this product).
150
*
151
* @return the implementation vendor.
152
*/
153
public String getImplementationVendor() {
154
return ServiceName.JMX_IMPL_VENDOR;
155
}
156
157
// From NotificationEmitter extends NotificationBroacaster
158
//
159
public MBeanNotificationInfo[] getNotificationInfo() {
160
final int len = MBeanServerDelegate.notifsInfo.length;
161
final MBeanNotificationInfo[] infos =
162
new MBeanNotificationInfo[len];
163
System.arraycopy(MBeanServerDelegate.notifsInfo,0,infos,0,len);
164
return infos;
165
}
166
167
// From NotificationEmitter extends NotificationBroacaster
168
//
169
public synchronized
170
void addNotificationListener(NotificationListener listener,
171
NotificationFilter filter,
172
Object handback)
173
throws IllegalArgumentException {
174
broadcaster.addNotificationListener(listener,filter,handback) ;
175
}
176
177
// From NotificationEmitter extends NotificationBroacaster
178
//
179
public synchronized
180
void removeNotificationListener(NotificationListener listener,
181
NotificationFilter filter,
182
Object handback)
183
throws ListenerNotFoundException {
184
broadcaster.removeNotificationListener(listener,filter,handback) ;
185
}
186
187
// From NotificationEmitter extends NotificationBroacaster
188
//
189
public synchronized
190
void removeNotificationListener(NotificationListener listener)
191
throws ListenerNotFoundException {
192
broadcaster.removeNotificationListener(listener) ;
193
}
194
195
/**
196
* Enables the MBean server to send a notification.
197
* If the passed <var>notification</var> has a sequence number lesser
198
* or equal to 0, then replace it with the delegate's own sequence
199
* number.
200
* @param notification The notification to send.
201
*
202
*/
203
public void sendNotification(Notification notification) {
204
if (notification.getSequenceNumber() < 1) {
205
synchronized (this) {
206
notification.setSequenceNumber(this.sequenceNumber++);
207
}
208
}
209
broadcaster.sendNotification(notification);
210
}
211
212
/**
213
* Defines the default ObjectName of the MBeanServerDelegate.
214
*
215
* @since 1.6
216
*/
217
public static final ObjectName DELEGATE_NAME =
218
Util.newObjectName("JMImplementation:type=MBeanServerDelegate");
219
220
/* Return a timestamp that is monotonically increasing even if
221
System.currentTimeMillis() isn't (for example, if you call this
222
constructor more than once in the same millisecond, or if the
223
clock always returns the same value). This means that the ids
224
for a given JVM will always be distinact, though there is no
225
such guarantee for two different JVMs. */
226
private static synchronized long getStamp() {
227
long s = System.currentTimeMillis();
228
if (oldStamp >= s) {
229
s = oldStamp + 1;
230
}
231
oldStamp = s;
232
return s;
233
}
234
}
235
236