View Javadoc

1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  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.client;
18  
19  import java.util.Properties;
20  
21  import org.apache.geronimo.gbean.GBeanInfo;
22  import org.apache.geronimo.gbean.GBeanInfoBuilder;
23  import org.apache.geronimo.gbean.GBeanLifecycle;
24  import org.omg.CORBA.ORB;
25  
26  /**
27   * @version $Rev: 356022 $ $Date: 2005-12-11 12:58:34 -0800 (Sun, 11 Dec 2005) $
28   */
29  public class AppClientCORBABean implements GBeanLifecycle {
30      private final ClassLoader classLoader;
31      private ORB orb;
32  
33      public AppClientCORBABean(ClassLoader classLoader) {
34          this.classLoader = classLoader;
35      }
36  
37      public void doStart() throws Exception {
38          ClassLoader savedLoader = Thread.currentThread().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").start();
44          } finally {
45              Thread.currentThread().setContextClassLoader(savedLoader);
46          }
47      }
48  
49      public void doStop() throws Exception {
50          orb.shutdown(true);
51      }
52  
53      public void doFail() {
54          orb.shutdown(false);
55      }
56  
57      public ORB getORB() {
58          return orb;
59      }
60  
61      private static final class ORBRunable implements Runnable {
62          private final ORB orb;
63  
64          public ORBRunable(ORB orb) {
65              this.orb = orb;
66          }
67  
68          public void run() {
69              orb.run();
70          }
71      }
72  
73      public static final GBeanInfo GBEAN_INFO;
74  
75      static {
76          GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(AppClientCORBABean.class);
77  
78          infoFactory.addAttribute("classLoader", ClassLoader.class, false);
79          infoFactory.addAttribute("ORB", ORB.class, false);
80  
81          infoFactory.setConstructor(new String[]{"classLoader"});
82  
83          GBEAN_INFO = infoFactory.getBeanInfo();
84      }
85  
86      public static GBeanInfo getGBeanInfo() {
87          return GBEAN_INFO;
88      }
89  
90  }