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. package com.sun.corba.se.impl.activation;
  23. import java.io.File;
  24. import java.util.Properties;
  25. import org.omg.CORBA.INITIALIZE;
  26. import org.omg.CORBA.INTERNAL;
  27. import org.omg.CORBA.CompletionStatus;
  28. import org.omg.CosNaming.NamingContext;
  29. import org.omg.PortableServer.POA;
  30. import com.sun.corba.se.pept.transport.Acceptor;
  31. import com.sun.corba.se.spi.activation.Repository;
  32. import com.sun.corba.se.spi.activation.RepositoryPackage.ServerDef;
  33. import com.sun.corba.se.spi.activation.Locator;
  34. import com.sun.corba.se.spi.activation.LocatorHelper;
  35. import com.sun.corba.se.spi.activation.Activator;
  36. import com.sun.corba.se.spi.activation.ActivatorHelper;
  37. import com.sun.corba.se.spi.activation.ServerAlreadyRegistered;
  38. import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
  39. import com.sun.corba.se.spi.transport.SocketInfo;
  40. import com.sun.corba.se.spi.orb.ORB;
  41. import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl;
  42. import com.sun.corba.se.impl.naming.cosnaming.TransientNameService;
  43. import com.sun.corba.se.impl.naming.pcosnaming.NameService;
  44. import com.sun.corba.se.impl.orbutil.ORBConstants;
  45. import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
  46. import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl;
  47. /**
  48. *
  49. * @version 1.10, 97/12/06
  50. * @author Rohit Garg
  51. * @since JDK1.2
  52. */
  53. public class ORBD
  54. {
  55. private int initSvcPort;
  56. protected void initializeBootNaming(ORB orb)
  57. {
  58. // create a bootstrap server
  59. initSvcPort = orb.getORBData().getORBInitialPort();
  60. Acceptor acceptor;
  61. // REVISIT: see ORBConfigurator. use factory in TransportDefault.
  62. if (orb.getORBData().getLegacySocketFactory() == null) {
  63. acceptor =
  64. new SocketOrChannelAcceptorImpl(
  65. orb,
  66. initSvcPort,
  67. LegacyServerSocketEndPointInfo.BOOT_NAMING,
  68. SocketInfo.IIOP_CLEAR_TEXT);
  69. } else {
  70. acceptor =
  71. new SocketFactoryAcceptorImpl(
  72. orb,
  73. initSvcPort,
  74. LegacyServerSocketEndPointInfo.BOOT_NAMING,
  75. SocketInfo.IIOP_CLEAR_TEXT);
  76. }
  77. orb.getCorbaTransportManager().registerAcceptor(acceptor);
  78. }
  79. protected ORB createORB(String[] args)
  80. {
  81. Properties props = System.getProperties();
  82. // For debugging.
  83. //props.put( ORBConstants.DEBUG_PROPERTY, "naming" ) ;
  84. //props.put( ORBConstants.DEBUG_PROPERTY, "transport,giop,naming" ) ;
  85. props.put( ORBConstants.SERVER_ID_PROPERTY, "1000" ) ;
  86. props.put( ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,
  87. props.getProperty( ORBConstants.ORBD_PORT_PROPERTY,
  88. Integer.toString(
  89. ORBConstants.DEFAULT_ACTIVATION_PORT ) ) ) ;
  90. // See Bug 4396928 for more information about why we are initializing
  91. // the ORBClass to PIORB (now ORBImpl, but should check the bugid).
  92. props.put("org.omg.CORBA.ORBClass",
  93. "com.sun.corba.se.impl.orb.ORBImpl");
  94. return (ORB) ORB.init(args, props);
  95. }
  96. private void run(String[] args)
  97. {
  98. try {
  99. // parse the args and try setting the values for these
  100. // properties
  101. processArgs(args);
  102. ORB orb = createORB(args);
  103. if (orb.orbdDebugFlag)
  104. System.out.println( "ORBD begins initialization." ) ;
  105. boolean firstRun = createSystemDirs( ORBConstants.DEFAULT_DB_DIR );
  106. startActivationObjects(orb);
  107. if (firstRun) // orbd is being run the first time
  108. installOrbServers(getRepository(), getActivator());
  109. if (orb.orbdDebugFlag) {
  110. System.out.println( "ORBD is ready." ) ;
  111. System.out.println("ORBD serverid: " +
  112. System.getProperty(ORBConstants.SERVER_ID_PROPERTY));
  113. System.out.println("activation dbdir: " +
  114. System.getProperty(ORBConstants.DB_DIR_PROPERTY));
  115. System.out.println("activation port: " +
  116. System.getProperty(ORBConstants.ORBD_PORT_PROPERTY));
  117. String pollingTime = System.getProperty(
  118. ORBConstants.SERVER_POLLING_TIME);
  119. if( pollingTime == null ) {
  120. pollingTime = Integer.toString(
  121. ORBConstants.DEFAULT_SERVER_POLLING_TIME );
  122. }
  123. System.out.println("activation Server Polling Time: " +
  124. pollingTime + " milli-seconds ");
  125. String startupDelay = System.getProperty(
  126. ORBConstants.SERVER_STARTUP_DELAY);
  127. if( startupDelay == null ) {
  128. startupDelay = Integer.toString(
  129. ORBConstants.DEFAULT_SERVER_STARTUP_DELAY );
  130. }
  131. System.out.println("activation Server Startup Delay: " +
  132. startupDelay + " milli-seconds " );
  133. }
  134. // The following two lines start the Persistent NameService
  135. NameServiceStartThread theThread =
  136. new NameServiceStartThread( orb, dbDir );
  137. theThread.start( );
  138. orb.run();
  139. } catch( org.omg.CORBA.COMM_FAILURE cex ) {
  140. System.out.println( CorbaResourceUtil.getText("orbd.commfailure"));
  141. System.out.println( cex );
  142. cex.printStackTrace();
  143. } catch( org.omg.CORBA.INTERNAL iex ) {
  144. System.out.println( CorbaResourceUtil.getText(
  145. "orbd.internalexception"));
  146. System.out.println( iex );
  147. iex.printStackTrace();
  148. } catch (Exception ex) {
  149. System.out.println(CorbaResourceUtil.getText(
  150. "orbd.usage", "orbd"));
  151. System.out.println( ex );
  152. ex.printStackTrace();
  153. }
  154. }
  155. private void processArgs(String[] args)
  156. {
  157. Properties props = System.getProperties();
  158. for (int i=0; i < args.length; i++) {
  159. if (args[i].equals("-port")) {
  160. if ((i+1) < args.length) {
  161. props.put(ORBConstants.ORBD_PORT_PROPERTY, args[++i]);
  162. } else {
  163. System.out.println(CorbaResourceUtil.getText(
  164. "orbd.usage", "orbd"));
  165. }
  166. } else if (args[i].equals("-defaultdb")) {
  167. if ((i+1) < args.length) {
  168. props.put(ORBConstants.DB_DIR_PROPERTY, args[++i]);
  169. } else {
  170. System.out.println(CorbaResourceUtil.getText(
  171. "orbd.usage", "orbd"));
  172. }
  173. } else if (args[i].equals("-serverid")) {
  174. if ((i+1) < args.length) {
  175. props.put(ORBConstants.SERVER_ID_PROPERTY, args[++i]);
  176. } else {
  177. System.out.println(CorbaResourceUtil.getText(
  178. "orbd.usage", "orbd"));
  179. }
  180. } else if (args[i].equals("-serverPollingTime")) {
  181. if ((i+1) < args.length) {
  182. props.put(ORBConstants.SERVER_POLLING_TIME, args[++i]);
  183. } else {
  184. System.out.println(CorbaResourceUtil.getText(
  185. "orbd.usage", "orbd"));
  186. }
  187. } else if (args[i].equals("-serverStartupDelay")) {
  188. if ((i+1) < args.length) {
  189. props.put(ORBConstants.SERVER_STARTUP_DELAY, args[++i]);
  190. } else {
  191. System.out.println(CorbaResourceUtil.getText(
  192. "orbd.usage", "orbd"));
  193. }
  194. }
  195. }
  196. }
  197. /**
  198. * Ensure that the Db directory exists. If not, create the Db
  199. * and the log directory and return true. Otherwise return false.
  200. */
  201. protected boolean createSystemDirs(String defaultDbDir)
  202. {
  203. boolean dirCreated = false;
  204. Properties props = System.getProperties();
  205. String fileSep = props.getProperty("file.separator");
  206. // determine the ORB db directory
  207. dbDir = new File (props.getProperty( ORBConstants.DB_DIR_PROPERTY,
  208. props.getProperty("user.dir") + fileSep + defaultDbDir));
  209. // create the db and the logs directories
  210. dbDirName = dbDir.getAbsolutePath();
  211. props.put(ORBConstants.DB_DIR_PROPERTY, dbDirName);
  212. if (!dbDir.exists()) {
  213. dbDir.mkdir();
  214. dirCreated = true;
  215. }
  216. File logDir = new File (dbDir, ORBConstants.SERVER_LOG_DIR ) ;
  217. if (!logDir.exists()) logDir.mkdir();
  218. return dirCreated;
  219. }
  220. protected File dbDir;
  221. protected File getDbDir()
  222. {
  223. return dbDir;
  224. }
  225. private String dbDirName;
  226. protected String getDbDirName()
  227. {
  228. return dbDirName;
  229. }
  230. protected void startActivationObjects(ORB orb) throws Exception
  231. {
  232. // create Initial Name Service object
  233. initializeBootNaming(orb);
  234. // create Repository object
  235. repository = new RepositoryImpl(orb, dbDir, orb.orbdDebugFlag );
  236. orb.register_initial_reference( ORBConstants.SERVER_REPOSITORY_NAME, repository );
  237. // create Locator and Activator objects
  238. ServerManagerImpl serverMgr =
  239. new ServerManagerImpl( orb,
  240. orb.getCorbaTransportManager(),
  241. repository,
  242. getDbDirName(),
  243. orb.orbdDebugFlag );
  244. locator = LocatorHelper.narrow(serverMgr);
  245. orb.register_initial_reference( ORBConstants.SERVER_LOCATOR_NAME, locator );
  246. activator = ActivatorHelper.narrow(serverMgr);
  247. orb.register_initial_reference( ORBConstants.SERVER_ACTIVATOR_NAME, activator );
  248. // start Name Service
  249. TransientNameService nameService = new TransientNameService(orb,
  250. ORBConstants.TRANSIENT_NAME_SERVICE_NAME);
  251. }
  252. protected Locator locator;
  253. protected Locator getLocator()
  254. {
  255. return locator;
  256. }
  257. protected Activator activator;
  258. protected Activator getActivator()
  259. {
  260. return activator;
  261. }
  262. protected RepositoryImpl repository;
  263. protected RepositoryImpl getRepository()
  264. {
  265. return repository;
  266. }
  267. /**
  268. * Go through the list of ORB Servers and initialize and start
  269. * them up.
  270. */
  271. protected void installOrbServers(RepositoryImpl repository,
  272. Activator activator)
  273. {
  274. int serverId;
  275. String[] server;
  276. ServerDef serverDef;
  277. for (int i=0; i < orbServers.length; i++) {
  278. try {
  279. server = orbServers[i];
  280. serverDef = new ServerDef(server[1], server[2],
  281. server[3], server[4], server[5] );
  282. serverId = Integer.valueOf(orbServers[i][0]).intValue();
  283. repository.registerServer(serverDef, serverId);
  284. activator.activate(serverId);
  285. } catch (Exception ex) {}
  286. }
  287. }
  288. public static void main(String[] args) {
  289. ORBD orbd = new ORBD();
  290. orbd.run(args);
  291. }
  292. /**
  293. * List of servers to be auto registered and started by the ORBd.
  294. *
  295. * Each server entry is of the form {id, name, path, args, vmargs}.
  296. */
  297. private static String[][] orbServers = {
  298. {""}
  299. };
  300. }