KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jmx > remote > HessianMBeanServerConnection


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jmx.remote;
31
32 import com.caucho.hessian.client.HessianProxyFactory;
33 import com.caucho.hessian.jmx.JMXSerializerFactory;
34 import com.caucho.util.L10N;
35 import com.caucho.util.Log;
36 import com.caucho.vfs.IOExceptionWrapper;
37
38 import javax.management.*;
39 import java.io.IOException JavaDoc;
40 import java.util.Set JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * Static convenience methods.
45  */

46 public class HessianMBeanServerConnection
47   implements MBeanServerConnection
48 {
49   private static final L10N L = new L10N(HessianMBeanServerConnection.class);
50   private static final Logger JavaDoc log = Log.open(HessianMBeanServerConnection.class);
51
52   private String JavaDoc _url;
53   private RemoteJMX _jmxProxy;
54
55   /**
56    * Creates the MBeanClient.
57    */

58   public HessianMBeanServerConnection()
59   {
60   }
61
62   /**
63    * Creates the MBeanClient.
64    */

65   public HessianMBeanServerConnection(String JavaDoc url)
66   {
67     _url = url;
68   }
69
70   /**
71    * Sets the proxy
72    */

73   public void setProxy(RemoteJMX proxy)
74   {
75     _jmxProxy = proxy;
76   }
77
78   /**
79    * Returns the mbean info
80    */

81   public MBeanInfo getMBeanInfo(ObjectName objectName)
82     throws InstanceNotFoundException, IntrospectionException,
83            ReflectionException, IOException JavaDoc
84   {
85     try {
86       return getProxy().getMBeanInfo(objectName.getCanonicalName());
87     }
88     catch (JMException ex) {
89       if (ex instanceof InstanceNotFoundException)
90         throw (InstanceNotFoundException) ex;
91
92       if (ex instanceof IntrospectionException)
93         throw (IntrospectionException) ex;
94
95       if (ex instanceof ReflectionException)
96         throw (ReflectionException) ex;
97
98       throw new RuntimeException JavaDoc(ex);
99     }
100   }
101
102   public boolean isInstanceOf(ObjectName name, String JavaDoc className)
103     throws InstanceNotFoundException, IOException JavaDoc
104   {
105
106     // XXX: unimplemented
107
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
108
109     return false;
110   }
111
112   /**
113    * Gets an attribute.
114    */

115   public Object JavaDoc getAttribute(ObjectName objectName, String JavaDoc attrName)
116     throws MBeanException, AttributeNotFoundException,
117            InstanceNotFoundException, ReflectionException,
118            IOException JavaDoc
119   {
120     try {
121       return getProxy().getAttribute(objectName.getCanonicalName(), attrName);
122     }
123     catch (JMException ex) {
124       if (ex instanceof MBeanException)
125         throw (MBeanException) ex;
126
127       if (ex instanceof AttributeNotFoundException)
128         throw (AttributeNotFoundException) ex;
129
130       if (ex instanceof InstanceNotFoundException)
131         throw (InstanceNotFoundException) ex;
132
133       if (ex instanceof ReflectionException)
134         throw (ReflectionException) ex;
135
136       throw new RuntimeException JavaDoc(ex);
137     }
138   }
139
140   public AttributeList getAttributes(ObjectName name, String JavaDoc[] attributes)
141     throws InstanceNotFoundException, ReflectionException, IOException JavaDoc
142   {
143
144     // XXX: unimplemented
145
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
146
147     return null;
148   }
149
150   public void setAttribute(ObjectName name, Attribute attribute)
151     throws
152     InstanceNotFoundException,
153     AttributeNotFoundException,
154     InvalidAttributeValueException,
155     MBeanException,
156     ReflectionException,
157     IOException JavaDoc
158   {
159
160     // XXX: unimplemented
161
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
162
163
164   }
165
166   public AttributeList setAttributes(ObjectName name, AttributeList attributes)
167     throws InstanceNotFoundException, ReflectionException, IOException JavaDoc
168   {
169
170     // XXX: unimplemented
171
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
172
173     return null;
174   }
175
176   public Object JavaDoc invoke(ObjectName name,
177                        String JavaDoc operationName,
178                        Object JavaDoc params[],
179                        String JavaDoc signature[])
180     throws
181     InstanceNotFoundException,
182     MBeanException,
183     ReflectionException,
184     IOException JavaDoc
185   {
186
187     // XXX: unimplemented
188
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
189
190     return null;
191   }
192
193   public String JavaDoc getDefaultDomain()
194     throws IOException JavaDoc
195   {
196
197     // XXX: unimplemented
198
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
199
200     return null;
201   }
202
203   public String JavaDoc[] getDomains()
204     throws IOException JavaDoc
205   {
206
207     // XXX: unimplemented
208
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
209
210     return new String JavaDoc[0];
211   }
212
213   public void addNotificationListener(ObjectName name,
214                                       NotificationListener listener,
215                                       NotificationFilter filter,
216                                       Object JavaDoc handback)
217     throws InstanceNotFoundException, IOException JavaDoc
218   {
219
220     // XXX: unimplemented
221
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
222
223
224   }
225
226   public void addNotificationListener(ObjectName name,
227                                       ObjectName listener,
228                                       NotificationFilter filter,
229                                       Object JavaDoc handback)
230     throws InstanceNotFoundException, IOException JavaDoc
231   {
232
233     // XXX: unimplemented
234
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
235
236
237   }
238
239   public void removeNotificationListener(ObjectName name, ObjectName listener)
240     throws InstanceNotFoundException, ListenerNotFoundException, IOException JavaDoc
241   {
242
243     // XXX: unimplemented
244
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
245
246
247   }
248
249   public void removeNotificationListener(ObjectName name,
250                                          ObjectName listener,
251                                          NotificationFilter filter,
252                                          Object JavaDoc handback)
253     throws InstanceNotFoundException, ListenerNotFoundException, IOException JavaDoc
254   {
255
256     // XXX: unimplemented
257
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
258
259
260   }
261
262   public void removeNotificationListener(ObjectName name,
263                                          NotificationListener listener)
264     throws InstanceNotFoundException, ListenerNotFoundException, IOException JavaDoc
265   {
266
267     // XXX: unimplemented
268
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
269
270
271   }
272
273   public void removeNotificationListener(ObjectName name,
274                                          NotificationListener listener,
275                                          NotificationFilter filter,
276                                          Object JavaDoc handback)
277     throws InstanceNotFoundException, ListenerNotFoundException, IOException JavaDoc
278   {
279
280     // XXX: unimplemented
281
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
282
283
284   }
285
286   public ObjectInstance createMBean(String JavaDoc className, ObjectName name)
287     throws
288     ReflectionException,
289     InstanceAlreadyExistsException,
290     MBeanRegistrationException,
291     MBeanException,
292     NotCompliantMBeanException,
293     IOException JavaDoc
294   {
295     // XXX: unimplemented
296
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
297
298     return null;
299   }
300
301   public ObjectInstance createMBean(String JavaDoc className,
302                                     ObjectName name,
303                                     ObjectName loaderName)
304     throws
305     ReflectionException,
306     InstanceAlreadyExistsException,
307     MBeanRegistrationException,
308     MBeanException,
309     NotCompliantMBeanException,
310     InstanceNotFoundException,
311     IOException JavaDoc
312   {
313
314     // XXX: unimplemented
315
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
316
317     return null;
318   }
319
320   public ObjectInstance createMBean(String JavaDoc className,
321                                     ObjectName name,
322                                     Object JavaDoc params[],
323                                     String JavaDoc signature[])
324     throws
325     ReflectionException,
326     InstanceAlreadyExistsException,
327     MBeanRegistrationException,
328     MBeanException,
329     NotCompliantMBeanException,
330     IOException JavaDoc
331   {
332
333     // XXX: unimplemented
334
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
335
336     return null;
337   }
338
339   public ObjectInstance createMBean(String JavaDoc className,
340                                     ObjectName name,
341                                     ObjectName loaderName,
342                                     Object JavaDoc params[],
343                                     String JavaDoc signature[])
344     throws
345     ReflectionException,
346     InstanceAlreadyExistsException,
347     MBeanRegistrationException,
348     MBeanException,
349     NotCompliantMBeanException,
350     InstanceNotFoundException,
351     IOException JavaDoc
352   {
353
354     // XXX: unimplemented
355
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
356
357     return null;
358   }
359
360   public void unregisterMBean(ObjectName name)
361     throws InstanceNotFoundException, MBeanRegistrationException, IOException JavaDoc
362   {
363
364     // XXX: unimplemented
365
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
366
367
368   }
369
370   /**
371    * Returns the object instance
372    */

373   public ObjectInstance getObjectInstance(ObjectName objectName)
374     throws InstanceNotFoundException, IOException JavaDoc
375   {
376     MBeanInfo info = null;
377
378     try {
379       info = getMBeanInfo(objectName);
380     }
381     catch (IntrospectionException e) {
382       throw new IOExceptionWrapper(e);
383     }
384     catch (ReflectionException e) {
385       throw new IOExceptionWrapper(e);
386     }
387
388     String JavaDoc className = info.getClassName();
389
390     return new ObjectInstance(objectName, className);
391   }
392
393   public Set JavaDoc queryMBeans(ObjectName name, QueryExp query)
394     throws IOException JavaDoc
395   {
396
397     // XXX: unimplemented
398
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
399
400     return null;
401   }
402
403   public Set JavaDoc queryNames(ObjectName name, QueryExp query)
404     throws IOException JavaDoc
405   {
406
407     // XXX: unimplemented
408
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
409
410     return null;
411   }
412
413   public boolean isRegistered(ObjectName name)
414     throws IOException JavaDoc
415   {
416     return true;
417   }
418
419   public Integer JavaDoc getMBeanCount()
420     throws IOException JavaDoc
421   {
422
423     // XXX: unimplemented
424
if (true) throw new UnsupportedOperationException JavaDoc("unimplemented");
425
426     return null;
427   }
428
429   private RemoteJMX getProxy()
430   {
431     if (_jmxProxy == null) {
432       try {
433         HessianProxyFactory proxy = new HessianProxyFactory();
434         proxy.getSerializerFactory().addFactory(new JMXSerializerFactory());
435         _jmxProxy = (RemoteJMX) proxy.create(_url);
436       } catch (Exception JavaDoc e) {
437         throw new RuntimeException JavaDoc(e);
438       }
439     }
440
441     return _jmxProxy;
442   }
443 }
444
445
Popular Tags