KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > activation > ORBD


1 /*
2  * @(#)ORBD.java 1.53 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * @(#)ORBD.java 1.27 00/03/02
9  *
10  * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
11  * Palo Alto, California, 94303, U.S.A. All Rights Reserved.
12  *
13  * This software is the confidential and proprietary information of Sun
14  * Microsystems, Inc. ("Confidential Information"). You shall not
15  * disclose such Confidential Information and shall use it only in
16  * accordance with the terms of the license agreement you entered into
17  * with Sun.
18  *
19  * CopyrightVersion 1.2
20  *
21  */

22
23 package com.sun.corba.se.impl.activation;
24
25 import java.io.File JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import org.omg.CORBA.INITIALIZE JavaDoc;
29 import org.omg.CORBA.INTERNAL JavaDoc;
30 import org.omg.CORBA.CompletionStatus JavaDoc;
31 import org.omg.CosNaming.NamingContext JavaDoc;
32 import org.omg.PortableServer.POA JavaDoc;
33
34 import com.sun.corba.se.pept.transport.Acceptor;
35
36 import com.sun.corba.se.spi.activation.Repository;
37 import com.sun.corba.se.spi.activation.RepositoryPackage.ServerDef;
38 import com.sun.corba.se.spi.activation.Locator;
39 import com.sun.corba.se.spi.activation.LocatorHelper;
40 import com.sun.corba.se.spi.activation.Activator;
41 import com.sun.corba.se.spi.activation.ActivatorHelper;
42 import com.sun.corba.se.spi.activation.ServerAlreadyRegistered;
43 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
44 import com.sun.corba.se.spi.transport.SocketInfo;
45 import com.sun.corba.se.spi.orb.ORB;
46
47 import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl;
48 import com.sun.corba.se.impl.naming.cosnaming.TransientNameService;
49 import com.sun.corba.se.impl.naming.pcosnaming.NameService;
50 import com.sun.corba.se.impl.orbutil.ORBConstants;
51 import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
52 import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl;
53
54 /**
55  *
56  * @version 1.10, 97/12/06
57  * @author Rohit Garg
58  * @since JDK1.2
59  */

60 public class ORBD
61 {
62     private int initSvcPort;
63
64     protected void initializeBootNaming(ORB orb)
65     {
66         // create a bootstrap server
67
initSvcPort = orb.getORBData().getORBInitialPort();
68
69     Acceptor acceptor;
70     // REVISIT: see ORBConfigurator. use factory in TransportDefault.
71
if (orb.getORBData().getLegacySocketFactory() == null) {
72         acceptor =
73         new SocketOrChannelAcceptorImpl(
74             orb,
75             initSvcPort,
76             LegacyServerSocketEndPointInfo.BOOT_NAMING,
77             SocketInfo.IIOP_CLEAR_TEXT);
78     } else {
79         acceptor =
80         new SocketFactoryAcceptorImpl(
81             orb,
82             initSvcPort,
83             LegacyServerSocketEndPointInfo.BOOT_NAMING,
84             SocketInfo.IIOP_CLEAR_TEXT);
85     }
86     orb.getCorbaTransportManager().registerAcceptor(acceptor);
87     }
88
89     protected ORB createORB(String JavaDoc[] args)
90     {
91     Properties JavaDoc props = System.getProperties();
92
93     // For debugging.
94
//props.put( ORBConstants.DEBUG_PROPERTY, "naming" ) ;
95
//props.put( ORBConstants.DEBUG_PROPERTY, "transport,giop,naming" ) ;
96

97     props.put( ORBConstants.SERVER_ID_PROPERTY, "1000" ) ;
98     props.put( ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,
99         props.getProperty( ORBConstants.ORBD_PORT_PROPERTY,
100         Integer.toString(
101             ORBConstants.DEFAULT_ACTIVATION_PORT ) ) ) ;
102
103     // See Bug 4396928 for more information about why we are initializing
104
// the ORBClass to PIORB (now ORBImpl, but should check the bugid).
105
props.put("org.omg.CORBA.ORBClass",
106         "com.sun.corba.se.impl.orb.ORBImpl");
107
108     return (ORB) ORB.init(args, props);
109     }
110
111     private void run(String JavaDoc[] args)
112     {
113     try {
114         // parse the args and try setting the values for these
115
// properties
116
processArgs(args);
117
118         ORB orb = createORB(args);
119
120         if (orb.orbdDebugFlag)
121         System.out.println( "ORBD begins initialization." ) ;
122
123         boolean firstRun = createSystemDirs( ORBConstants.DEFAULT_DB_DIR );
124
125         startActivationObjects(orb);
126
127         if (firstRun) // orbd is being run the first time
128
installOrbServers(getRepository(), getActivator());
129
130         if (orb.orbdDebugFlag) {
131         System.out.println( "ORBD is ready." ) ;
132             System.out.println("ORBD serverid: " +
133                     System.getProperty(ORBConstants.SERVER_ID_PROPERTY));
134             System.out.println("activation dbdir: " +
135                     System.getProperty(ORBConstants.DB_DIR_PROPERTY));
136             System.out.println("activation port: " +
137                     System.getProperty(ORBConstants.ORBD_PORT_PROPERTY));
138
139                 String JavaDoc pollingTime = System.getProperty(
140                     ORBConstants.SERVER_POLLING_TIME);
141                 if( pollingTime == null ) {
142                     pollingTime = Integer.toString(
143                         ORBConstants.DEFAULT_SERVER_POLLING_TIME );
144                 }
145                 System.out.println("activation Server Polling Time: " +
146                         pollingTime + " milli-seconds ");
147
148                 String JavaDoc startupDelay = System.getProperty(
149                     ORBConstants.SERVER_STARTUP_DELAY);
150                 if( startupDelay == null ) {
151                     startupDelay = Integer.toString(
152                         ORBConstants.DEFAULT_SERVER_STARTUP_DELAY );
153                 }
154             System.out.println("activation Server Startup Delay: " +
155                         startupDelay + " milli-seconds " );
156         }
157
158         // The following two lines start the Persistent NameService
159
NameServiceStartThread theThread =
160                 new NameServiceStartThread( orb, dbDir );
161             theThread.start( );
162
163         orb.run();
164     } catch( org.omg.CORBA.COMM_FAILURE JavaDoc cex ) {
165             System.out.println( CorbaResourceUtil.getText("orbd.commfailure"));
166         System.out.println( cex );
167         cex.printStackTrace();
168         } catch( org.omg.CORBA.INTERNAL JavaDoc iex ) {
169             System.out.println( CorbaResourceUtil.getText(
170                 "orbd.internalexception"));
171         System.out.println( iex );
172         iex.printStackTrace();
173         } catch (Exception JavaDoc ex) {
174         System.out.println(CorbaResourceUtil.getText(
175                 "orbd.usage", "orbd"));
176         System.out.println( ex );
177         ex.printStackTrace();
178     }
179     }
180
181     private void processArgs(String JavaDoc[] args)
182     {
183     Properties JavaDoc props = System.getProperties();
184     for (int i=0; i < args.length; i++) {
185         if (args[i].equals("-port")) {
186             if ((i+1) < args.length) {
187                 props.put(ORBConstants.ORBD_PORT_PROPERTY, args[++i]);
188             } else {
189                 System.out.println(CorbaResourceUtil.getText(
190             "orbd.usage", "orbd"));
191             }
192         } else if (args[i].equals("-defaultdb")) {
193             if ((i+1) < args.length) {
194                 props.put(ORBConstants.DB_DIR_PROPERTY, args[++i]);
195             } else {
196                 System.out.println(CorbaResourceUtil.getText(
197             "orbd.usage", "orbd"));
198             }
199         } else if (args[i].equals("-serverid")) {
200             if ((i+1) < args.length) {
201                 props.put(ORBConstants.SERVER_ID_PROPERTY, args[++i]);
202             } else {
203                 System.out.println(CorbaResourceUtil.getText(
204             "orbd.usage", "orbd"));
205             }
206         } else if (args[i].equals("-serverPollingTime")) {
207             if ((i+1) < args.length) {
208                 props.put(ORBConstants.SERVER_POLLING_TIME, args[++i]);
209             } else {
210                 System.out.println(CorbaResourceUtil.getText(
211             "orbd.usage", "orbd"));
212             }
213         } else if (args[i].equals("-serverStartupDelay")) {
214             if ((i+1) < args.length) {
215                 props.put(ORBConstants.SERVER_STARTUP_DELAY, args[++i]);
216             } else {
217                 System.out.println(CorbaResourceUtil.getText(
218             "orbd.usage", "orbd"));
219             }
220             }
221     }
222     }
223
224     /**
225      * Ensure that the Db directory exists. If not, create the Db
226      * and the log directory and return true. Otherwise return false.
227      */

228     protected boolean createSystemDirs(String JavaDoc defaultDbDir)
229     {
230     boolean dirCreated = false;
231     Properties JavaDoc props = System.getProperties();
232     String JavaDoc fileSep = props.getProperty("file.separator");
233
234     // determine the ORB db directory
235
dbDir = new File JavaDoc (props.getProperty( ORBConstants.DB_DIR_PROPERTY,
236         props.getProperty("user.dir") + fileSep + defaultDbDir));
237
238     // create the db and the logs directories
239
dbDirName = dbDir.getAbsolutePath();
240     props.put(ORBConstants.DB_DIR_PROPERTY, dbDirName);
241     if (!dbDir.exists()) {
242         dbDir.mkdir();
243         dirCreated = true;
244     }
245
246     File JavaDoc logDir = new File JavaDoc (dbDir, ORBConstants.SERVER_LOG_DIR ) ;
247     if (!logDir.exists()) logDir.mkdir();
248
249     return dirCreated;
250     }
251
252     protected File JavaDoc dbDir;
253     protected File JavaDoc getDbDir()
254     {
255     return dbDir;
256     }
257
258     private String JavaDoc dbDirName;
259     protected String JavaDoc getDbDirName()
260     {
261     return dbDirName;
262     }
263
264     protected void startActivationObjects(ORB orb) throws Exception JavaDoc
265     {
266     // create Initial Name Service object
267
initializeBootNaming(orb);
268
269     // create Repository object
270
repository = new RepositoryImpl(orb, dbDir, orb.orbdDebugFlag );
271     orb.register_initial_reference( ORBConstants.SERVER_REPOSITORY_NAME, repository );
272
273     // create Locator and Activator objects
274
ServerManagerImpl serverMgr =
275         new ServerManagerImpl( orb,
276                    orb.getCorbaTransportManager(),
277                    repository,
278                    getDbDirName(),
279                    orb.orbdDebugFlag );
280
281     locator = LocatorHelper.narrow(serverMgr);
282     orb.register_initial_reference( ORBConstants.SERVER_LOCATOR_NAME, locator );
283
284     activator = ActivatorHelper.narrow(serverMgr);
285     orb.register_initial_reference( ORBConstants.SERVER_ACTIVATOR_NAME, activator );
286
287         // start Name Service
288
TransientNameService nameService = new TransientNameService(orb,
289         ORBConstants.TRANSIENT_NAME_SERVICE_NAME);
290     }
291
292     protected Locator locator;
293     protected Locator getLocator()
294     {
295     return locator;
296     }
297
298     protected Activator activator;
299     protected Activator getActivator()
300     {
301     return activator;
302     }
303
304     protected RepositoryImpl repository;
305     protected RepositoryImpl getRepository()
306     {
307     return repository;
308     }
309
310     /**
311      * Go through the list of ORB Servers and initialize and start
312      * them up.
313      */

314     protected void installOrbServers(RepositoryImpl repository,
315                      Activator activator)
316     {
317     int serverId;
318     String JavaDoc[] server;
319     ServerDef serverDef;
320
321     for (int i=0; i < orbServers.length; i++) {
322         try {
323         server = orbServers[i];
324         serverDef = new ServerDef(server[1], server[2],
325                       server[3], server[4], server[5] );
326
327         serverId = Integer.valueOf(orbServers[i][0]).intValue();
328
329         repository.registerServer(serverDef, serverId);
330
331         activator.activate(serverId);
332
333         } catch (Exception JavaDoc ex) {}
334     }
335     }
336
337     public static void main(String JavaDoc[] args) {
338     ORBD orbd = new ORBD();
339     orbd.run(args);
340     }
341
342     /**
343      * List of servers to be auto registered and started by the ORBd.
344      *
345      * Each server entry is of the form {id, name, path, args, vmargs}.
346      */

347     private static String JavaDoc[][] orbServers = {
348     {""}
349     };
350 }
351
Popular Tags