KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > jmx > ChainedMBeanServer


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Marc Wick.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.controller.jmx;
26
27 import java.io.ObjectInputStream JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import javax.management.Attribute JavaDoc;
31 import javax.management.AttributeList JavaDoc;
32 import javax.management.AttributeNotFoundException JavaDoc;
33 import javax.management.InstanceAlreadyExistsException JavaDoc;
34 import javax.management.InstanceNotFoundException JavaDoc;
35 import javax.management.IntrospectionException JavaDoc;
36 import javax.management.InvalidAttributeValueException JavaDoc;
37 import javax.management.ListenerNotFoundException JavaDoc;
38 import javax.management.MBeanException JavaDoc;
39 import javax.management.MBeanInfo JavaDoc;
40 import javax.management.MBeanRegistrationException JavaDoc;
41 import javax.management.MBeanServer JavaDoc;
42 import javax.management.NotCompliantMBeanException JavaDoc;
43 import javax.management.NotificationFilter JavaDoc;
44 import javax.management.NotificationListener JavaDoc;
45 import javax.management.ObjectInstance JavaDoc;
46 import javax.management.ObjectName JavaDoc;
47 import javax.management.OperationsException JavaDoc;
48 import javax.management.QueryExp JavaDoc;
49 import javax.management.ReflectionException JavaDoc;
50 import javax.management.loading.ClassLoaderRepository JavaDoc;
51
52 /**
53  * Base class for chained MBeanServers. By default this class delegates all
54  * method calls to the nested MBeanServer. Subclass it to add behavior to one or
55  * more (or all) methods.
56  * <p>
57  * This class takes its origin in mx4j.server.ChainedMBeanServer
58  *
59  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
60  * @version 1.0
61  */

62 public class ChainedMBeanServer implements MBeanServer JavaDoc
63
64 {
65   private MBeanServer JavaDoc mbServer;
66
67   /**
68    * Creates a new ChainedMBeanServer that will delegate to an MBeanServer
69    * specified using {@link #setMBeanServer}
70    */

71   public ChainedMBeanServer()
72   {
73     this(null);
74   }
75
76   /**
77    * Creates a new ChainedMBeanServer that delegates to the specified
78    * <code>MBeanServer</code>.
79    *
80    * @param server MBeanServer
81    */

82   public ChainedMBeanServer(MBeanServer JavaDoc server)
83   {
84     setMBeanServer(server);
85   }
86
87   /**
88    * Returns the nested MBeanServer
89    */

90   protected synchronized MBeanServer JavaDoc getMBeanServer()
91   {
92     return mbServer;
93   }
94
95   protected synchronized void setMBeanServer(MBeanServer JavaDoc server)
96   {
97     mbServer = server;
98   }
99
100   /**
101    * @see javax.management.MBeanServerConnection#addNotificationListener(javax.management.ObjectName,
102    * javax.management.NotificationListener,
103    * javax.management.NotificationFilter, java.lang.Object)
104    */

105   public void addNotificationListener(ObjectName JavaDoc observed,
106       NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
107       throws InstanceNotFoundException JavaDoc
108   {
109     getMBeanServer().addNotificationListener(observed, listener, filter,
110         handback);
111   }
112
113   /**
114    * @see javax.management.MBeanServerConnection#addNotificationListener(javax.management.ObjectName,
115    * javax.management.ObjectName, javax.management.NotificationFilter,
116    * java.lang.Object)
117    */

118   public void addNotificationListener(ObjectName JavaDoc observed, ObjectName JavaDoc listener,
119       NotificationFilter JavaDoc filter, Object JavaDoc handback)
120       throws InstanceNotFoundException JavaDoc
121   {
122     getMBeanServer().addNotificationListener(observed, listener, filter,
123         handback);
124   }
125
126   /**
127    * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
128    * javax.management.ObjectName)
129    */

130   public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc objectName)
131       throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc,
132       MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc
133   {
134     return getMBeanServer().createMBean(className, objectName);
135   }
136
137   /**
138    * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
139    * javax.management.ObjectName, java.lang.Object[], java.lang.String[])
140    */

141   public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc objectName,
142       Object JavaDoc[] args, String JavaDoc[] parameters) throws ReflectionException JavaDoc,
143       InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
144       MBeanException JavaDoc, NotCompliantMBeanException JavaDoc
145   {
146     return getMBeanServer()
147         .createMBean(className, objectName, args, parameters);
148   }
149
150   /**
151    * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
152    * javax.management.ObjectName, javax.management.ObjectName)
153    */

154   public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc objectName,
155       ObjectName JavaDoc loaderName) throws ReflectionException JavaDoc,
156       InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
157       MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc
158   {
159     return getMBeanServer().createMBean(className, objectName, loaderName);
160   }
161
162   /**
163    * @see javax.management.MBeanServerConnection#createMBean(java.lang.String,
164    * javax.management.ObjectName, javax.management.ObjectName,
165    * java.lang.Object[], java.lang.String[])
166    */

167   public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc objectName,
168       ObjectName JavaDoc loaderName, Object JavaDoc[] args, String JavaDoc[] parameters)
169       throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc,
170       MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc,
171       InstanceNotFoundException JavaDoc
172   {
173     return getMBeanServer().createMBean(className, objectName, loaderName,
174         args, parameters);
175   }
176
177   /**
178    * @see javax.management.MBeanServer#deserialize(java.lang.String, byte[])
179    */

180   public ObjectInputStream JavaDoc deserialize(String JavaDoc className, byte[] bytes)
181       throws OperationsException JavaDoc, ReflectionException JavaDoc
182   {
183     return getMBeanServer().deserialize(className, bytes);
184   }
185
186   /**
187    * @see javax.management.MBeanServer#deserialize(java.lang.String,
188    * javax.management.ObjectName, byte[])
189    */

190   public ObjectInputStream JavaDoc deserialize(String JavaDoc className, ObjectName JavaDoc loaderName,
191       byte[] bytes) throws InstanceNotFoundException JavaDoc, OperationsException JavaDoc,
192       ReflectionException JavaDoc
193   {
194     return getMBeanServer().deserialize(className, loaderName, bytes);
195   }
196
197   /**
198    * @see javax.management.MBeanServer#deserialize(javax.management.ObjectName,
199    * byte[])
200    */

201   public ObjectInputStream JavaDoc deserialize(ObjectName JavaDoc objectName, byte[] bytes)
202       throws InstanceNotFoundException JavaDoc, OperationsException JavaDoc
203   {
204     return getMBeanServer().deserialize(objectName, bytes);
205   }
206
207   /**
208    * @see javax.management.MBeanServerConnection#getAttribute(javax.management.ObjectName,
209    * java.lang.String)
210    */

211   public Object JavaDoc getAttribute(ObjectName JavaDoc objectName, String JavaDoc attribute)
212       throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc,
213       InstanceNotFoundException JavaDoc, ReflectionException JavaDoc
214   {
215     return getMBeanServer().getAttribute(objectName, attribute);
216   }
217
218   /**
219    * @see javax.management.MBeanServerConnection#getAttributes(javax.management.ObjectName,
220    * java.lang.String[])
221    */

222   public AttributeList JavaDoc getAttributes(ObjectName JavaDoc objectName, String JavaDoc[] attributes)
223       throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc
224   {
225     return getMBeanServer().getAttributes(objectName, attributes);
226   }
227
228   /**
229    * @see javax.management.MBeanServerConnection#getDefaultDomain()
230    */

231   public String JavaDoc getDefaultDomain()
232   {
233     return getMBeanServer().getDefaultDomain();
234   }
235
236   /**
237    * @see javax.management.MBeanServerConnection#getDomains()
238    */

239   public String JavaDoc[] getDomains()
240   {
241     return getMBeanServer().getDomains();
242   }
243
244   /**
245    * @see javax.management.MBeanServerConnection#getMBeanCount()
246    */

247   public Integer JavaDoc getMBeanCount()
248   {
249     return getMBeanServer().getMBeanCount();
250   }
251
252   /**
253    * @see javax.management.MBeanServerConnection#getMBeanInfo(javax.management.ObjectName)
254    */

255   public MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc objectName)
256       throws InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
257       ReflectionException JavaDoc
258   {
259     return getMBeanServer().getMBeanInfo(objectName);
260   }
261
262   /**
263    * @see javax.management.MBeanServerConnection#getObjectInstance(javax.management.ObjectName)
264    */

265   public ObjectInstance JavaDoc getObjectInstance(ObjectName JavaDoc objectName)
266       throws InstanceNotFoundException JavaDoc
267   {
268     return getMBeanServer().getObjectInstance(objectName);
269   }
270
271   /**
272    * @see javax.management.MBeanServer#instantiate(java.lang.String)
273    */

274   public Object JavaDoc instantiate(String JavaDoc className) throws ReflectionException JavaDoc,
275       MBeanException JavaDoc
276   {
277     return getMBeanServer().instantiate(className);
278   }
279
280   /**
281    * @see javax.management.MBeanServer#instantiate(java.lang.String,
282    * java.lang.Object[], java.lang.String[])
283    */

284   public Object JavaDoc instantiate(String JavaDoc className, Object JavaDoc[] args, String JavaDoc[] parameters)
285       throws ReflectionException JavaDoc, MBeanException JavaDoc
286   {
287     return getMBeanServer().instantiate(className, args, parameters);
288   }
289
290   /**
291    * @see javax.management.MBeanServer#instantiate(java.lang.String,
292    * javax.management.ObjectName)
293    */

294   public Object JavaDoc instantiate(String JavaDoc className, ObjectName JavaDoc loaderName)
295       throws ReflectionException JavaDoc, MBeanException JavaDoc, InstanceNotFoundException JavaDoc
296   {
297     return getMBeanServer().instantiate(className, loaderName);
298   }
299
300   /**
301    * @see javax.management.MBeanServer#instantiate(java.lang.String,
302    * javax.management.ObjectName, java.lang.Object[], java.lang.String[])
303    */

304   public Object JavaDoc instantiate(String JavaDoc className, ObjectName JavaDoc loaderName,
305       Object JavaDoc[] args, String JavaDoc[] parameters) throws ReflectionException JavaDoc,
306       MBeanException JavaDoc, InstanceNotFoundException JavaDoc
307   {
308     return getMBeanServer()
309         .instantiate(className, loaderName, args, parameters);
310   }
311
312   /**
313    * @see javax.management.MBeanServerConnection#invoke(javax.management.ObjectName,
314    * java.lang.String, java.lang.Object[], java.lang.String[])
315    */

316   public Object JavaDoc invoke(ObjectName JavaDoc objectName, String JavaDoc methodName, Object JavaDoc[] args,
317       String JavaDoc[] parameters) throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc,
318       ReflectionException JavaDoc
319   {
320     return getMBeanServer().invoke(objectName, methodName, args, parameters);
321   }
322
323   /**
324    * @see javax.management.MBeanServerConnection#isInstanceOf(javax.management.ObjectName,
325    * java.lang.String)
326    */

327   public boolean isInstanceOf(ObjectName JavaDoc objectName, String JavaDoc className)
328       throws InstanceNotFoundException JavaDoc
329   {
330     return getMBeanServer().isInstanceOf(objectName, className);
331   }
332
333   /**
334    * @see javax.management.MBeanServerConnection#isRegistered(javax.management.ObjectName)
335    */

336   public boolean isRegistered(ObjectName JavaDoc objectname)
337   {
338     return getMBeanServer().isRegistered(objectname);
339   }
340
341   /**
342    * @see javax.management.MBeanServerConnection#queryMBeans(javax.management.ObjectName,
343    * javax.management.QueryExp)
344    */

345   public Set JavaDoc queryMBeans(ObjectName JavaDoc patternName, QueryExp JavaDoc filter)
346   {
347     return getMBeanServer().queryMBeans(patternName, filter);
348   }
349
350   /**
351    * @see javax.management.MBeanServerConnection#queryNames(javax.management.ObjectName,
352    * javax.management.QueryExp)
353    */

354   public Set JavaDoc queryNames(ObjectName JavaDoc patternName, QueryExp JavaDoc filter)
355   {
356     return getMBeanServer().queryNames(patternName, filter);
357   }
358
359   /**
360    * @see javax.management.MBeanServer#registerMBean(java.lang.Object,
361    * javax.management.ObjectName)
362    */

363   public ObjectInstance JavaDoc registerMBean(Object JavaDoc mbean, ObjectName JavaDoc objectName)
364       throws InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
365       NotCompliantMBeanException JavaDoc
366   {
367     return getMBeanServer().registerMBean(mbean, objectName);
368   }
369
370   /**
371    * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
372    * javax.management.NotificationListener)
373    */

374   public void removeNotificationListener(ObjectName JavaDoc observed,
375       NotificationListener JavaDoc listener) throws InstanceNotFoundException JavaDoc,
376       ListenerNotFoundException JavaDoc
377   {
378     getMBeanServer().removeNotificationListener(observed, listener);
379   }
380
381   /**
382    * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
383    * javax.management.ObjectName)
384    */

385   public void removeNotificationListener(ObjectName JavaDoc observed,
386       ObjectName JavaDoc listener) throws InstanceNotFoundException JavaDoc,
387       ListenerNotFoundException JavaDoc
388   {
389     getMBeanServer().removeNotificationListener(observed, listener);
390   }
391
392   /**
393    * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
394    * javax.management.ObjectName, javax.management.NotificationFilter,
395    * java.lang.Object)
396    */

397   public void removeNotificationListener(ObjectName JavaDoc observed,
398       ObjectName JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
399       throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc
400   {
401     getMBeanServer().removeNotificationListener(observed, listener, filter,
402         handback);
403   }
404
405   /**
406    * @see javax.management.MBeanServerConnection#removeNotificationListener(javax.management.ObjectName,
407    * javax.management.NotificationListener,
408    * javax.management.NotificationFilter, java.lang.Object)
409    */

410   public void removeNotificationListener(ObjectName JavaDoc observed,
411       NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
412       throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc
413   {
414     getMBeanServer().removeNotificationListener(observed, listener, filter,
415         handback);
416   }
417
418   /**
419    * @see javax.management.MBeanServerConnection#setAttribute(javax.management.ObjectName,
420    * javax.management.Attribute)
421    */

422   public void setAttribute(ObjectName JavaDoc objectName, Attribute JavaDoc attribute)
423       throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc,
424       InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
425   {
426     getMBeanServer().setAttribute(objectName, attribute);
427   }
428
429   /**
430    * @see javax.management.MBeanServerConnection#setAttributes(javax.management.ObjectName,
431    * javax.management.AttributeList)
432    */

433   public AttributeList JavaDoc setAttributes(ObjectName JavaDoc objectName,
434       AttributeList JavaDoc attributes) throws InstanceNotFoundException JavaDoc,
435       ReflectionException JavaDoc
436   {
437     return getMBeanServer().setAttributes(objectName, attributes);
438   }
439
440   /**
441    * @see javax.management.MBeanServerConnection#unregisterMBean(javax.management.ObjectName)
442    */

443   public void unregisterMBean(ObjectName JavaDoc objectName)
444       throws InstanceNotFoundException JavaDoc, MBeanRegistrationException JavaDoc
445   {
446     getMBeanServer().unregisterMBean(objectName);
447   }
448
449   /**
450    * @see javax.management.MBeanServer#getClassLoaderFor(javax.management.ObjectName)
451    */

452   public ClassLoader JavaDoc getClassLoaderFor(ObjectName JavaDoc mbeanName)
453       throws InstanceNotFoundException JavaDoc
454   {
455     return getMBeanServer().getClassLoaderFor(mbeanName);
456   }
457
458   /**
459    * @see javax.management.MBeanServer#getClassLoader(javax.management.ObjectName)
460    */

461   public ClassLoader JavaDoc getClassLoader(ObjectName JavaDoc loaderName)
462       throws InstanceNotFoundException JavaDoc
463   {
464     return getMBeanServer().getClassLoader(loaderName);
465   }
466
467   /**
468    * @see javax.management.MBeanServer#getClassLoaderRepository()
469    */

470   public ClassLoaderRepository JavaDoc getClassLoaderRepository()
471   {
472     return getMBeanServer().getClassLoaderRepository();
473   }
474
475 }
476
Popular Tags