001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Marc Wick.
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.controller.jmx;
022:
023: import java.io.ObjectInputStream;
024: import java.util.Set;
025:
026: import javax.management.Attribute;
027: import javax.management.AttributeList;
028: import javax.management.AttributeNotFoundException;
029: import javax.management.InstanceAlreadyExistsException;
030: import javax.management.InstanceNotFoundException;
031: import javax.management.IntrospectionException;
032: import javax.management.InvalidAttributeValueException;
033: import javax.management.ListenerNotFoundException;
034: import javax.management.MBeanException;
035: import javax.management.MBeanInfo;
036: import javax.management.MBeanRegistrationException;
037: import javax.management.MBeanServer;
038: import javax.management.NotCompliantMBeanException;
039: import javax.management.NotificationFilter;
040: import javax.management.NotificationListener;
041: import javax.management.ObjectInstance;
042: import javax.management.ObjectName;
043: import javax.management.OperationsException;
044: import javax.management.QueryExp;
045: import javax.management.ReflectionException;
046: import javax.management.loading.ClassLoaderRepository;
047:
048: /**
049: * Base class for chained MBeanServers. By default this class delegates all
050: * method calls to the nested MBeanServer. Subclass it to add behavior to one or
051: * more (or all) methods.
052: * <p>
053: * This class takes its origin in mx4j.server.ChainedMBeanServer
054: *
055: * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
056: * @version 1.0
057: */
058: public class ChainedMBeanServer implements MBeanServer
059:
060: {
061: private MBeanServer mbServer;
062:
063: /**
064: * Creates a new ChainedMBeanServer that will delegate to an MBeanServer
065: * specified using {@link #setMBeanServer}
066: */
067: public ChainedMBeanServer() {
068: this (null);
069: }
070:
071: /**
072: * Creates a new ChainedMBeanServer that delegates to the specified
073: * <code>MBeanServer</code>.
074: *
075: * @param server MBeanServer
076: */
077: public ChainedMBeanServer(MBeanServer server) {
078: setMBeanServer(server);
079: }
080:
081: /**
082: * Returns the nested MBeanServer
083: */
084: protected synchronized MBeanServer getMBeanServer() {
085: return mbServer;
086: }
087:
088: protected synchronized void setMBeanServer(MBeanServer server) {
089: mbServer = server;
090: }
091:
092: /**
093: * @see javax.management.MBeanServerConnection#addNotificationListener(javax.management.ObjectName,
094: * javax.management.NotificationListener,
095: * javax.management.NotificationFilter, java.lang.Object)
096: */
097: public void addNotificationListener(ObjectName observed,
098: NotificationListener listener, NotificationFilter filter,
099: Object handback) throws InstanceNotFoundException {
100: getMBeanServer().addNotificationListener(observed, listener,
101: filter, handback);
102: }
103:
104: /**
105: * @see javax.management.MBeanServerConnection#addNotificationListener(javax.management.ObjectName,
106: * javax.management.ObjectName, javax.management.NotificationFilter,
107: * java.lang.Object)
108: */
109: public void addNotificationListener(ObjectName observed,
110: ObjectName listener, NotificationFilter filter,
111: Object handback) throws InstanceNotFoundException {
112: getMBeanServer().addNotificationListener(observed, listener,
113: filter, handback);
114: }
115:
116: /**
117: * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
118: * javax.management.ObjectName)
119: */
120: public ObjectInstance createMBean(String className,
121: ObjectName objectName) throws ReflectionException,
122: InstanceAlreadyExistsException, MBeanRegistrationException,
123: MBeanException, NotCompliantMBeanException {
124: return getMBeanServer().createMBean(className, objectName);
125: }
126:
127: /**
128: * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
129: * javax.management.ObjectName, java.lang.Object[], java.lang.String[])
130: */
131: public ObjectInstance createMBean(String className,
132: ObjectName objectName, Object[] args, String[] parameters)
133: throws ReflectionException, InstanceAlreadyExistsException,
134: MBeanRegistrationException, MBeanException,
135: NotCompliantMBeanException {
136: return getMBeanServer().createMBean(className, objectName,
137: args, parameters);
138: }
139:
140: /**
141: * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
142: * javax.management.ObjectName, javax.management.ObjectName)
143: */
144: public ObjectInstance createMBean(String className,
145: ObjectName objectName, ObjectName loaderName)
146: throws ReflectionException, InstanceAlreadyExistsException,
147: MBeanRegistrationException, MBeanException,
148: NotCompliantMBeanException, InstanceNotFoundException {
149: return getMBeanServer().createMBean(className, objectName,
150: loaderName);
151: }
152:
153: /**
154: * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
155: * javax.management.ObjectName, javax.management.ObjectName,
156: * java.lang.Object[], java.lang.String[])
157: */
158: public ObjectInstance createMBean(String className,
159: ObjectName objectName, ObjectName loaderName,
160: Object[] args, String[] parameters)
161: throws ReflectionException, InstanceAlreadyExistsException,
162: MBeanRegistrationException, MBeanException,
163: NotCompliantMBeanException, InstanceNotFoundException {
164: return getMBeanServer().createMBean(className, objectName,
165: loaderName, args, parameters);
166: }
167:
168: /**
169: * @see javax.management.MBeanServer#deserialize(java.lang.String, byte[])
170: */
171: public ObjectInputStream deserialize(String className, byte[] bytes)
172: throws OperationsException, ReflectionException {
173: return getMBeanServer().deserialize(className, bytes);
174: }
175:
176: /**
177: * @see javax.management.MBeanServer#deserialize(java.lang.String,
178: * javax.management.ObjectName, byte[])
179: */
180: public ObjectInputStream deserialize(String className,
181: ObjectName loaderName, byte[] bytes)
182: throws InstanceNotFoundException, OperationsException,
183: ReflectionException {
184: return getMBeanServer().deserialize(className, loaderName,
185: bytes);
186: }
187:
188: /**
189: * @see javax.management.MBeanServer#deserialize(javax.management.ObjectName,
190: * byte[])
191: */
192: public ObjectInputStream deserialize(ObjectName objectName,
193: byte[] bytes) throws InstanceNotFoundException,
194: OperationsException {
195: return getMBeanServer().deserialize(objectName, bytes);
196: }
197:
198: /**
199: * @see javax.management.MBeanServerConnection#getAttribute(javax.management.ObjectName,
200: * java.lang.String)
201: */
202: public Object getAttribute(ObjectName objectName, String attribute)
203: throws MBeanException, AttributeNotFoundException,
204: InstanceNotFoundException, ReflectionException {
205: return getMBeanServer().getAttribute(objectName, attribute);
206: }
207:
208: /**
209: * @see javax.management.MBeanServerConnection#getAttributes(javax.management.ObjectName,
210: * java.lang.String[])
211: */
212: public AttributeList getAttributes(ObjectName objectName,
213: String[] attributes) throws InstanceNotFoundException,
214: ReflectionException {
215: return getMBeanServer().getAttributes(objectName, attributes);
216: }
217:
218: /**
219: * @see javax.management.MBeanServerConnection#getDefaultDomain()
220: */
221: public String getDefaultDomain() {
222: return getMBeanServer().getDefaultDomain();
223: }
224:
225: /**
226: * @see javax.management.MBeanServerConnection#getDomains()
227: */
228: public String[] getDomains() {
229: return getMBeanServer().getDomains();
230: }
231:
232: /**
233: * @see javax.management.MBeanServerConnection#getMBeanCount()
234: */
235: public Integer getMBeanCount() {
236: return getMBeanServer().getMBeanCount();
237: }
238:
239: /**
240: * @see javax.management.MBeanServerConnection#getMBeanInfo(javax.management.ObjectName)
241: */
242: public MBeanInfo getMBeanInfo(ObjectName objectName)
243: throws InstanceNotFoundException, IntrospectionException,
244: ReflectionException {
245: return getMBeanServer().getMBeanInfo(objectName);
246: }
247:
248: /**
249: * @see javax.management.MBeanServerConnection#getObjectInstance(javax.management.ObjectName)
250: */
251: public ObjectInstance getObjectInstance(ObjectName objectName)
252: throws InstanceNotFoundException {
253: return getMBeanServer().getObjectInstance(objectName);
254: }
255:
256: /**
257: * @see javax.management.MBeanServer#instantiate(java.lang.String)
258: */
259: public Object instantiate(String className)
260: throws ReflectionException, MBeanException {
261: return getMBeanServer().instantiate(className);
262: }
263:
264: /**
265: * @see javax.management.MBeanServer#instantiate(java.lang.String,
266: * java.lang.Object[], java.lang.String[])
267: */
268: public Object instantiate(String className, Object[] args,
269: String[] parameters) throws ReflectionException,
270: MBeanException {
271: return getMBeanServer()
272: .instantiate(className, args, parameters);
273: }
274:
275: /**
276: * @see javax.management.MBeanServer#instantiate(java.lang.String,
277: * javax.management.ObjectName)
278: */
279: public Object instantiate(String className, ObjectName loaderName)
280: throws ReflectionException, MBeanException,
281: InstanceNotFoundException {
282: return getMBeanServer().instantiate(className, loaderName);
283: }
284:
285: /**
286: * @see javax.management.MBeanServer#instantiate(java.lang.String,
287: * javax.management.ObjectName, java.lang.Object[], java.lang.String[])
288: */
289: public Object instantiate(String className, ObjectName loaderName,
290: Object[] args, String[] parameters)
291: throws ReflectionException, MBeanException,
292: InstanceNotFoundException {
293: return getMBeanServer().instantiate(className, loaderName,
294: args, parameters);
295: }
296:
297: /**
298: * @see javax.management.MBeanServerConnection#invoke(javax.management.ObjectName,
299: * java.lang.String, java.lang.Object[], java.lang.String[])
300: */
301: public Object invoke(ObjectName objectName, String methodName,
302: Object[] args, String[] parameters)
303: throws InstanceNotFoundException, MBeanException,
304: ReflectionException {
305: return getMBeanServer().invoke(objectName, methodName, args,
306: parameters);
307: }
308:
309: /**
310: * @see javax.management.MBeanServerConnection#isInstanceOf(javax.management.ObjectName,
311: * java.lang.String)
312: */
313: public boolean isInstanceOf(ObjectName objectName, String className)
314: throws InstanceNotFoundException {
315: return getMBeanServer().isInstanceOf(objectName, className);
316: }
317:
318: /**
319: * @see javax.management.MBeanServerConnection#isRegistered(javax.management.ObjectName)
320: */
321: public boolean isRegistered(ObjectName objectname) {
322: return getMBeanServer().isRegistered(objectname);
323: }
324:
325: /**
326: * @see javax.management.MBeanServerConnection#queryMBeans(javax.management.ObjectName,
327: * javax.management.QueryExp)
328: */
329: public Set queryMBeans(ObjectName patternName, QueryExp filter) {
330: return getMBeanServer().queryMBeans(patternName, filter);
331: }
332:
333: /**
334: * @see javax.management.MBeanServerConnection#queryNames(javax.management.ObjectName,
335: * javax.management.QueryExp)
336: */
337: public Set queryNames(ObjectName patternName, QueryExp filter) {
338: return getMBeanServer().queryNames(patternName, filter);
339: }
340:
341: /**
342: * @see javax.management.MBeanServer#registerMBean(java.lang.Object,
343: * javax.management.ObjectName)
344: */
345: public ObjectInstance registerMBean(Object mbean,
346: ObjectName objectName)
347: throws InstanceAlreadyExistsException,
348: MBeanRegistrationException, NotCompliantMBeanException {
349: return getMBeanServer().registerMBean(mbean, objectName);
350: }
351:
352: /**
353: * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
354: * javax.management.NotificationListener)
355: */
356: public void removeNotificationListener(ObjectName observed,
357: NotificationListener listener)
358: throws InstanceNotFoundException, ListenerNotFoundException {
359: getMBeanServer().removeNotificationListener(observed, listener);
360: }
361:
362: /**
363: * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
364: * javax.management.ObjectName)
365: */
366: public void removeNotificationListener(ObjectName observed,
367: ObjectName listener) throws InstanceNotFoundException,
368: ListenerNotFoundException {
369: getMBeanServer().removeNotificationListener(observed, listener);
370: }
371:
372: /**
373: * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
374: * javax.management.ObjectName, javax.management.NotificationFilter,
375: * java.lang.Object)
376: */
377: public void removeNotificationListener(ObjectName observed,
378: ObjectName listener, NotificationFilter filter,
379: Object handback) throws InstanceNotFoundException,
380: ListenerNotFoundException {
381: getMBeanServer().removeNotificationListener(observed, listener,
382: filter, handback);
383: }
384:
385: /**
386: * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
387: * javax.management.NotificationListener,
388: * javax.management.NotificationFilter, java.lang.Object)
389: */
390: public void removeNotificationListener(ObjectName observed,
391: NotificationListener listener, NotificationFilter filter,
392: Object handback) throws InstanceNotFoundException,
393: ListenerNotFoundException {
394: getMBeanServer().removeNotificationListener(observed, listener,
395: filter, handback);
396: }
397:
398: /**
399: * @see javax.management.MBeanServerConnection#setAttribute(javax.management.ObjectName,
400: * javax.management.Attribute)
401: */
402: public void setAttribute(ObjectName objectName, Attribute attribute)
403: throws InstanceNotFoundException,
404: AttributeNotFoundException, InvalidAttributeValueException,
405: MBeanException, ReflectionException {
406: getMBeanServer().setAttribute(objectName, attribute);
407: }
408:
409: /**
410: * @see javax.management.MBeanServerConnection#setAttributes(javax.management.ObjectName,
411: * javax.management.AttributeList)
412: */
413: public AttributeList setAttributes(ObjectName objectName,
414: AttributeList attributes) throws InstanceNotFoundException,
415: ReflectionException {
416: return getMBeanServer().setAttributes(objectName, attributes);
417: }
418:
419: /**
420: * @see javax.management.MBeanServerConnection#unregisterMBean(javax.management.ObjectName)
421: */
422: public void unregisterMBean(ObjectName objectName)
423: throws InstanceNotFoundException,
424: MBeanRegistrationException {
425: getMBeanServer().unregisterMBean(objectName);
426: }
427:
428: /**
429: * @see javax.management.MBeanServer#getClassLoaderFor(javax.management.ObjectName)
430: */
431: public ClassLoader getClassLoaderFor(ObjectName mbeanName)
432: throws InstanceNotFoundException {
433: return getMBeanServer().getClassLoaderFor(mbeanName);
434: }
435:
436: /**
437: * @see javax.management.MBeanServer#getClassLoader(javax.management.ObjectName)
438: */
439: public ClassLoader getClassLoader(ObjectName loaderName)
440: throws InstanceNotFoundException {
441: return getMBeanServer().getClassLoader(loaderName);
442: }
443:
444: /**
445: * @see javax.management.MBeanServer#getClassLoaderRepository()
446: */
447: public ClassLoaderRepository getClassLoaderRepository() {
448: return getMBeanServer().getClassLoaderRepository();
449: }
450:
451: }
|