1 /* |
|
2 * Copyright 2008 Sun Microsystems, Inc. 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 package javax.management.remote; |
|
26 |
|
27 import java.io.ObjectInputStream; |
|
28 import java.util.Set; |
|
29 import javax.management.Attribute; |
|
30 import javax.management.AttributeList; |
|
31 import javax.management.AttributeNotFoundException; |
|
32 import javax.management.InstanceAlreadyExistsException; |
|
33 import javax.management.InstanceNotFoundException; |
|
34 import javax.management.IntrospectionException; |
|
35 import javax.management.InvalidAttributeValueException; |
|
36 import javax.management.ListenerNotFoundException; |
|
37 import javax.management.MBeanException; |
|
38 import javax.management.MBeanInfo; |
|
39 import javax.management.MBeanRegistrationException; |
|
40 import javax.management.MBeanServer; |
|
41 import javax.management.NotCompliantMBeanException; |
|
42 import javax.management.NotificationFilter; |
|
43 import javax.management.NotificationListener; |
|
44 import javax.management.ObjectInstance; |
|
45 import javax.management.ObjectName; |
|
46 import javax.management.OperationsException; |
|
47 import javax.management.QueryExp; |
|
48 import javax.management.ReflectionException; |
|
49 import javax.management.loading.ClassLoaderRepository; |
|
50 |
|
51 /** |
|
52 * An {@link MBeanServerForwarder} that forwards all {@link MBeanServer} |
|
53 * operations unchanged to the next {@code MBeanServer} in the chain. |
|
54 * This class is typically subclassed to override some but not all methods. |
|
55 */ |
|
56 public class IdentityMBeanServerForwarder implements MBeanServerForwarder { |
|
57 |
|
58 private MBeanServer next; |
|
59 |
|
60 /** |
|
61 * <p>Construct a forwarder that has no next {@code MBeanServer}. |
|
62 * The resulting object will be unusable until {@link #setMBeanServer |
|
63 * setMBeanServer} is called to establish the next item in the chain.</p> |
|
64 */ |
|
65 public IdentityMBeanServerForwarder() { |
|
66 } |
|
67 |
|
68 /** |
|
69 * <p>Construct a forwarder that forwards to the given {@code MBeanServer}. |
|
70 * It is not an error for {@code next} to be null, but the resulting object |
|
71 * will be unusable until {@link #setMBeanServer setMBeanServer} is called |
|
72 * to establish the next item in the chain.</p> |
|
73 */ |
|
74 public IdentityMBeanServerForwarder(MBeanServer next) { |
|
75 this.next = next; |
|
76 } |
|
77 |
|
78 public synchronized MBeanServer getMBeanServer() { |
|
79 return next; |
|
80 } |
|
81 |
|
82 public synchronized void setMBeanServer(MBeanServer mbs) { |
|
83 next = mbs; |
|
84 } |
|
85 |
|
86 private synchronized MBeanServer next() { |
|
87 return next; |
|
88 } |
|
89 |
|
90 public void unregisterMBean(ObjectName name) |
|
91 throws InstanceNotFoundException, MBeanRegistrationException { |
|
92 next().unregisterMBean(name); |
|
93 } |
|
94 |
|
95 public AttributeList setAttributes(ObjectName name, |
|
96 AttributeList attributes) |
|
97 throws InstanceNotFoundException, ReflectionException { |
|
98 return next().setAttributes(name, attributes); |
|
99 } |
|
100 |
|
101 public void setAttribute(ObjectName name, Attribute attribute) |
|
102 throws InstanceNotFoundException, AttributeNotFoundException, |
|
103 InvalidAttributeValueException, MBeanException, |
|
104 ReflectionException { |
|
105 next().setAttribute(name, attribute); |
|
106 } |
|
107 |
|
108 public void removeNotificationListener(ObjectName name, |
|
109 NotificationListener listener, |
|
110 NotificationFilter filter, |
|
111 Object handback) |
|
112 throws InstanceNotFoundException, ListenerNotFoundException { |
|
113 next().removeNotificationListener(name, listener, filter, handback); |
|
114 } |
|
115 |
|
116 public void removeNotificationListener(ObjectName name, |
|
117 NotificationListener listener) |
|
118 throws InstanceNotFoundException, ListenerNotFoundException { |
|
119 next().removeNotificationListener(name, listener); |
|
120 } |
|
121 |
|
122 public void removeNotificationListener(ObjectName name, ObjectName listener, |
|
123 NotificationFilter filter, |
|
124 Object handback) |
|
125 throws InstanceNotFoundException, ListenerNotFoundException { |
|
126 next().removeNotificationListener(name, listener, filter, handback); |
|
127 } |
|
128 |
|
129 public void removeNotificationListener(ObjectName name, ObjectName listener) |
|
130 throws InstanceNotFoundException, ListenerNotFoundException { |
|
131 next().removeNotificationListener(name, listener); |
|
132 } |
|
133 |
|
134 public ObjectInstance registerMBean(Object object, ObjectName name) |
|
135 throws InstanceAlreadyExistsException, MBeanRegistrationException, |
|
136 NotCompliantMBeanException { |
|
137 return next().registerMBean(object, name); |
|
138 } |
|
139 |
|
140 public Set<ObjectName> queryNames(ObjectName name, QueryExp query) { |
|
141 return next().queryNames(name, query); |
|
142 } |
|
143 |
|
144 public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) { |
|
145 return next().queryMBeans(name, query); |
|
146 } |
|
147 |
|
148 public boolean isRegistered(ObjectName name) { |
|
149 return next().isRegistered(name); |
|
150 } |
|
151 |
|
152 public boolean isInstanceOf(ObjectName name, String className) |
|
153 throws InstanceNotFoundException { |
|
154 return next().isInstanceOf(name, className); |
|
155 } |
|
156 |
|
157 public Object invoke(ObjectName name, String operationName, Object[] params, |
|
158 String[] signature) |
|
159 throws InstanceNotFoundException, MBeanException, |
|
160 ReflectionException { |
|
161 return next().invoke(name, operationName, params, signature); |
|
162 } |
|
163 |
|
164 public Object instantiate(String className, ObjectName loaderName, |
|
165 Object[] params, String[] signature) |
|
166 throws ReflectionException, MBeanException, |
|
167 InstanceNotFoundException { |
|
168 return next().instantiate(className, loaderName, params, signature); |
|
169 } |
|
170 |
|
171 public Object instantiate(String className, Object[] params, |
|
172 String[] signature) |
|
173 throws ReflectionException, MBeanException { |
|
174 return next().instantiate(className, params, signature); |
|
175 } |
|
176 |
|
177 public Object instantiate(String className, ObjectName loaderName) |
|
178 throws ReflectionException, MBeanException, |
|
179 InstanceNotFoundException { |
|
180 return next().instantiate(className, loaderName); |
|
181 } |
|
182 |
|
183 public Object instantiate(String className) |
|
184 throws ReflectionException, MBeanException { |
|
185 return next().instantiate(className); |
|
186 } |
|
187 |
|
188 public ObjectInstance getObjectInstance(ObjectName name) |
|
189 throws InstanceNotFoundException { |
|
190 return next().getObjectInstance(name); |
|
191 } |
|
192 |
|
193 public MBeanInfo getMBeanInfo(ObjectName name) |
|
194 throws InstanceNotFoundException, IntrospectionException, |
|
195 ReflectionException { |
|
196 return next().getMBeanInfo(name); |
|
197 } |
|
198 |
|
199 public Integer getMBeanCount() { |
|
200 return next().getMBeanCount(); |
|
201 } |
|
202 |
|
203 public String[] getDomains() { |
|
204 return next().getDomains(); |
|
205 } |
|
206 |
|
207 public String getDefaultDomain() { |
|
208 return next().getDefaultDomain(); |
|
209 } |
|
210 |
|
211 public ClassLoaderRepository getClassLoaderRepository() { |
|
212 return next().getClassLoaderRepository(); |
|
213 } |
|
214 |
|
215 public ClassLoader getClassLoaderFor(ObjectName mbeanName) |
|
216 throws InstanceNotFoundException { |
|
217 return next().getClassLoaderFor(mbeanName); |
|
218 } |
|
219 |
|
220 public ClassLoader getClassLoader(ObjectName loaderName) |
|
221 throws InstanceNotFoundException { |
|
222 return next().getClassLoader(loaderName); |
|
223 } |
|
224 |
|
225 public AttributeList getAttributes(ObjectName name, String[] attributes) |
|
226 throws InstanceNotFoundException, ReflectionException { |
|
227 return next().getAttributes(name, attributes); |
|
228 } |
|
229 |
|
230 public Object getAttribute(ObjectName name, String attribute) |
|
231 throws MBeanException, AttributeNotFoundException, |
|
232 InstanceNotFoundException, ReflectionException { |
|
233 return next().getAttribute(name, attribute); |
|
234 } |
|
235 |
|
236 @Deprecated |
|
237 public ObjectInputStream deserialize(String className, |
|
238 ObjectName loaderName, |
|
239 byte[] data) |
|
240 throws InstanceNotFoundException, OperationsException, |
|
241 ReflectionException { |
|
242 return next().deserialize(className, loaderName, data); |
|
243 } |
|
244 |
|
245 @Deprecated |
|
246 public ObjectInputStream deserialize(String className, byte[] data) |
|
247 throws OperationsException, ReflectionException { |
|
248 return next().deserialize(className, data); |
|
249 } |
|
250 |
|
251 @Deprecated |
|
252 public ObjectInputStream deserialize(ObjectName name, byte[] data) |
|
253 throws InstanceNotFoundException, OperationsException { |
|
254 return next().deserialize(name, data); |
|
255 } |
|
256 |
|
257 public ObjectInstance createMBean(String className, ObjectName name, |
|
258 ObjectName loaderName, Object[] params, |
|
259 String[] signature) |
|
260 throws ReflectionException, InstanceAlreadyExistsException, |
|
261 MBeanRegistrationException, MBeanException, |
|
262 NotCompliantMBeanException, InstanceNotFoundException { |
|
263 return next().createMBean(className, name, loaderName, params, signature); |
|
264 } |
|
265 |
|
266 public ObjectInstance createMBean(String className, ObjectName name, |
|
267 Object[] params, String[] signature) |
|
268 throws ReflectionException, InstanceAlreadyExistsException, |
|
269 MBeanRegistrationException, MBeanException, |
|
270 NotCompliantMBeanException { |
|
271 return next().createMBean(className, name, params, signature); |
|
272 } |
|
273 |
|
274 public ObjectInstance createMBean(String className, ObjectName name, |
|
275 ObjectName loaderName) |
|
276 throws ReflectionException, InstanceAlreadyExistsException, |
|
277 MBeanRegistrationException, MBeanException, |
|
278 NotCompliantMBeanException, InstanceNotFoundException { |
|
279 return next().createMBean(className, name, loaderName); |
|
280 } |
|
281 |
|
282 public ObjectInstance createMBean(String className, ObjectName name) |
|
283 throws ReflectionException, InstanceAlreadyExistsException, |
|
284 MBeanRegistrationException, MBeanException, |
|
285 NotCompliantMBeanException { |
|
286 return next().createMBean(className, name); |
|
287 } |
|
288 |
|
289 public void addNotificationListener(ObjectName name, ObjectName listener, |
|
290 NotificationFilter filter, |
|
291 Object handback) |
|
292 throws InstanceNotFoundException { |
|
293 next().addNotificationListener(name, listener, filter, handback); |
|
294 } |
|
295 |
|
296 public void addNotificationListener(ObjectName name, |
|
297 NotificationListener listener, |
|
298 NotificationFilter filter, |
|
299 Object handback) |
|
300 throws InstanceNotFoundException { |
|
301 next().addNotificationListener(name, listener, filter, handback); |
|
302 } |
|
303 } |
|