01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.client;
17:
18: import java.util.Properties;
19:
20: import org.apache.geronimo.gbean.GBeanInfo;
21: import org.apache.geronimo.gbean.GBeanInfoBuilder;
22: import org.apache.geronimo.gbean.GBeanLifecycle;
23: import org.omg.CORBA.ORB;
24:
25: /**
26: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
27: */
28: public class AppClientCORBABean implements GBeanLifecycle {
29: private final ClassLoader classLoader;
30: private ORB orb;
31:
32: public AppClientCORBABean(ClassLoader classLoader) {
33: this .classLoader = classLoader;
34: }
35:
36: public void doStart() throws Exception {
37: ClassLoader savedLoader = Thread.currentThread()
38: .getContextClassLoader();
39: try {
40: Thread.currentThread().setContextClassLoader(classLoader);
41:
42: orb = ORB.init(new String[0], new Properties());
43: new Thread(new ORBRunable(orb), "ORBInitialization")
44: .start();
45: } finally {
46: Thread.currentThread().setContextClassLoader(savedLoader);
47: }
48: }
49:
50: public void doStop() throws Exception {
51: orb.shutdown(true);
52: }
53:
54: public void doFail() {
55: orb.shutdown(false);
56: }
57:
58: public ORB getORB() {
59: return orb;
60: }
61:
62: private static final class ORBRunable implements Runnable {
63: private final ORB orb;
64:
65: public ORBRunable(ORB orb) {
66: this .orb = orb;
67: }
68:
69: public void run() {
70: orb.run();
71: }
72: }
73:
74: public static final GBeanInfo GBEAN_INFO;
75:
76: static {
77: GBeanInfoBuilder infoFactory = GBeanInfoBuilder
78: .createStatic(AppClientCORBABean.class);
79:
80: infoFactory.addAttribute("classLoader", ClassLoader.class,
81: false);
82: infoFactory.addAttribute("ORB", ORB.class, false);
83:
84: infoFactory.setConstructor(new String[] { "classLoader" });
85:
86: GBEAN_INFO = infoFactory.getBeanInfo();
87: }
88:
89: public static GBeanInfo getGBeanInfo() {
90: return GBEAN_INFO;
91: }
92:
93: }
|