001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.client;
018
019 import java.util.Properties;
020
021 import org.apache.geronimo.gbean.GBeanInfo;
022 import org.apache.geronimo.gbean.GBeanInfoBuilder;
023 import org.apache.geronimo.gbean.GBeanLifecycle;
024 import org.omg.CORBA.ORB;
025
026 /**
027 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
028 */
029 public class AppClientCORBABean implements GBeanLifecycle {
030 private final ClassLoader classLoader;
031 private ORB orb;
032
033 public AppClientCORBABean(ClassLoader classLoader) {
034 this.classLoader = classLoader;
035 }
036
037 public void doStart() throws Exception {
038 ClassLoader savedLoader = Thread.currentThread().getContextClassLoader();
039 try {
040 Thread.currentThread().setContextClassLoader(classLoader);
041
042 orb = ORB.init(new String[0], new Properties());
043 new Thread(new ORBRunable(orb), "ORBInitialization").start();
044 } finally {
045 Thread.currentThread().setContextClassLoader(savedLoader);
046 }
047 }
048
049 public void doStop() throws Exception {
050 orb.shutdown(true);
051 }
052
053 public void doFail() {
054 orb.shutdown(false);
055 }
056
057 public ORB getORB() {
058 return orb;
059 }
060
061 private static final class ORBRunable implements Runnable {
062 private final ORB orb;
063
064 public ORBRunable(ORB orb) {
065 this.orb = orb;
066 }
067
068 public void run() {
069 orb.run();
070 }
071 }
072
073 public static final GBeanInfo GBEAN_INFO;
074
075 static {
076 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(AppClientCORBABean.class);
077
078 infoFactory.addAttribute("classLoader", ClassLoader.class, false);
079 infoFactory.addAttribute("ORB", ORB.class, false);
080
081 infoFactory.setConstructor(new String[]{"classLoader"});
082
083 GBEAN_INFO = infoFactory.getBeanInfo();
084 }
085
086 public static GBeanInfo getGBeanInfo() {
087 return GBEAN_INFO;
088 }
089
090 }