1 7 22 23 package com.sun.corba.se.impl.activation; 24 25 import java.io.File ; 26 import java.util.Properties ; 27 28 import org.omg.CORBA.INITIALIZE ; 29 import org.omg.CORBA.INTERNAL ; 30 import org.omg.CORBA.CompletionStatus ; 31 import org.omg.CosNaming.NamingContext ; 32 import org.omg.PortableServer.POA ; 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 60 public class ORBD 61 { 62 private int initSvcPort; 63 64 protected void initializeBootNaming(ORB orb) 65 { 66 initSvcPort = orb.getORBData().getORBInitialPort(); 68 69 Acceptor acceptor; 70 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 [] args) 90 { 91 Properties props = System.getProperties(); 92 93 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 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 [] args) 112 { 113 try { 114 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) 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 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 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 NameServiceStartThread theThread = 160 new NameServiceStartThread( orb, dbDir ); 161 theThread.start( ); 162 163 orb.run(); 164 } catch( org.omg.CORBA.COMM_FAILURE cex ) { 165 System.out.println( CorbaResourceUtil.getText("orbd.commfailure")); 166 System.out.println( cex ); 167 cex.printStackTrace(); 168 } catch( org.omg.CORBA.INTERNAL iex ) { 169 System.out.println( CorbaResourceUtil.getText( 170 "orbd.internalexception")); 171 System.out.println( iex ); 172 iex.printStackTrace(); 173 } catch (Exception 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 [] args) 182 { 183 Properties 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 228 protected boolean createSystemDirs(String defaultDbDir) 229 { 230 boolean dirCreated = false; 231 Properties props = System.getProperties(); 232 String fileSep = props.getProperty("file.separator"); 233 234 dbDir = new File (props.getProperty( ORBConstants.DB_DIR_PROPERTY, 236 props.getProperty("user.dir") + fileSep + defaultDbDir)); 237 238 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 logDir = new File (dbDir, ORBConstants.SERVER_LOG_DIR ) ; 247 if (!logDir.exists()) logDir.mkdir(); 248 249 return dirCreated; 250 } 251 252 protected File dbDir; 253 protected File getDbDir() 254 { 255 return dbDir; 256 } 257 258 private String dbDirName; 259 protected String getDbDirName() 260 { 261 return dbDirName; 262 } 263 264 protected void startActivationObjects(ORB orb) throws Exception 265 { 266 initializeBootNaming(orb); 268 269 repository = new RepositoryImpl(orb, dbDir, orb.orbdDebugFlag ); 271 orb.register_initial_reference( ORBConstants.SERVER_REPOSITORY_NAME, repository ); 272 273 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 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 314 protected void installOrbServers(RepositoryImpl repository, 315 Activator activator) 316 { 317 int serverId; 318 String [] 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 ex) {} 334 } 335 } 336 337 public static void main(String [] args) { 338 ORBD orbd = new ORBD(); 339 orbd.run(args); 340 } 341 342 347 private static String [][] orbServers = { 348 {""} 349 }; 350 } 351 | Popular Tags |