KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > naming > jacorb > JacORBManager


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * JacORBManager.java
20  *
21  * This object is responsible for managing the JacORB instance. It start the ORB
22  * , POA and the embedded name Cos Name service.
23  */

24
25 // package
26
package com.rift.coad.lib.naming.jacorb;
27
28 // java imports
29
import java.util.Properties JavaDoc;
30 import org.omg.CORBA.ORB JavaDoc;
31 import org.omg.PortableServer.POA JavaDoc;
32 import org.omg.PortableServer.POAHelper JavaDoc;
33 import org.omg.CosNaming.NamingContext JavaDoc;
34 import org.omg.CosNaming.NamingContextHelper JavaDoc;
35 import org.omg.CosNaming.NameComponent JavaDoc;
36
37 // jac orb imports
38
import org.jacorb.naming.EmbeddedNameServer;
39
40 // coadunation imports
41
import com.rift.coad.lib.configuration.Configuration;
42 import com.rift.coad.lib.configuration.ConfigurationFactory;
43 import com.rift.coad.lib.naming.OrbManager;
44 import com.rift.coad.lib.thread.CoadunationThreadGroup;
45
46
47 /**
48  * This object is responsible for managing the JacORB instance.
49  *
50  * @author Brett Chaldecott
51  */

52 public class JacORBManager implements OrbManager {
53     
54     /**
55      * The thread responsible for running the orb.
56      */

57     public class OrbRunner extends Thread JavaDoc {
58         
59         /**
60          * The constructor of the orb runner class.
61          */

62         public OrbRunner() {
63             
64         }
65         
66         /**
67          * The run method
68          */

69         public void run() {
70             orb.run();
71         }
72     }
73     
74     // class constants
75
private final static String JavaDoc HOST = "host";
76     private final static String JavaDoc PORT = "port";
77     private final static String JavaDoc DEFAULT_PORT = "2000";
78     private final static String JavaDoc NAME_SERVER_STORE = "name_server_store";
79     
80     // private member variables
81
private ORB JavaDoc orb = null;
82     private POA JavaDoc poa = null;
83     private OrbRunner orbRunner = null;
84     private EmbeddedNameServer embeddedNameServer = null;
85     
86     /** Creates a new instance of JacORBManager */
87     public JacORBManager(CoadunationThreadGroup threadGroup) throws
88             JacORBException {
89         try {
90             // start the orb
91
Properties JavaDoc properties = new Properties JavaDoc();
92             Configuration config = ConfigurationFactory.getInstance().
93                     getConfig(this.getClass());
94             properties.setProperty("org.omg.CORBA.ORBClass",
95                     "org.jacorb.orb.ORB");
96             System.setProperty("org.omg.CORBA.ORBClass",
97                     "org.jacorb.orb.ORB");
98             properties.setProperty("org.omg.CORBA.ORBSingletonClass",
99                     "org.jacorb.orb.ORBSingleton");
100             System.setProperty("org.omg.CORBA.ORBSingletonClass",
101                     "org.jacorb.orb.ORBSingleton");
102             properties.setProperty("javax.rmi.CORBA.PortableRemoteObjectClass",
103                     org.objectweb.carol.rmi.multi.JacORBPRODelegate.
104                     class.getName());
105             System.setProperty("javax.rmi.CORBA.PortableRemoteObjectClass",
106                     org.objectweb.carol.rmi.multi.JacORBPRODelegate.
107                     class.getName());
108             System.setProperty("javax.rmi.CORBA.UtilClass",
109                     org.objectweb.carol.util.delegate.UtilDelegateImpl.
110                     class.getName());
111             properties.setProperty("OAPort",config.getString(PORT,DEFAULT_PORT));
112             properties.setProperty("OAIAddr",config.getString(HOST));
113             
114             // Name server properties
115
// The following properties are for the name server which runs using
116
// the same orb instance
117
/*
118              * by setting the following property, the ORB will
119              * accept client requests targeted at the object with
120              * key "NameService", so more readablee corbaloc URLs
121              * can be used
122              */

123             properties.put("jacorb.orb.objectKeyMap.NameService",
124                     "StandardNS/NameServer-POA/_root");
125             properties.put("jacorb.implname", "StandardNS");
126             properties.put("jacorb.naming.db_dir",
127                     config.getString(NAME_SERVER_STORE));
128             // end of name server properties
129
orb = ORB.init(new String JavaDoc[0],properties);
130             
131             // start the poa
132
poa = POAHelper.narrow(
133                     orb.resolve_initial_references("RootPOA"));
134             
135             // init the embedded name server
136
embeddedNameServer = new EmbeddedNameServer(orb,poa);
137             
138             // activate the poa
139
poa.the_POAManager().activate();
140             
141             // start the orb
142
orbRunner = new OrbRunner();
143             orbRunner.start();
144             
145         } catch (Exception JavaDoc ex) {
146             throw new JacORBException ("Failed to start the orb : " +
147                     ex.getMessage(),ex);
148         }
149     }
150     
151     
152     /**
153      * This method returns a reference to the orb.
154      *
155      * @return The reference to the orb.
156      */

157     public ORB JavaDoc getORB() {
158         return orb;
159     }
160     
161     
162     /**
163      * The reference to the poa.
164      */

165     public POA JavaDoc getPOA() {
166         return poa;
167     }
168     
169     
170     /**
171      * This method is called to terminate the orb.
172      */

173     public void terminate() {
174         orb.shutdown(true);
175     }
176 }
177
178
Popular Tags