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(ObjectNam