KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > jmx > KernelDelegate


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.system.jmx;
18
19 import java.util.Date JavaDoc;
20 import java.util.Set JavaDoc;
21 import javax.management.AttributeNotFoundException JavaDoc;
22 import javax.management.InstanceNotFoundException JavaDoc;
23 import javax.management.JMException JavaDoc;
24 import javax.management.JMRuntimeException JavaDoc;
25 import javax.management.MBeanServerConnection JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27
28 import org.apache.geronimo.gbean.GBeanData;
29 import org.apache.geronimo.gbean.GBeanInfo;
30 import org.apache.geronimo.gbean.AbstractName;
31 import org.apache.geronimo.gbean.AbstractNameQuery;
32 import org.apache.geronimo.kernel.DependencyManager;
33 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
34 import org.apache.geronimo.kernel.GBeanNotFoundException;
35 import org.apache.geronimo.kernel.InternalKernelException;
36 import org.apache.geronimo.kernel.Kernel;
37 import org.apache.geronimo.kernel.NoSuchAttributeException;
38 import org.apache.geronimo.kernel.NoSuchOperationException;
39 import org.apache.geronimo.kernel.Naming;
40 import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor;
41 import org.apache.geronimo.kernel.proxy.ProxyManager;
42
43 /**
44  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
45  */

46 public class KernelDelegate implements Kernel {
47     private final MBeanServerConnection JavaDoc mbeanServer;
48     private final ProxyManager proxyManager;
49
50     public KernelDelegate(MBeanServerConnection JavaDoc mbeanServer) {
51         this.mbeanServer = mbeanServer;
52         proxyManager = new JMXProxyManager(this);
53     }
54
55     public Date JavaDoc getBootTime() {
56         return (Date JavaDoc) getKernelAttribute("bootTime");
57     }
58
59     public String JavaDoc getKernelName() {
60         return (String JavaDoc) getKernelAttribute("kernelName");
61     }
62
63     public Naming getNaming() {
64         return (Naming) getKernelAttribute("naming");
65     }
66
67     public Object JavaDoc getGBean(ObjectName JavaDoc name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
68         try {
69             return invokeKernel("getGBean", new Object JavaDoc[] {name}, new String JavaDoc[] {ObjectName JavaDoc.class.getName()});
70         } catch (GBeanNotFoundException e) {
71             throw e;
72         } catch (RuntimeException JavaDoc e) {
73             throw e;
74         } catch (Exception JavaDoc e) {
75             throw new InternalKernelException(e);
76         }
77     }
78
79     public Object JavaDoc getGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
80         try {
81             return invokeKernel("getGBean", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
82         } catch (GBeanNotFoundException e) {
83             throw e;
84         } catch (RuntimeException JavaDoc e) {
85             throw e;
86         } catch (Exception JavaDoc e) {
87             throw new InternalKernelException(e);
88         }
89     }
90
91     public Object JavaDoc getGBean(String JavaDoc shortName) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
92         try {
93             return invokeKernel("getGBean", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
94         } catch (GBeanNotFoundException e) {
95             throw e;
96         } catch (RuntimeException JavaDoc e) {
97             throw e;
98         } catch (Exception JavaDoc e) {
99             throw new InternalKernelException(e);
100         }
101     }
102
103     public Object JavaDoc getGBean(Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
104         try {
105             return invokeKernel("getGBean", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
106         } catch (GBeanNotFoundException e) {
107             throw e;
108         } catch (RuntimeException JavaDoc e) {
109             throw e;
110         } catch (Exception JavaDoc e) {
111             throw new InternalKernelException(e);
112         }
113     }
114
115     public Object JavaDoc getGBean(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
116         try {
117             return invokeKernel("getGBean", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
118         } catch (GBeanNotFoundException e) {
119             throw e;
120         } catch (RuntimeException JavaDoc e) {
121             throw e;
122         } catch (Exception JavaDoc e) {
123             throw new InternalKernelException(e);
124         }
125     }
126
127     public void loadGBean(GBeanData gbeanData, ClassLoader JavaDoc classLoader) throws GBeanAlreadyExistsException {
128         try {
129             invokeKernel("loadGBean", new Object JavaDoc[] {gbeanData, classLoader}, new String JavaDoc[] {GBeanData.class.getName(), ClassLoader JavaDoc.class.getName()});
130         } catch (GBeanAlreadyExistsException e) {
131             throw e;
132         } catch (RuntimeException JavaDoc e) {
133             throw e;
134         } catch (Exception JavaDoc e) {
135             throw new InternalKernelException(e);
136         }
137     }
138
139     public void startGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
140         try {
141             invokeKernel("startGBean", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
142         } catch (GBeanNotFoundException e) {
143             throw e;
144         } catch (RuntimeException JavaDoc e) {
145             throw e;
146         } catch (Exception JavaDoc e) {
147             throw new InternalKernelException(e);
148         }
149     }
150
151     public void startGBean(String JavaDoc shortName) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
152         try {
153             invokeKernel("startGBean", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
154         } catch (GBeanNotFoundException e) {
155             throw e;
156         } catch (RuntimeException JavaDoc e) {
157             throw e;
158         } catch (Exception JavaDoc e) {
159             throw new InternalKernelException(e);
160         }
161     }
162
163     public void startGBean(Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
164         try {
165             invokeKernel("startGBean", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
166         } catch (GBeanNotFoundException e) {
167             throw e;
168         } catch (RuntimeException JavaDoc e) {
169             throw e;
170         } catch (Exception JavaDoc e) {
171             throw new InternalKernelException(e);
172         }
173     }
174
175     public void startGBean(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
176         try {
177             invokeKernel("startGBean", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
178         } catch (GBeanNotFoundException e) {
179             throw e;
180         } catch (RuntimeException JavaDoc e) {
181             throw e;
182         } catch (Exception JavaDoc e) {
183             throw new InternalKernelException(e);
184         }
185     }
186
187     public void startRecursiveGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
188         try {
189             invokeKernel("startRecursiveGBean", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
190         } catch (GBeanNotFoundException e) {
191             throw e;
192         } catch (RuntimeException JavaDoc e) {
193             throw e;
194         } catch (Exception JavaDoc e) {
195             throw new InternalKernelException(e);
196         }
197     }
198
199     public void startRecursiveGBean(String JavaDoc shortName) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
200         try {
201             invokeKernel("startRecursiveGBean", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
202         } catch (GBeanNotFoundException e) {
203             throw e;
204         } catch (RuntimeException JavaDoc e) {
205             throw e;
206         } catch (Exception JavaDoc e) {
207             throw new InternalKernelException(e);
208         }
209     }
210
211     public void startRecursiveGBean(Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
212         try {
213             invokeKernel("startRecursiveGBean", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
214         } catch (GBeanNotFoundException e) {
215             throw e;
216         } catch (RuntimeException JavaDoc e) {
217             throw e;
218         } catch (Exception JavaDoc e) {
219             throw new InternalKernelException(e);
220         }
221     }
222
223     public void startRecursiveGBean(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
224         try {
225             invokeKernel("startRecursiveGBean", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
226         } catch (GBeanNotFoundException e) {
227             throw e;
228         } catch (RuntimeException JavaDoc e) {
229             throw e;
230         } catch (Exception JavaDoc e) {
231             throw new InternalKernelException(e);
232         }
233     }
234
235     public boolean isRunning(AbstractName name) {
236         try {
237             return ((Boolean JavaDoc) invokeKernel("isRunning", new Object JavaDoc[]{name}, new String JavaDoc[]{AbstractName.class.getName()})).booleanValue();
238         } catch (RuntimeException JavaDoc e) {
239             throw e;
240         } catch (Exception JavaDoc e) {
241             throw new InternalKernelException(e);
242         }
243      }
244
245     public boolean isRunning(String JavaDoc shortName) {
246         try {
247             return ((Boolean JavaDoc) invokeKernel("isRunning", new Object JavaDoc[]{shortName}, new String JavaDoc[]{String JavaDoc.class.getName()})).booleanValue();
248         } catch (RuntimeException JavaDoc e) {
249             throw e;
250         } catch (Exception JavaDoc e) {
251             throw new InternalKernelException(e);
252         }
253     }
254
255     public boolean isRunning(Class JavaDoc type) {
256         try {
257             return ((Boolean JavaDoc) invokeKernel("isRunning", new Object JavaDoc[]{type}, new String JavaDoc[]{Class JavaDoc.class.getName()})).booleanValue();
258         } catch (RuntimeException JavaDoc e) {
259             throw e;
260         } catch (Exception JavaDoc e) {
261             throw new InternalKernelException(e);
262         }
263     }
264
265     public boolean isRunning(String JavaDoc shortName, Class JavaDoc type) {
266         try {
267             return ((Boolean JavaDoc) invokeKernel("isRunning", new Object JavaDoc[]{shortName, type}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName()})).booleanValue();
268         } catch (RuntimeException JavaDoc e) {
269             throw e;
270         } catch (Exception JavaDoc e) {
271             throw new InternalKernelException(e);
272         }
273     }
274
275
276     public void stopGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
277         try {
278             invokeKernel("stopGBean", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
279         } catch (GBeanNotFoundException e) {
280             throw e;
281         } catch (RuntimeException JavaDoc e) {
282             throw e;
283         } catch (Exception JavaDoc e) {
284             throw new InternalKernelException(e);
285         }
286     }
287
288     public void stopGBean(String JavaDoc shortName) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
289         try {
290             invokeKernel("stopGBean", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
291         } catch (GBeanNotFoundException e) {
292             throw e;
293         } catch (RuntimeException JavaDoc e) {
294             throw e;
295         } catch (Exception JavaDoc e) {
296             throw new InternalKernelException(e);
297         }
298     }
299
300     public void stopGBean(Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
301         try {
302             invokeKernel("stopGBean", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
303         } catch (GBeanNotFoundException e) {
304             throw e;
305         } catch (RuntimeException JavaDoc e) {
306             throw e;
307         } catch (Exception JavaDoc e) {
308             throw new InternalKernelException(e);
309         }
310     }
311
312     public void stopGBean(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
313         try {
314             invokeKernel("stopGBean", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
315         } catch (GBeanNotFoundException e) {
316             throw e;
317         } catch (RuntimeException JavaDoc e) {
318             throw e;
319         } catch (Exception JavaDoc e) {
320             throw new InternalKernelException(e);
321         }
322     }
323
324     public void unloadGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
325         try {
326             invokeKernel("unloadGBean", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
327         } catch (GBeanNotFoundException e) {
328             throw e;
329         } catch (RuntimeException JavaDoc e) {
330             throw e;
331         } catch (Exception JavaDoc e) {
332             throw new InternalKernelException(e);
333         }
334     }
335
336     public void unloadGBean(String JavaDoc shortName) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
337         try {
338             invokeKernel("unloadGBean", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
339         } catch (GBeanNotFoundException e) {
340             throw e;
341         } catch (RuntimeException JavaDoc e) {
342             throw e;
343         } catch (Exception JavaDoc e) {
344             throw new InternalKernelException(e);
345         }
346     }
347
348     public void unloadGBean(Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
349         try {
350             invokeKernel("unloadGBean", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
351         } catch (GBeanNotFoundException e) {
352             throw e;
353         } catch (RuntimeException JavaDoc e) {
354             throw e;
355         } catch (Exception JavaDoc e) {
356             throw new InternalKernelException(e);
357         }
358     }
359
360     public void unloadGBean(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException, IllegalStateException JavaDoc {
361         try {
362             invokeKernel("unloadGBean", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
363         } catch (GBeanNotFoundException e) {
364             throw e;
365         } catch (RuntimeException JavaDoc e) {
366             throw e;
367         } catch (Exception JavaDoc e) {
368             throw new InternalKernelException(e);
369         }
370     }
371
372     public int getGBeanState(ObjectName JavaDoc name) throws GBeanNotFoundException {
373         try {
374             return ((Integer JavaDoc) invokeKernel("getGBeanState", new Object JavaDoc[]{name}, new String JavaDoc[]{ObjectName JavaDoc.class.getName()})).intValue();
375         } catch (GBeanNotFoundException e) {
376             throw e;
377         } catch (RuntimeException JavaDoc e) {
378             throw e;
379         } catch (Exception JavaDoc e) {
380             throw new InternalKernelException(e);
381         }
382     }
383
384     public int getGBeanState(AbstractName name) throws GBeanNotFoundException {
385         try {
386             return ((Integer JavaDoc) invokeKernel("getGBeanState", new Object JavaDoc[]{name}, new String JavaDoc[]{AbstractName.class.getName()})).intValue();
387         } catch (GBeanNotFoundException e) {
388             throw e;
389         } catch (RuntimeException JavaDoc e) {
390             throw e;
391         } catch (Exception JavaDoc e) {
392             throw new InternalKernelException(e);
393         }
394     }
395
396     public int getGBeanState(String JavaDoc shortName) throws GBeanNotFoundException {
397         try {
398             return ((Integer JavaDoc) invokeKernel("getGBeanState", new Object JavaDoc[]{shortName}, new String JavaDoc[]{String JavaDoc.class.getName()})).intValue();
399         } catch (GBeanNotFoundException e) {
400             throw e;
401         } catch (RuntimeException JavaDoc e) {
402             throw e;
403         } catch (Exception JavaDoc e) {
404             throw new InternalKernelException(e);
405         }
406     }
407
408     public int getGBeanState(Class JavaDoc type) throws GBeanNotFoundException {
409         try {
410             return ((Integer JavaDoc) invokeKernel("getGBeanState", new Object JavaDoc[]{type}, new String JavaDoc[]{Class JavaDoc.class.getName()})).intValue();
411         } catch (GBeanNotFoundException e) {
412             throw e;
413         } catch (RuntimeException JavaDoc e) {
414             throw e;
415         } catch (Exception JavaDoc e) {
416             throw new InternalKernelException(e);
417         }
418     }
419
420     public int getGBeanState(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException {
421         try {
422             return ((Integer JavaDoc) invokeKernel("getGBeanState", new Object JavaDoc[]{shortName, type}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName()})).intValue();
423         } catch (GBeanNotFoundException e) {
424             throw e;
425         } catch (RuntimeException JavaDoc e) {
426             throw e;
427         } catch (Exception JavaDoc e) {
428             throw new InternalKernelException(e);
429         }
430     }
431
432     public long getGBeanStartTime(AbstractName name) throws GBeanNotFoundException {
433         try {
434             return ((Long JavaDoc) invokeKernel("getGBeanStartTime", new Object JavaDoc[]{name}, new String JavaDoc[]{AbstractName.class.getName()})).longValue();
435         } catch (GBeanNotFoundException e) {
436             throw e;
437         } catch (RuntimeException JavaDoc e) {
438             throw e;
439         } catch (Exception JavaDoc e) {
440             throw new InternalKernelException(e);
441         }
442     }
443
444     public long getGBeanStartTime(String JavaDoc shortName) throws GBeanNotFoundException {
445         try {
446             return ((Long JavaDoc) invokeKernel("getGBeanStartTime", new Object JavaDoc[]{shortName}, new String JavaDoc[]{String JavaDoc.class.getName()})).longValue();
447         } catch (GBeanNotFoundException e) {
448             throw e;
449         } catch (RuntimeException JavaDoc e) {
450             throw e;
451         } catch (Exception JavaDoc e) {
452             throw new InternalKernelException(e);
453         }
454     }
455
456     public long getGBeanStartTime(Class JavaDoc type) throws GBeanNotFoundException {
457         try {
458             return ((Long JavaDoc) invokeKernel("getGBeanStartTime", new Object JavaDoc[]{type}, new String JavaDoc[]{Class JavaDoc.class.getName()})).longValue();
459         } catch (GBeanNotFoundException e) {
460             throw e;
461         } catch (RuntimeException JavaDoc e) {
462             throw e;
463         } catch (Exception JavaDoc e) {
464             throw new InternalKernelException(e);
465         }
466     }
467
468     public long getGBeanStartTime(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException {
469         try {
470             return ((Long JavaDoc) invokeKernel("getGBeanStartTime", new Object JavaDoc[]{shortName, type}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName()})).longValue();
471         } catch (GBeanNotFoundException e) {
472             throw e;
473         } catch (RuntimeException JavaDoc e) {
474             throw e;
475         } catch (Exception JavaDoc e) {
476             throw new InternalKernelException(e);
477         }
478     }
479
480     public Object JavaDoc getAttribute(ObjectName JavaDoc objectName, String JavaDoc attributeName) throws Exception JavaDoc {
481         return invokeKernel("getAttribute", new Object JavaDoc[]{objectName, attributeName}, new String JavaDoc[]{ObjectName JavaDoc.class.getName(), String JavaDoc.class.getName()});
482     }
483
484     public Object JavaDoc getAttribute(AbstractName abstractName, String JavaDoc attributeName) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
485         return invokeKernel("getAttribute", new Object JavaDoc[]{abstractName, attributeName}, new String JavaDoc[]{AbstractName.class.getName(), String JavaDoc.class.getName()});
486     }
487
488     public Object JavaDoc getAttribute(String JavaDoc shortName, String JavaDoc attributeName) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
489         return invokeKernel("getAttribute", new Object JavaDoc[]{shortName, attributeName}, new String JavaDoc[]{String JavaDoc.class.getName(), String JavaDoc.class.getName()});
490     }
491
492     public Object JavaDoc getAttribute(Class JavaDoc type, String JavaDoc attributeName) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
493         return invokeKernel("getAttribute", new Object JavaDoc[]{type, attributeName}, new String JavaDoc[]{Class JavaDoc.class.getName(), String JavaDoc.class.getName()});
494     }
495
496     public Object JavaDoc getAttribute(String JavaDoc shortName, Class JavaDoc type, String JavaDoc attributeName) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
497         return invokeKernel("getAttribute", new Object JavaDoc[]{shortName, type, attributeName}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName(), String JavaDoc.class.getName()});
498     }
499
500     public void setAttribute(AbstractName abstractName, String JavaDoc attributeName, Object JavaDoc attributeValue) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
501         invokeKernel("setAttribute", new Object JavaDoc[]{abstractName, attributeName, attributeValue}, new String JavaDoc[]{AbstractName.class.getName(), String JavaDoc.class.getName(), Object JavaDoc.class.getName()});
502     }
503
504     public void setAttribute(String JavaDoc shortName, String JavaDoc attributeName, Object JavaDoc attributeValue) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
505         invokeKernel("setAttribute", new Object JavaDoc[]{shortName, attributeName, attributeValue}, new String JavaDoc[]{String JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc.class.getName()});
506     }
507
508     public void setAttribute(Class JavaDoc type, String JavaDoc attributeName, Object JavaDoc attributeValue) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
509         invokeKernel("setAttribute", new Object JavaDoc[]{type, attributeName, attributeValue}, new String JavaDoc[]{Class JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc.class.getName()});
510     }
511
512     public void setAttribute(String JavaDoc shortName, Class JavaDoc type, String JavaDoc attributeName, Object JavaDoc attributeValue) throws GBeanNotFoundException, NoSuchAttributeException, Exception JavaDoc {
513         invokeKernel("setAttribute", new Object JavaDoc[]{shortName, type, attributeName, attributeValue}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc.class.getName()});
514     }
515
516     public Object JavaDoc invoke(ObjectName JavaDoc objectName, String JavaDoc methodName) throws Exception JavaDoc {
517         return invokeKernel("invoke", new Object JavaDoc[]{objectName, methodName}, new String JavaDoc[]{ObjectName JavaDoc.class.getName(), String JavaDoc.class.getName()});
518     }
519
520     public Object JavaDoc invoke(AbstractName abstractName, String JavaDoc methodName) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
521         return invokeKernel("invoke", new Object JavaDoc[]{abstractName, methodName}, new String JavaDoc[]{AbstractName.class.getName(), String JavaDoc.class.getName()});
522     }
523
524     public Object JavaDoc invoke(String JavaDoc shortName, String JavaDoc methodName) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
525         return invokeKernel("invoke", new Object JavaDoc[]{shortName, methodName}, new String JavaDoc[]{String JavaDoc.class.getName(), String JavaDoc.class.getName()});
526     }
527
528     public Object JavaDoc invoke(Class JavaDoc type, String JavaDoc methodName) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
529         return invokeKernel("invoke", new Object JavaDoc[]{type, methodName}, new String JavaDoc[]{Class JavaDoc.class.getName(), String JavaDoc.class.getName()});
530     }
531
532     public Object JavaDoc invoke(String JavaDoc shortName, Class JavaDoc type, String JavaDoc methodName) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
533         return invokeKernel("invoke", new Object JavaDoc[]{shortName, type, methodName}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName(), String JavaDoc.class.getName()});
534     }
535
536     public Object JavaDoc invoke(ObjectName JavaDoc objectName, String JavaDoc methodName, Object JavaDoc[] args, String JavaDoc[] types) throws Exception JavaDoc {
537         return invokeKernel("invoke", new Object JavaDoc[]{objectName, methodName, args, types}, new String JavaDoc[]{ObjectName JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc[].class.getName(), String JavaDoc[].class.getName()});
538     }
539
540     public Object JavaDoc invoke(AbstractName abstractName, String JavaDoc methodName, Object JavaDoc[] args, String JavaDoc[] types) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
541         return invokeKernel("invoke", new Object JavaDoc[]{abstractName, methodName, args, types}, new String JavaDoc[]{AbstractName.class.getName(), String JavaDoc.class.getName(), Object JavaDoc[].class.getName(), String JavaDoc[].class.getName()});
542     }
543
544     public Object JavaDoc invoke(String JavaDoc shortName, String JavaDoc methodName, Object JavaDoc[] args, String JavaDoc[] types) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
545         return invokeKernel("invoke", new Object JavaDoc[]{shortName, methodName, args, types}, new String JavaDoc[]{String JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc[].class.getName(), String JavaDoc[].class.getName()});
546     }
547
548     public Object JavaDoc invoke(Class JavaDoc type, String JavaDoc methodName, Object JavaDoc[] args, String JavaDoc[] types) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
549         return invokeKernel("invoke", new Object JavaDoc[]{type, methodName, args, types}, new String JavaDoc[]{Class JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc[].class.getName(), String JavaDoc[].class.getName()});
550     }
551
552     public Object JavaDoc invoke(String JavaDoc shortName, Class JavaDoc type, String JavaDoc methodName, Object JavaDoc[] args, String JavaDoc[] types) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception JavaDoc {
553         return invokeKernel("invoke", new Object JavaDoc[]{shortName, type, methodName, args, types}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName(), String JavaDoc.class.getName(), Object JavaDoc[].class.getName(), String JavaDoc[].class.getName()});
554     }
555
556     public boolean isLoaded(AbstractName name) {
557         try {
558             return ((Boolean JavaDoc) invokeKernel("isLoaded", new Object JavaDoc[]{name}, new String JavaDoc[]{AbstractName.class.getName()})).booleanValue();
559         } catch (RuntimeException JavaDoc e) {
560             throw e;
561         } catch (Exception JavaDoc e) {
562             throw new InternalKernelException(e);
563         }
564      }
565
566     public boolean isLoaded(String JavaDoc shortName) {
567         try {
568             return ((Boolean JavaDoc) invokeKernel("isLoaded", new Object JavaDoc[]{shortName}, new String JavaDoc[]{String JavaDoc.class.getName()})).booleanValue();
569         } catch (RuntimeException JavaDoc e) {
570             throw e;
571         } catch (Exception JavaDoc e) {
572             throw new InternalKernelException(e);
573         }
574     }
575
576     public boolean isLoaded(Class JavaDoc type) {
577         try {
578             return ((Boolean JavaDoc) invokeKernel("isLoaded", new Object JavaDoc[]{type}, new String JavaDoc[]{Class JavaDoc.class.getName()})).booleanValue();
579         } catch (RuntimeException JavaDoc e) {
580             throw e;
581         } catch (Exception JavaDoc e) {
582             throw new InternalKernelException(e);
583         }
584     }
585
586     public boolean isLoaded(String JavaDoc shortName, Class JavaDoc type) {
587         try {
588             return ((Boolean JavaDoc) invokeKernel("isLoaded", new Object JavaDoc[]{shortName, type}, new String JavaDoc[]{String JavaDoc.class.getName(), Class JavaDoc.class.getName()})).booleanValue();
589         } catch (RuntimeException JavaDoc e) {
590             throw e;
591         } catch (Exception JavaDoc e) {
592             throw new InternalKernelException(e);
593         }
594     }
595
596     public GBeanInfo getGBeanInfo(ObjectName JavaDoc name) throws GBeanNotFoundException {
597         try {
598             return (GBeanInfo) invokeKernel("getGBeanInfo", new Object JavaDoc[] {name}, new String JavaDoc[] {ObjectName JavaDoc.class.getName()});
599         } catch (GBeanNotFoundException e) {
600             throw e;
601         } catch (RuntimeException JavaDoc e) {
602             throw e;
603         } catch (Exception JavaDoc e) {
604             throw new InternalKernelException(e);
605         }
606     }
607
608     public GBeanInfo getGBeanInfo(AbstractName name) throws GBeanNotFoundException {
609         try {
610             return (GBeanInfo) invokeKernel("getGBeanInfo", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
611         } catch (GBeanNotFoundException e) {
612             throw e;
613         } catch (RuntimeException JavaDoc e) {
614             throw e;
615         } catch (Exception JavaDoc e) {
616             throw new InternalKernelException(e);
617         }
618     }
619
620     public GBeanInfo getGBeanInfo(String JavaDoc shortName) throws GBeanNotFoundException {
621         try {
622             return (GBeanInfo) invokeKernel("getGBeanInfo", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
623         } catch (GBeanNotFoundException e) {
624             throw e;
625         } catch (RuntimeException JavaDoc e) {
626             throw e;
627         } catch (Exception JavaDoc e) {
628             throw new InternalKernelException(e);
629         }
630     }
631
632     public GBeanInfo getGBeanInfo(Class JavaDoc type) throws GBeanNotFoundException {
633         try {
634             return (GBeanInfo) invokeKernel("getGBeanInfo", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
635         } catch (GBeanNotFoundException e) {
636             throw e;
637         } catch (RuntimeException JavaDoc e) {
638             throw e;
639         } catch (Exception JavaDoc e) {
640             throw new InternalKernelException(e);
641         }
642     }
643
644     public GBeanInfo getGBeanInfo(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException {
645         try {
646             return (GBeanInfo) invokeKernel("getGBeanInfo", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
647         } catch (GBeanNotFoundException e) {
648             throw e;
649         } catch (RuntimeException JavaDoc e) {
650             throw e;
651         } catch (Exception JavaDoc e) {
652             throw new InternalKernelException(e);
653         }
654     }
655
656     public Set JavaDoc listGBeans(ObjectName JavaDoc pattern) {
657         try {
658             return (Set JavaDoc) invokeKernel("listGBeans", new Object JavaDoc[] {pattern}, new String JavaDoc[] {ObjectName JavaDoc.class.getName()});
659         } catch (RuntimeException JavaDoc e) {
660             throw e;
661         } catch (Exception JavaDoc e) {
662             throw new InternalKernelException(e);
663         }
664     }
665
666     public Set JavaDoc listGBeans(Set JavaDoc patterns) {
667         try {
668             return (Set JavaDoc) invokeKernel("listGBeans", new Object JavaDoc[] {patterns}, new String JavaDoc[] {Set JavaDoc.class.getName()});
669         } catch (RuntimeException JavaDoc e) {
670             throw e;
671         } catch (Exception JavaDoc e) {
672             throw new InternalKernelException(e);
673         }
674     }
675
676     public void registerShutdownHook(Runnable JavaDoc hook) {
677         try {
678             invokeKernel("registerShutdownHook", new Object JavaDoc[] {hook}, new String JavaDoc[] {Runnable JavaDoc.class.getName()});
679         } catch (RuntimeException JavaDoc e) {
680             throw e;
681         } catch (Exception JavaDoc e) {
682             throw new InternalKernelException(e);
683         }
684     }
685
686     public void unregisterShutdownHook(Runnable JavaDoc hook) {
687         try {
688             invokeKernel("unregisterShutdownHook", new Object JavaDoc[] {hook}, new String JavaDoc[] {Runnable JavaDoc.class.getName()});
689         } catch (RuntimeException JavaDoc e) {
690             throw e;
691         } catch (Exception JavaDoc e) {
692             throw new InternalKernelException(e);
693         }
694     }
695
696     public void shutdown() {
697         try {
698             invokeKernel("shutdown", new Object JavaDoc[] {}, new String JavaDoc[] {});
699         } catch (RuntimeException JavaDoc e) {
700             throw e;
701         } catch (Exception JavaDoc e) {
702             throw new InternalKernelException(e);
703         }
704     }
705
706     public ClassLoader JavaDoc getClassLoaderFor(AbstractName name) throws GBeanNotFoundException {
707         try {
708             return (ClassLoader JavaDoc) invokeKernel("getClassLoaderFor", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
709         } catch (GBeanNotFoundException e) {
710             throw e;
711         } catch (RuntimeException JavaDoc e) {
712             throw e;
713         } catch (Exception JavaDoc e) {
714             throw new InternalKernelException(e);
715         }
716     }
717
718     public ClassLoader JavaDoc getClassLoaderFor(String JavaDoc shortName) throws GBeanNotFoundException {
719         try {
720             return (ClassLoader JavaDoc) invokeKernel("getClassLoaderFor", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
721         } catch (GBeanNotFoundException e) {
722             throw e;
723         } catch (RuntimeException JavaDoc e) {
724             throw e;
725         } catch (Exception JavaDoc e) {
726             throw new InternalKernelException(e);
727         }
728     }
729
730     public ClassLoader JavaDoc getClassLoaderFor(Class JavaDoc type) throws GBeanNotFoundException {
731         try {
732             return (ClassLoader JavaDoc) invokeKernel("getClassLoaderFor", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
733         } catch (GBeanNotFoundException e) {
734             throw e;
735         } catch (RuntimeException JavaDoc e) {
736             throw e;
737         } catch (Exception JavaDoc e) {
738             throw new InternalKernelException(e);
739         }
740     }
741
742     public ClassLoader JavaDoc getClassLoaderFor(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException {
743         try {
744             return (ClassLoader JavaDoc) invokeKernel("getClassLoaderFor", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
745         } catch (GBeanNotFoundException e) {
746             throw e;
747         } catch (RuntimeException JavaDoc e) {
748             throw e;
749         } catch (Exception JavaDoc e) {
750             throw new InternalKernelException(e);
751         }
752     }
753
754     public GBeanData getGBeanData(AbstractName name) throws GBeanNotFoundException, InternalKernelException {
755         try {
756             return (GBeanData) invokeKernel("getGBeanData", new Object JavaDoc[] {name}, new String JavaDoc[] {AbstractName.class.getName()});
757         } catch (GBeanNotFoundException e) {
758             throw e;
759         } catch (RuntimeException JavaDoc e) {
760             throw e;
761         } catch (Exception JavaDoc e) {
762             throw new InternalKernelException(e);
763         }
764     }
765
766     public GBeanData getGBeanData(String JavaDoc shortName) throws GBeanNotFoundException, InternalKernelException {
767         try {
768             return (GBeanData) invokeKernel("getGBeanData", new Object JavaDoc[] {shortName}, new String JavaDoc[] {String JavaDoc.class.getName()});
769         } catch (GBeanNotFoundException e) {
770             throw e;
771         } catch (RuntimeException JavaDoc e) {
772             throw e;
773         } catch (Exception JavaDoc e) {
774             throw new InternalKernelException(e);
775         }
776     }
777
778     public GBeanData getGBeanData(Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException {
779         try {
780             return (GBeanData) invokeKernel("getGBeanData", new Object JavaDoc[] {type}, new String JavaDoc[] {Class JavaDoc.class.getName()});
781         } catch (GBeanNotFoundException e) {
782             throw e;
783         } catch (RuntimeException JavaDoc e) {
784             throw e;
785         } catch (Exception JavaDoc e) {
786             throw new InternalKernelException(e);
787         }
788     }
789
790     public GBeanData getGBeanData(String JavaDoc shortName, Class JavaDoc type) throws GBeanNotFoundException, InternalKernelException {
791         try {
792             return (GBeanData) invokeKernel("getGBeanData", new Object JavaDoc[] {shortName, type}, new String JavaDoc[] {String JavaDoc.class.getName(), Class JavaDoc.class.getName()});
793         } catch (GBeanNotFoundException e) {
794             throw e;
795         } catch (RuntimeException JavaDoc e) {
796             throw e;
797         } catch (Exception JavaDoc e) {
798             throw new InternalKernelException(e);
799         }
800     }
801
802     public AbstractName getAbstractNameFor(Object JavaDoc service) {
803         AbstractName name = proxyManager.getProxyTarget(service);
804         if (name != null) {
805             return name;
806         }
807         try {
808             return (AbstractName) invokeKernel("getAbstractNameFor", new Object JavaDoc[] {service}, new String JavaDoc[] {Object JavaDoc.class.getName()});
809         } catch (RuntimeException JavaDoc e) {
810             throw e;
811         } catch (Exception JavaDoc e) {
812             throw new InternalKernelException(e);
813         }
814     }
815
816     public String JavaDoc getShortNameFor(Object JavaDoc service) {
817         AbstractName name = getAbstractNameFor(service);
818         return (String JavaDoc) name.getName().get("name");
819     }
820
821     public boolean isRunning() {
822         return ((Boolean JavaDoc) getKernelAttribute("running")).booleanValue();
823     }
824
825     public Set JavaDoc listGBeans(AbstractNameQuery query) {
826         try {
827             return (Set JavaDoc) invokeKernel("listGBeans", new Object JavaDoc[] {query}, new String JavaDoc[] {AbstractNameQuery.class.getName()});
828         } catch (RuntimeException JavaDoc e) {
829             throw e;
830         } catch (Exception JavaDoc e) {
831             throw new InternalKernelException(e);
832         }
833     }
834
835     /**
836      * Throws UnsupportedOperationException. The dependency manager is not accesable over a remote connection.
837      */

838     public DependencyManager getDependencyManager() {
839         throw new UnsupportedOperationException JavaDoc("Dependency manager is not accessable by way of a remote connection");
840     }
841
842     /**
843      * Throws UnsupportedOperationException. The lifecycle monitor is not accesable over a remote connection.
844      */

845     public LifecycleMonitor getLifecycleMonitor() {
846         throw new UnsupportedOperationException JavaDoc("Lifecycle monitor is not accessable by way of a remote connection");
847     }
848
849     public ProxyManager getProxyManager() {
850         return proxyManager;
851     }
852
853     /**
854      * Throws UnsupportedOperationException. A remote kernel will alreayd be booted.
855      */

856     public void boot() throws Exception JavaDoc {
857         throw new UnsupportedOperationException JavaDoc("A remote kernel can not be booted");
858     }
859
860     private Object JavaDoc getKernelAttribute(String JavaDoc attributeName) {
861         try {
862             return mbeanServer.getAttribute(Kernel.KERNEL, attributeName);
863         } catch (Exception JavaDoc e) {
864             Throwable JavaDoc cause = unwrapJMException(e);
865             if (cause instanceof InstanceNotFoundException JavaDoc) {
866                 throw new InternalKernelException("Kernel is not loaded");
867             } else if (cause instanceof AttributeNotFoundException JavaDoc) {
868                 throw new InternalKernelException("KernelDelegate is out of synch with Kernel");
869             } else {
870                 throw new InternalKernelException(cause);
871             }
872         }
873     }
874
875     private Object JavaDoc invokeKernel(String JavaDoc methodName, Object JavaDoc[] args, String JavaDoc[] types) throws Exception JavaDoc {
876         if(args != null && types != null && args.length != types.length) {
877             throw new IllegalArgumentException JavaDoc("Call to "+methodName+" has "+args.length+" arguments but "+types.length+" argument classes!");
878         }
879         try {
880             return mbeanServer.invoke(Kernel.KERNEL, methodName, args, types);
881         } catch (Exception JavaDoc e) {
882             Throwable JavaDoc cause = unwrapJMException(e);
883             if (cause instanceof InstanceNotFoundException JavaDoc) {
884                 throw new InternalKernelException("Kernel is not loaded");
885             } else if (cause instanceof NoSuchMethodException JavaDoc) {
886                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc("KernelDelegate is out of synch with Kernel on ");
887                 buf.append(methodName).append("(");
888                 if(types != null) {
889                     for (int i = 0; i < types.length; i++) {
890                         String JavaDoc type = types[i];
891                         if(i>0) buf.append(",");
892                         buf.append(type);
893                     }
894                 }
895                 buf.append(")");
896                 throw new InternalKernelException(buf.toString());
897             } else if (cause instanceof JMException JavaDoc) {
898                 throw new InternalKernelException(cause);
899             } else if (cause instanceof JMRuntimeException JavaDoc) {
900                 throw new InternalKernelException(cause);
901             } else if (cause instanceof Error JavaDoc) {
902                 throw (Error JavaDoc) cause;
903             } else if (cause instanceof Exception JavaDoc) {
904                 throw (Exception JavaDoc) cause;
905             } else {
906                 throw new InternalKernelException("Unknown throwable", cause);
907             }
908         }
909     }
910
911     private Throwable JavaDoc unwrapJMException(Throwable JavaDoc cause) {
912         while ((cause instanceof JMException JavaDoc || cause instanceof JMRuntimeException JavaDoc) && cause.getCause() != null) {
913             cause = cause.getCause();
914         }
915         return cause;
916     }
917 }
918
Popular Tags