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