author | vlivanov |
Thu, 18 Jan 2018 02:25:18 +0300 | |
changeset 48596 | 860326263d1f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, 2008, 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 sun.tools.jconsole.inspector; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import javax.management.*; |
|
30 |
import javax.swing.Icon; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
31 |
import sun.tools.jconsole.JConsole; |
2 | 32 |
import sun.tools.jconsole.MBeansTab; |
697
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
33 |
import sun.tools.jconsole.ProxyClient.SnapshotMBeanServerConnection; |
2 | 34 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
35 |
public class XMBean { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
36 |
|
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
37 |
private final MBeansTab mbeansTab; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
38 |
private final ObjectName objectName; |
2 | 39 |
private Icon icon; |
40 |
private String text; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
41 |
private Boolean broadcaster; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
42 |
private final Object broadcasterLock = new Object(); |
2 | 43 |
private MBeanInfo mbeanInfo; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
44 |
private final Object mbeanInfoLock = new Object(); |
2 | 45 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
46 |
public XMBean(ObjectName objectName, MBeansTab mbeansTab) { |
2 | 47 |
this.mbeansTab = mbeansTab; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
48 |
this.objectName = objectName; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
49 |
text = objectName.getKeyProperty("name"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
50 |
if (text == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
51 |
text = objectName.getDomain(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
52 |
} |
2 | 53 |
if (MBeanServerDelegate.DELEGATE_NAME.equals(objectName)) { |
54 |
icon = IconManager.MBEANSERVERDELEGATE; |
|
55 |
} else { |
|
56 |
icon = IconManager.MBEAN; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
MBeanServerConnection getMBeanServerConnection() { |
|
61 |
return mbeansTab.getMBeanServerConnection(); |
|
62 |
} |
|
63 |
||
697
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
64 |
SnapshotMBeanServerConnection getSnapshotMBeanServerConnection() { |
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
65 |
return mbeansTab.getSnapshotMBeanServerConnection(); |
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
66 |
} |
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
67 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
68 |
public Boolean isBroadcaster() { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
69 |
synchronized (broadcasterLock) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
70 |
if (broadcaster == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
71 |
try { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
72 |
broadcaster = getMBeanServerConnection().isInstanceOf( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
73 |
getObjectName(), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
74 |
"javax.management.NotificationBroadcaster"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
75 |
} catch (Exception e) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
76 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
77 |
System.err.println("Couldn't check if MBean [" + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
78 |
objectName + "] is a notification broadcaster"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
79 |
e.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
80 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
81 |
return false; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
82 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
83 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
84 |
return broadcaster; |
2 | 85 |
} |
86 |
} |
|
87 |
||
88 |
public Object invoke(String operationName) throws Exception { |
|
89 |
Object result = getMBeanServerConnection().invoke( |
|
90 |
getObjectName(), operationName, new Object[0], new String[0]); |
|
91 |
return result; |
|
92 |
} |
|
93 |
||
94 |
public Object invoke(String operationName, Object params[], String sig[]) |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
95 |
throws Exception { |
2 | 96 |
Object result = getMBeanServerConnection().invoke( |
97 |
getObjectName(), operationName, params, sig); |
|
98 |
return result; |
|
99 |
} |
|
100 |
||
101 |
public void setAttribute(Attribute attribute) |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
102 |
throws AttributeNotFoundException, InstanceNotFoundException, |
2 | 103 |
InvalidAttributeValueException, MBeanException, |
104 |
ReflectionException, IOException { |
|
105 |
getMBeanServerConnection().setAttribute(getObjectName(), attribute); |
|
106 |
} |
|
107 |
||
108 |
public Object getAttribute(String attributeName) |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
109 |
throws AttributeNotFoundException, InstanceNotFoundException, |
2 | 110 |
MBeanException, ReflectionException, IOException { |
697
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
111 |
return getSnapshotMBeanServerConnection().getAttribute( |
2 | 112 |
getObjectName(), attributeName); |
113 |
} |
|
114 |
||
115 |
public AttributeList getAttributes(String attributeNames[]) |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
116 |
throws AttributeNotFoundException, InstanceNotFoundException, |
2 | 117 |
MBeanException, ReflectionException, IOException { |
697
fb86c99b92a2
6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents:
55
diff
changeset
|
118 |
return getSnapshotMBeanServerConnection().getAttributes( |
2 | 119 |
getObjectName(), attributeNames); |
120 |
} |
|
121 |
||
122 |
public AttributeList getAttributes(MBeanAttributeInfo attributeNames[]) |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
123 |
throws AttributeNotFoundException, InstanceNotFoundException, |
2 | 124 |
MBeanException, ReflectionException, IOException { |
125 |
String attributeString[] = new String[attributeNames.length]; |
|
126 |
for (int i = 0; i < attributeNames.length; i++) { |
|
127 |
attributeString[i] = attributeNames[i].getName(); |
|
128 |
} |
|
129 |
return getAttributes(attributeString); |
|
130 |
} |
|
131 |
||
132 |
public ObjectName getObjectName() { |
|
133 |
return objectName; |
|
134 |
} |
|
135 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
136 |
public MBeanInfo getMBeanInfo() throws InstanceNotFoundException, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
137 |
IntrospectionException, ReflectionException, IOException { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
138 |
synchronized (mbeanInfoLock) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
139 |
if (mbeanInfo == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
140 |
mbeanInfo = getMBeanServerConnection().getMBeanInfo(objectName); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
141 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
142 |
return mbeanInfo; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
143 |
} |
2 | 144 |
} |
145 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
146 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
147 |
public boolean equals(Object obj) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
148 |
if (obj == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
149 |
return false; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
150 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
151 |
if (obj == this) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
152 |
return true; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
153 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
154 |
if (!(obj instanceof XMBean)) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
155 |
return false; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
156 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
157 |
XMBean that = (XMBean) obj; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
158 |
return getObjectName().equals(that.getObjectName()); |
2 | 159 |
} |
160 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
161 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
162 |
public int hashCode() { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
163 |
return (objectName == null ? 0 : objectName.hashCode()); |
2 | 164 |
} |
165 |
||
166 |
public String getText() { |
|
167 |
return text; |
|
168 |
} |
|
169 |
||
170 |
public void setText(String text) { |
|
171 |
this.text = text; |
|
172 |
} |
|
173 |
||
174 |
public Icon getIcon() { |
|
175 |
return icon; |
|
176 |
} |
|
177 |
||
178 |
public void setIcon(Icon icon) { |
|
179 |
this.icon = icon; |
|
180 |
} |
|
181 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
182 |
@Override |
2 | 183 |
public String toString() { |
184 |
return getText(); |
|
185 |
} |
|
186 |
} |