author | sjiang |
Fri, 17 Apr 2015 09:40:02 +0200 | |
changeset 30355 | e37c7eba132f |
parent 25859 | jdk/src/java.management/share/classes/sun/management/DiagnosticCommandImpl.java@3317bb8137f4 |
child 35281 | 0759290c119a |
permissions | -rw-r--r-- |
17954 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
17954 | 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 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
26 |
package com.sun.management.internal; |
17954 | 27 |
|
28 |
import com.sun.management.DiagnosticCommandMBean; |
|
29 |
import java.lang.reflect.Constructor; |
|
30 |
import java.lang.reflect.InvocationTargetException; |
|
31 |
import java.security.Permission; |
|
32 |
import java.util.*; |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
33 |
import javax.management.Attribute; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
34 |
import javax.management.AttributeList; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
35 |
import javax.management.AttributeNotFoundException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
36 |
import javax.management.Descriptor; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
37 |
import javax.management.ImmutableDescriptor; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
38 |
import javax.management.InvalidAttributeValueException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
39 |
import javax.management.ListenerNotFoundException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
40 |
import javax.management.MBeanException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
41 |
import javax.management.MBeanInfo; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
42 |
import javax.management.MBeanNotificationInfo; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
43 |
import javax.management.MBeanOperationInfo; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
44 |
import javax.management.MBeanParameterInfo; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
45 |
import javax.management.MalformedObjectNameException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
46 |
import javax.management.Notification; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
47 |
import javax.management.NotificationFilter; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
48 |
import javax.management.NotificationListener; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
49 |
import javax.management.ObjectName; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
50 |
import javax.management.ReflectionException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
51 |
import sun.management.ManagementFactoryHelper; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
52 |
import sun.management.NotificationEmitterSupport; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
53 |
import sun.management.VMManagement; |
17954 | 54 |
|
55 |
/** |
|
56 |
* Implementation class for the diagnostic commands subsystem. |
|
57 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
17954
diff
changeset
|
58 |
* @since 1.8 |
17954 | 59 |
*/ |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
60 |
public class DiagnosticCommandImpl extends NotificationEmitterSupport |
17954 | 61 |
implements DiagnosticCommandMBean { |
62 |
||
63 |
private final VMManagement jvm; |
|
64 |
private volatile Map<String, Wrapper> wrappers = null; |
|
65 |
private static final String strClassName = "".getClass().getName(); |
|
66 |
private static final String strArrayClassName = String[].class.getName(); |
|
67 |
private final boolean isSupported; |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
68 |
private static DiagnosticCommandImpl diagCommandMBean = null; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
69 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
70 |
static synchronized DiagnosticCommandMBean getDiagnosticCommandMBean() { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
71 |
VMManagement jvm = ManagementFactoryHelper.getVMManagement(); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
72 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
73 |
// Remote Diagnostic Commands may not be supported |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
74 |
if (diagCommandMBean == null && jvm.isRemoteDiagnosticCommandsSupported()) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
75 |
diagCommandMBean = new DiagnosticCommandImpl(jvm); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
76 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
77 |
return diagCommandMBean; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
78 |
} |
17954 | 79 |
|
80 |
@Override |
|
81 |
public Object getAttribute(String attribute) throws AttributeNotFoundException, |
|
82 |
MBeanException, ReflectionException { |
|
83 |
throw new AttributeNotFoundException(attribute); |
|
84 |
} |
|
85 |
||
86 |
@Override |
|
87 |
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, |
|
88 |
InvalidAttributeValueException, MBeanException, ReflectionException { |
|
89 |
throw new AttributeNotFoundException(attribute.getName()); |
|
90 |
} |
|
91 |
||
92 |
@Override |
|
93 |
public AttributeList getAttributes(String[] attributes) { |
|
94 |
return new AttributeList(); |
|
95 |
} |
|
96 |
||
97 |
@Override |
|
98 |
public AttributeList setAttributes(AttributeList attributes) { |
|
99 |
return new AttributeList(); |
|
100 |
} |
|
101 |
||
102 |
private class Wrapper { |
|
103 |
||
104 |
String name; |
|
105 |
String cmd; |
|
106 |
DiagnosticCommandInfo info; |
|
107 |
Permission permission; |
|
108 |
||
109 |
Wrapper(String name, String cmd, DiagnosticCommandInfo info) |
|
110 |
throws InstantiationException { |
|
111 |
this.name = name; |
|
112 |
this.cmd = cmd; |
|
113 |
this.info = info; |
|
114 |
this.permission = null; |
|
115 |
Exception cause = null; |
|
116 |
if (info.getPermissionClass() != null) { |
|
117 |
try { |
|
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
24865
diff
changeset
|
118 |
Class<?> c = Class.forName(info.getPermissionClass()); |
17954 | 119 |
if (info.getPermissionAction() == null) { |
120 |
try { |
|
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
24865
diff
changeset
|
121 |
Constructor<?> constructor = c.getConstructor(String.class); |
17954 | 122 |
permission = (Permission) constructor.newInstance(info.getPermissionName()); |
123 |
||
124 |
} catch (InstantiationException | IllegalAccessException |
|
125 |
| IllegalArgumentException | InvocationTargetException |
|
126 |
| NoSuchMethodException | SecurityException ex) { |
|
127 |
cause = ex; |
|
128 |
} |
|
129 |
} |
|
130 |
if (permission == null) { |
|
131 |
try { |
|
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
24865
diff
changeset
|
132 |
Constructor<?> constructor = c.getConstructor(String.class, String.class); |
17954 | 133 |
permission = (Permission) constructor.newInstance( |
134 |
info.getPermissionName(), |
|
135 |
info.getPermissionAction()); |
|
136 |
} catch (InstantiationException | IllegalAccessException |
|
137 |
| IllegalArgumentException | InvocationTargetException |
|
138 |
| NoSuchMethodException | SecurityException ex) { |
|
139 |
cause = ex; |
|
140 |
} |
|
141 |
} |
|
142 |
} catch (ClassNotFoundException ex) { } |
|
143 |
if (permission == null) { |
|
144 |
InstantiationException iex = |
|
145 |
new InstantiationException("Unable to instantiate required permission"); |
|
146 |
iex.initCause(cause); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
public String execute(String[] args) { |
|
152 |
if (permission != null) { |
|
153 |
SecurityManager sm = System.getSecurityManager(); |
|
154 |
if (sm != null) { |
|
155 |
sm.checkPermission(permission); |
|
156 |
} |
|
157 |
} |
|
158 |
if(args == null) { |
|
159 |
return executeDiagnosticCommand(cmd); |
|
160 |
} else { |
|
161 |
StringBuilder sb = new StringBuilder(); |
|
162 |
sb.append(cmd); |
|
163 |
for(int i=0; i<args.length; i++) { |
|
164 |
if(args[i] == null) { |
|
165 |
throw new IllegalArgumentException("Invalid null argument"); |
|
166 |
} |
|
167 |
sb.append(" "); |
|
168 |
sb.append(args[i]); |
|
169 |
} |
|
170 |
return executeDiagnosticCommand(sb.toString()); |
|
171 |
} |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
DiagnosticCommandImpl(VMManagement jvm) { |
|
176 |
this.jvm = jvm; |
|
177 |
isSupported = jvm.isRemoteDiagnosticCommandsSupported(); |
|
178 |
} |
|
179 |
||
180 |
private static class OperationInfoComparator implements Comparator<MBeanOperationInfo> { |
|
181 |
@Override |
|
182 |
public int compare(MBeanOperationInfo o1, MBeanOperationInfo o2) { |
|
183 |
return o1.getName().compareTo(o2.getName()); |
|
184 |
} |
|
185 |
} |
|
186 |
||
187 |
@Override |
|
188 |
public MBeanInfo getMBeanInfo() { |
|
189 |
SortedSet<MBeanOperationInfo> operations = new TreeSet<>(new OperationInfoComparator()); |
|
190 |
Map<String, Wrapper> wrappersmap; |
|
191 |
if (!isSupported) { |
|
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
24865
diff
changeset
|
192 |
wrappersmap = Collections.emptyMap(); |
17954 | 193 |
} else { |
194 |
try { |
|
195 |
String[] command = getDiagnosticCommands(); |
|
196 |
DiagnosticCommandInfo[] info = getDiagnosticCommandInfo(command); |
|
197 |
MBeanParameterInfo stringArgInfo[] = new MBeanParameterInfo[]{ |
|
198 |
new MBeanParameterInfo("arguments", strArrayClassName, |
|
199 |
"Array of Diagnostic Commands Arguments and Options") |
|
200 |
}; |
|
201 |
wrappersmap = new HashMap<>(); |
|
202 |
for (int i = 0; i < command.length; i++) { |
|
203 |
String name = transform(command[i]); |
|
204 |
try { |
|
205 |
Wrapper w = new Wrapper(name, command[i], info[i]); |
|
206 |
wrappersmap.put(name, w); |
|
207 |
operations.add(new MBeanOperationInfo( |
|
208 |
w.name, |
|
209 |
w.info.getDescription(), |
|
210 |
(w.info.getArgumentsInfo() == null |
|
211 |
|| w.info.getArgumentsInfo().isEmpty()) |
|
212 |
? null : stringArgInfo, |
|
213 |
strClassName, |
|
214 |
MBeanOperationInfo.ACTION_INFO, |
|
215 |
commandDescriptor(w))); |
|
216 |
} catch (InstantiationException ex) { |
|
217 |
// If for some reasons the creation of a diagnostic command |
|
218 |
// wrappers fails, the diagnostic command is just ignored |
|
219 |
// and won't appear in the DynamicMBean |
|
220 |
} |
|
221 |
} |
|
222 |
} catch (IllegalArgumentException | UnsupportedOperationException e) { |
|
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
24865
diff
changeset
|
223 |
wrappersmap = Collections.emptyMap(); |
17954 | 224 |
} |
225 |
} |
|
226 |
wrappers = Collections.unmodifiableMap(wrappersmap); |
|
227 |
HashMap<String, Object> map = new HashMap<>(); |
|
228 |
map.put("immutableInfo", "false"); |
|
229 |
map.put("interfaceClassName","com.sun.management.DiagnosticCommandMBean"); |
|
230 |
map.put("mxbean", "false"); |
|
231 |
Descriptor desc = new ImmutableDescriptor(map); |
|
232 |
return new MBeanInfo( |
|
233 |
this.getClass().getName(), |
|
234 |
"Diagnostic Commands", |
|
235 |
null, // attributes |
|
236 |
null, // constructors |
|
237 |
operations.toArray(new MBeanOperationInfo[operations.size()]), // operations |
|
238 |
getNotificationInfo(), // notifications |
|
239 |
desc); |
|
240 |
} |
|
241 |
||
242 |
@Override |
|
243 |
public Object invoke(String actionName, Object[] params, String[] signature) |
|
244 |
throws MBeanException, ReflectionException { |
|
245 |
if (!isSupported) { |
|
246 |
throw new UnsupportedOperationException(); |
|
247 |
} |
|
248 |
if (wrappers == null) { |
|
249 |
getMBeanInfo(); |
|
250 |
} |
|
251 |
Wrapper w = wrappers.get(actionName); |
|
252 |
if (w != null) { |
|
253 |
if (w.info.getArgumentsInfo().isEmpty() |
|
254 |
&& (params == null || params.length == 0) |
|
255 |
&& (signature == null || signature.length == 0)) { |
|
256 |
return w.execute(null); |
|
257 |
} else if((params != null && params.length == 1) |
|
258 |
&& (signature != null && signature.length == 1 |
|
259 |
&& signature[0] != null |
|
260 |
&& signature[0].compareTo(strArrayClassName) == 0)) { |
|
261 |
return w.execute((String[]) params[0]); |
|
262 |
} |
|
263 |
} |
|
264 |
throw new ReflectionException(new NoSuchMethodException(actionName)); |
|
265 |
} |
|
266 |
||
267 |
private static String transform(String name) { |
|
268 |
StringBuilder sb = new StringBuilder(); |
|
269 |
boolean toLower = true; |
|
270 |
boolean toUpper = false; |
|
271 |
for (int i = 0; i < name.length(); i++) { |
|
272 |
char c = name.charAt(i); |
|
273 |
if (c == '.' || c == '_') { |
|
274 |
toLower = false; |
|
275 |
toUpper = true; |
|
276 |
} else { |
|
277 |
if (toUpper) { |
|
278 |
toUpper = false; |
|
279 |
sb.append(Character.toUpperCase(c)); |
|
280 |
} else if(toLower) { |
|
281 |
sb.append(Character.toLowerCase(c)); |
|
282 |
} else { |
|
283 |
sb.append(c); |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
return sb.toString(); |
|
288 |
} |
|
289 |
||
290 |
private Descriptor commandDescriptor(Wrapper w) throws IllegalArgumentException { |
|
291 |
HashMap<String, Object> map = new HashMap<>(); |
|
292 |
map.put("dcmd.name", w.info.getName()); |
|
293 |
map.put("dcmd.description", w.info.getDescription()); |
|
294 |
map.put("dcmd.vmImpact", w.info.getImpact()); |
|
295 |
map.put("dcmd.permissionClass", w.info.getPermissionClass()); |
|
296 |
map.put("dcmd.permissionName", w.info.getPermissionName()); |
|
297 |
map.put("dcmd.permissionAction", w.info.getPermissionAction()); |
|
298 |
map.put("dcmd.enabled", w.info.isEnabled()); |
|
299 |
StringBuilder sb = new StringBuilder(); |
|
300 |
sb.append("help "); |
|
301 |
sb.append(w.info.getName()); |
|
302 |
map.put("dcmd.help", executeDiagnosticCommand(sb.toString())); |
|
303 |
if (w.info.getArgumentsInfo() != null && !w.info.getArgumentsInfo().isEmpty()) { |
|
304 |
HashMap<String, Object> allargmap = new HashMap<>(); |
|
305 |
for (DiagnosticCommandArgumentInfo arginfo : w.info.getArgumentsInfo()) { |
|
306 |
HashMap<String, Object> argmap = new HashMap<>(); |
|
307 |
argmap.put("dcmd.arg.name", arginfo.getName()); |
|
308 |
argmap.put("dcmd.arg.type", arginfo.getType()); |
|
309 |
argmap.put("dcmd.arg.description", arginfo.getDescription()); |
|
310 |
argmap.put("dcmd.arg.isMandatory", arginfo.isMandatory()); |
|
311 |
argmap.put("dcmd.arg.isMultiple", arginfo.isMultiple()); |
|
312 |
boolean isOption = arginfo.isOption(); |
|
313 |
argmap.put("dcmd.arg.isOption", isOption); |
|
314 |
if(!isOption) { |
|
315 |
argmap.put("dcmd.arg.position", arginfo.getPosition()); |
|
316 |
} else { |
|
317 |
argmap.put("dcmd.arg.position", -1); |
|
318 |
} |
|
319 |
allargmap.put(arginfo.getName(), new ImmutableDescriptor(argmap)); |
|
320 |
} |
|
321 |
map.put("dcmd.arguments", new ImmutableDescriptor(allargmap)); |
|
322 |
} |
|
323 |
return new ImmutableDescriptor(map); |
|
324 |
} |
|
325 |
||
326 |
private final static String notifName = |
|
327 |
"javax.management.Notification"; |
|
328 |
||
329 |
private final static String[] diagFramNotifTypes = { |
|
330 |
"jmx.mbean.info.changed" |
|
331 |
}; |
|
332 |
||
333 |
private MBeanNotificationInfo[] notifInfo = null; |
|
334 |
||
335 |
@Override |
|
336 |
public MBeanNotificationInfo[] getNotificationInfo() { |
|
337 |
synchronized (this) { |
|
338 |
if (notifInfo == null) { |
|
339 |
notifInfo = new MBeanNotificationInfo[1]; |
|
340 |
notifInfo[0] = |
|
341 |
new MBeanNotificationInfo(diagFramNotifTypes, |
|
342 |
notifName, |
|
343 |
"Diagnostic Framework Notification"); |
|
344 |
} |
|
345 |
} |
|
346 |
return notifInfo; |
|
347 |
} |
|
348 |
||
349 |
private static long seqNumber = 0; |
|
350 |
private static long getNextSeqNumber() { |
|
351 |
return ++seqNumber; |
|
352 |
} |
|
353 |
||
354 |
private void createDiagnosticFrameworkNotification() { |
|
355 |
||
356 |
if (!hasListeners()) { |
|
357 |
return; |
|
358 |
} |
|
359 |
ObjectName on = null; |
|
360 |
try { |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
361 |
on = ObjectName.getInstance(PlatformMBeanProviderImpl.DIAGNOSTIC_COMMAND_MBEAN_NAME); |
17954 | 362 |
} catch (MalformedObjectNameException e) { } |
363 |
Notification notif = new Notification("jmx.mbean.info.changed", |
|
364 |
on, |
|
365 |
getNextSeqNumber()); |
|
366 |
notif.setUserData(getMBeanInfo()); |
|
367 |
sendNotification(notif); |
|
368 |
} |
|
369 |
||
370 |
@Override |
|
371 |
public synchronized void addNotificationListener(NotificationListener listener, |
|
372 |
NotificationFilter filter, |
|
373 |
Object handback) { |
|
374 |
boolean before = hasListeners(); |
|
375 |
super.addNotificationListener(listener, filter, handback); |
|
376 |
boolean after = hasListeners(); |
|
377 |
if (!before && after) { |
|
378 |
setNotificationEnabled(true); |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
@Override |
|
383 |
public synchronized void removeNotificationListener(NotificationListener listener) |
|
384 |
throws ListenerNotFoundException { |
|
385 |
boolean before = hasListeners(); |
|
386 |
super.removeNotificationListener(listener); |
|
387 |
boolean after = hasListeners(); |
|
388 |
if (before && !after) { |
|
389 |
setNotificationEnabled(false); |
|
390 |
} |
|
391 |
} |
|
392 |
||
393 |
@Override |
|
394 |
public synchronized void removeNotificationListener(NotificationListener listener, |
|
395 |
NotificationFilter filter, |
|
396 |
Object handback) |
|
397 |
throws ListenerNotFoundException { |
|
398 |
boolean before = hasListeners(); |
|
399 |
super.removeNotificationListener(listener, filter, handback); |
|
400 |
boolean after = hasListeners(); |
|
401 |
if (before && !after) { |
|
402 |
setNotificationEnabled(false); |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
private native void setNotificationEnabled(boolean enabled); |
|
407 |
private native String[] getDiagnosticCommands(); |
|
408 |
private native DiagnosticCommandInfo[] getDiagnosticCommandInfo(String[] commands); |
|
409 |
private native String executeDiagnosticCommand(String command); |
|
410 |
||
411 |
} |