1 7 8 package com.sun.corba.se.impl.orb ; 9 10 import java.lang.reflect.InvocationTargetException ; 11 import java.lang.reflect.Method ; 12 import java.net.InetAddress ; 13 import java.security.PrivilegedAction ; 14 import java.security.PrivilegedExceptionAction ; 15 import java.security.AccessController ; 16 import java.util.Collection ; 17 import java.util.Iterator ; 18 19 import org.omg.CORBA.CompletionStatus ; 20 import org.omg.CORBA.portable.ValueFactory ; 21 22 import com.sun.corba.se.pept.protocol.ClientRequestDispatcher ; 23 import com.sun.corba.se.pept.transport.Acceptor; 24 25 import com.sun.corba.se.spi.activation.Locator ; 26 import com.sun.corba.se.spi.activation.Activator ; 27 import com.sun.corba.se.spi.activation.LocatorHelper ; 28 import com.sun.corba.se.spi.activation.ActivatorHelper ; 29 import com.sun.corba.se.spi.activation.EndPointInfo ; 30 31 import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ; 32 import com.sun.corba.se.spi.copyobject.CopyobjectDefaults ; 33 import com.sun.corba.se.spi.copyobject.CopierManager ; 34 35 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ; 36 import com.sun.corba.se.spi.ior.IOR; 37 import com.sun.corba.se.spi.ior.IORFactories ; 38 39 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ; 40 41 import com.sun.corba.se.spi.legacy.connection.ORBSocketFactory; 42 43 import com.sun.corba.se.spi.logging.CORBALogDomains ; 44 45 import com.sun.corba.se.spi.oa.OADefault ; 46 import com.sun.corba.se.spi.oa.ObjectAdapter ; 47 import com.sun.corba.se.spi.oa.ObjectAdapterFactory ; 48 49 import com.sun.corba.se.spi.orb.Operation ; 50 import com.sun.corba.se.spi.orb.OperationFactory ; 51 import com.sun.corba.se.spi.orb.ORBData ; 52 import com.sun.corba.se.spi.orb.DataCollector ; 53 import com.sun.corba.se.spi.orb.ORBConfigurator ; 54 import com.sun.corba.se.spi.orb.ParserImplBase ; 55 import com.sun.corba.se.spi.orb.PropertyParser ; 56 import com.sun.corba.se.spi.orb.ORB ; 57 58 import com.sun.corba.se.spi.orbutil.closure.Closure ; 59 import com.sun.corba.se.spi.orbutil.closure.ClosureFactory ; 60 61 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ; 62 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ; 63 import com.sun.corba.se.spi.protocol.RequestDispatcherDefault ; 64 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory ; 65 66 import com.sun.corba.se.spi.resolver.LocalResolver ; 67 import com.sun.corba.se.spi.resolver.Resolver ; 68 import com.sun.corba.se.spi.resolver.ResolverDefault ; 69 70 import com.sun.corba.se.spi.transport.CorbaContactInfoList; 71 import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory; 72 import com.sun.corba.se.spi.transport.SocketInfo; 73 import com.sun.corba.se.spi.transport.TransportDefault ; 74 75 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ; 76 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults ; 77 78 import com.sun.corba.se.spi.servicecontext.ServiceContext ; 79 import com.sun.corba.se.spi.servicecontext.ServiceContextRegistry ; 80 import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext ; 81 import com.sun.corba.se.spi.servicecontext.CodeSetServiceContext ; 82 import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext ; 83 import com.sun.corba.se.spi.servicecontext.ORBVersionServiceContext ; 84 import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext ; 85 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 86 import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl; 87 88 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo; 90 import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl; 91 import com.sun.corba.se.impl.legacy.connection.SocketFactoryContactInfoListImpl; 92 import com.sun.corba.se.impl.legacy.connection.USLPort; 93 94 import com.sun.corba.se.impl.orbutil.ORBConstants ; 96 97 import com.sun.corba.se.impl.dynamicany.DynAnyFactoryImpl ; 99 100 public class ORBConfiguratorImpl implements ORBConfigurator { 101 private ORBUtilSystemException wrapper ; 102 103 public static class ConfigParser extends ParserImplBase { 104 public Class [] userConfigurators = null ; 105 106 public PropertyParser makeParser() 107 { 108 PropertyParser parser = new PropertyParser() ; 109 Operation action = OperationFactory.compose( 110 OperationFactory.suffixAction(), 111 OperationFactory.classAction() 112 ) ; 113 parser.addPrefix( ORBConstants.SUN_PREFIX + "ORBUserConfigurators", 114 action, "userConfigurators", Class .class ) ; 115 return parser ; 116 } 117 } 118 119 public void configure( DataCollector collector, ORB orb ) 120 { 121 ORB theOrb = orb ; 122 wrapper = ORBUtilSystemException.get( orb, CORBALogDomains.ORB_LIFECYCLE ) ; 123 124 initObjectCopiers( theOrb ) ; 125 initIORFinders( theOrb ) ; 126 127 theOrb.setClientDelegateFactory( 128 TransportDefault.makeClientDelegateFactory( theOrb )) ; 130 131 initializeTransport(theOrb) ; 132 133 initializeNaming( theOrb ) ; 134 initServiceContextRegistry( theOrb ) ; 135 initRequestDispatcherRegistry( theOrb ) ; 136 registerInitialReferences( theOrb ) ; 137 138 persistentServerInitialization( theOrb ) ; 139 140 runUserConfigurators( collector, theOrb ) ; 141 } 142 143 private void runUserConfigurators( DataCollector collector, ORB orb ) 144 { 145 ConfigParser parser = new ConfigParser() ; 149 parser.init( collector ) ; 150 if (parser.userConfigurators != null) { 151 for (int ctr=0; ctr<parser.userConfigurators.length; ctr++) { 152 Class cls = parser.userConfigurators[ctr] ; 153 try { 154 ORBConfigurator config = (ORBConfigurator)(cls.newInstance()) ; 155 config.configure( collector, orb ) ; 156 } catch (Exception exc) { 157 } 160 } 161 } 162 } 163 164 private void persistentServerInitialization( ORB orb ) 165 { 166 ORBData data = orb.getORBData() ; 167 168 if (data.getServerIsORBActivated()) { 171 try { 172 Locator locator = LocatorHelper.narrow( 173 orb.resolve_initial_references( 174 ORBConstants.SERVER_LOCATOR_NAME )) ; 175 Activator activator = ActivatorHelper.narrow( 176 orb.resolve_initial_references( 177 ORBConstants.SERVER_ACTIVATOR_NAME )) ; 178 Collection serverEndpoints = 179 orb.getCorbaTransportManager().getAcceptors(null, null); 180 EndPointInfo[] endpointList = 181 new EndPointInfo[serverEndpoints.size()]; 182 Iterator iterator = serverEndpoints.iterator(); 183 int i = 0 ; 184 while (iterator.hasNext()) { 185 Object n = iterator.next(); 186 if (! (n instanceof LegacyServerSocketEndPointInfo)) { 187 continue; 188 } 189 LegacyServerSocketEndPointInfo ep = 190 (LegacyServerSocketEndPointInfo) n; 191 int port = locator.getEndpoint(ep.getType()); 193 if (port == -1) { 194 port = locator.getEndpoint(SocketInfo.IIOP_CLEAR_TEXT); 195 if (port == -1) { 196 throw new Exception ( 197 "ORBD must support IIOP_CLEAR_TEXT"); 198 } 199 } 200 201 ep.setLocatorPort(port); 202 203 endpointList[i++] = 204 new EndPointInfo(ep.getType(), ep.getPort()); 205 } 206 207 activator.registerEndpoints( 208 data.getPersistentServerId(), data.getORBId(), 209 endpointList); 210 } catch (Exception ex) { 211 throw wrapper.persistentServerInitError( 212 CompletionStatus.COMPLETED_MAYBE, ex ) ; 213 } 214 } 215 } 216 217 222 private void initializeTransport(final ORB orb) 223 { 224 ORBData od = orb.getORBData(); 225 226 CorbaContactInfoListFactory contactInfoListFactory = 227 od.getCorbaContactInfoListFactory(); 228 Acceptor[] acceptors = od.getAcceptors(); 229 230 ORBSocketFactory legacySocketFactory = od.getLegacySocketFactory(); 232 USLPort[] uslPorts = od.getUserSpecifiedListenPorts() ; 233 setLegacySocketFactoryORB(orb, legacySocketFactory); 234 236 240 if (legacySocketFactory != null && contactInfoListFactory != null) { 241 throw wrapper.socketFactoryAndContactInfoListAtSameTime(); 242 } 243 244 if (acceptors.length != 0 && legacySocketFactory != null) { 245 throw wrapper.acceptorsAndLegacySocketFactoryAtSameTime(); 246 } 247 248 249 253 od.getSocketFactory().setORB(orb); 254 255 259 if (legacySocketFactory != null) { 260 contactInfoListFactory = 264 new CorbaContactInfoListFactory() { 265 public void setORB(ORB orb) { } 266 public CorbaContactInfoList create( IOR ior ) { 267 return new SocketFactoryContactInfoListImpl( 268 orb, ior); 269 } 270 }; 271 } else if (contactInfoListFactory != null) { 273 contactInfoListFactory.setORB(orb); 275 } else { 276 contactInfoListFactory = 278 TransportDefault.makeCorbaContactInfoListFactory(orb); 279 } 280 orb.setCorbaContactInfoListFactory(contactInfoListFactory); 281 282 286 296 int port = -1; 298 if (od.getORBServerPort() != 0) { 299 port = od.getORBServerPort(); 300 } else if (od.getPersistentPortInitialized()) { 301 port = od.getPersistentServerPort(); 302 } else if (acceptors.length == 0) { 303 port = 0; 304 } 305 if (port != -1) { 306 createAndRegisterAcceptor(orb, legacySocketFactory, port, 307 LegacyServerSocketEndPointInfo.DEFAULT_ENDPOINT, 308 SocketInfo.IIOP_CLEAR_TEXT); 309 } 310 312 for (int i = 0; i < acceptors.length; i++) { 313 orb.getCorbaTransportManager().registerAcceptor(acceptors[i]); 314 } 315 316 USLPort[] ports = od.getUserSpecifiedListenPorts() ; 319 if (ports != null) { 320 for (int i = 0; i < ports.length; i++) { 321 createAndRegisterAcceptor( 322 orb, legacySocketFactory, ports[i].getPort(), 323 LegacyServerSocketEndPointInfo.NO_NAME, 324 ports[i].getType()); 325 } 326 } 327 } 329 330 333 private void createAndRegisterAcceptor(ORB orb, 335 ORBSocketFactory legacySocketFactory, 336 int port, String name, String type) 337 { 338 Acceptor acceptor; 339 if (legacySocketFactory == null) { 340 acceptor = 341 new SocketOrChannelAcceptorImpl(orb, port, name, type); 342 } else { 343 acceptor = 344 new SocketFactoryAcceptorImpl(orb, port, name, type); 345 } 346 orb.getTransportManager().registerAcceptor(acceptor); 347 } 348 349 private void setLegacySocketFactoryORB( 350 final ORB orb, final ORBSocketFactory legacySocketFactory) 351 { 352 if (legacySocketFactory == null) { 353 return; 354 } 355 356 361 try { 362 AccessController.doPrivileged( 363 new PrivilegedExceptionAction () { 364 public Object run() 365 throws InstantiationException , IllegalAccessException 366 { 367 try { 368 Class [] params = { ORB.class }; 369 Method method = 370 legacySocketFactory.getClass().getMethod( 371 "setORB", params); 372 Object [] args = { orb }; 373 method.invoke(legacySocketFactory, args); 374 } catch (NoSuchMethodException e) { 375 ; 378 } catch (IllegalAccessException e) { 379 RuntimeException rte = new RuntimeException (); 380 rte.initCause(e); 381 throw rte; 382 } catch (InvocationTargetException e) { 383 RuntimeException rte = new RuntimeException (); 384 rte.initCause(e); 385 throw rte; 386 } 387 return null; 388 } 389 } 390 ); 391 } catch (Throwable t) { 392 throw wrapper.unableToSetSocketFactoryOrb(t); 393 } 394 } 395 396 private void initializeNaming( ORB orb ) 397 { 398 LocalResolver localResolver = ResolverDefault.makeLocalResolver() ; 399 orb.setLocalResolver( localResolver ) ; 400 401 Resolver bootResolver = ResolverDefault.makeBootstrapResolver( orb, 402 orb.getORBData().getORBInitialHost(), 403 orb.getORBData().getORBInitialPort() ) ; 404 405 Operation urlOperation = ResolverDefault.makeINSURLOperation( orb, 406 bootResolver ) ; 407 orb.setURLOperation( urlOperation ) ; 408 409 Resolver irResolver = ResolverDefault.makeORBInitRefResolver( urlOperation, 410 orb.getORBData().getORBInitialReferences() ) ; 411 412 Resolver dirResolver = ResolverDefault.makeORBDefaultInitRefResolver( 413 urlOperation, orb.getORBData().getORBDefaultInitialReference() ) ; 414 415 Resolver resolver = 416 ResolverDefault.makeCompositeResolver( localResolver, 417 ResolverDefault.makeCompositeResolver( irResolver, 418 ResolverDefault.makeCompositeResolver( dirResolver, 419 bootResolver ) ) ) ; 420 orb.setResolver( resolver ) ; 421 } 422 423 private void initServiceContextRegistry( ORB orb ) 424 { 425 ServiceContextRegistry scr = orb.getServiceContextRegistry() ; 426 427 scr.register( UEInfoServiceContext.class ) ; 428 scr.register( CodeSetServiceContext.class ) ; 429 scr.register( SendingContextServiceContext.class ) ; 430 scr.register( ORBVersionServiceContext.class ) ; 431 scr.register( MaxStreamFormatVersionServiceContext.class ) ; 432 } 433 434 private void registerInitialReferences( final ORB orb ) 435 { 436 Closure closure = new Closure() { 438 public java.lang.Object evaluate() { 439 return new DynAnyFactoryImpl( orb ) ; 440 } 441 } ; 442 443 Closure future = ClosureFactory.makeFuture( closure ) ; 444 orb.getLocalResolver().register( ORBConstants.DYN_ANY_FACTORY_NAME, 445 future ) ; 446 } 447 448 private static final int ORB_STREAM = 0 ; 449 450 private void initObjectCopiers( ORB orb ) 451 { 452 ObjectCopierFactory orbStream = 454 CopyobjectDefaults.makeORBStreamObjectCopierFactory( orb ) ; 455 456 CopierManager cm = orb.getCopierManager() ; 457 cm.setDefaultId( ORB_STREAM ) ; 458 459 cm.registerObjectCopierFactory( orbStream, ORB_STREAM ) ; 460 } 461 462 private void initIORFinders( ORB orb ) 463 { 464 IdentifiableFactoryFinder profFinder = 465 orb.getTaggedProfileFactoryFinder() ; 466 profFinder.registerFactory( IIOPFactories.makeIIOPProfileFactory() ) ; 467 468 IdentifiableFactoryFinder profTempFinder = 469 orb.getTaggedProfileTemplateFactoryFinder() ; 470 profTempFinder.registerFactory( 471 IIOPFactories.makeIIOPProfileTemplateFactory() ) ; 472 473 IdentifiableFactoryFinder compFinder = 474 orb.getTaggedComponentFactoryFinder() ; 475 compFinder.registerFactory( 476 IIOPFactories.makeCodeSetsComponentFactory() ) ; 477 compFinder.registerFactory( 478 IIOPFactories.makeJavaCodebaseComponentFactory() ) ; 479 compFinder.registerFactory( 480 IIOPFactories.makeORBTypeComponentFactory() ) ; 481 compFinder.registerFactory( 482 IIOPFactories.makeMaxStreamFormatVersionComponentFactory() ) ; 483 compFinder.registerFactory( 484 IIOPFactories.makeAlternateIIOPAddressComponentFactory() ) ; 485 compFinder.registerFactory( 486 IIOPFactories.makeRequestPartitioningComponentFactory() ) ; 487 compFinder.registerFactory( 488 IIOPFactories.makeJavaSerializationComponentFactory()); 489 490 IORFactories.registerValueFactories( orb ) ; 492 493 orb.setObjectKeyFactory( IORFactories.makeObjectKeyFactory(orb) ) ; 495 } 496 497 private void initRequestDispatcherRegistry( ORB orb ) 498 { 499 RequestDispatcherRegistry scr = orb.getRequestDispatcherRegistry() ; 500 501 ClientRequestDispatcher csub = 503 RequestDispatcherDefault.makeClientRequestDispatcher() ; 504 scr.registerClientRequestDispatcher( csub, 505 ORBConstants.TOA_SCID ) ; 506 scr.registerClientRequestDispatcher( csub, 507 ORBConstants.TRANSIENT_SCID ) ; 508 scr.registerClientRequestDispatcher( csub, 509 ORBConstants.PERSISTENT_SCID ) ; 510 scr.registerClientRequestDispatcher( csub, 511 ORBConstants.SC_TRANSIENT_SCID ) ; 512 scr.registerClientRequestDispatcher( csub, 513 ORBConstants.SC_PERSISTENT_SCID ) ; 514 scr.registerClientRequestDispatcher( csub, 515 ORBConstants.IISC_TRANSIENT_SCID ) ; 516 scr.registerClientRequestDispatcher( csub, 517 ORBConstants.IISC_PERSISTENT_SCID ) ; 518 scr.registerClientRequestDispatcher( csub, 519 ORBConstants.MINSC_TRANSIENT_SCID ) ; 520 scr.registerClientRequestDispatcher( csub, 521 ORBConstants.MINSC_PERSISTENT_SCID ) ; 522 523 CorbaServerRequestDispatcher sd = 525 RequestDispatcherDefault.makeServerRequestDispatcher( orb ); 526 scr.registerServerRequestDispatcher( sd, 527 ORBConstants.TOA_SCID ) ; 528 scr.registerServerRequestDispatcher( sd, 529 ORBConstants.TRANSIENT_SCID ) ; 530 scr.registerServerRequestDispatcher( sd, 531 ORBConstants.PERSISTENT_SCID ) ; 532 scr.registerServerRequestDispatcher( sd, 533 ORBConstants.SC_TRANSIENT_SCID ) ; 534 scr.registerServerRequestDispatcher( sd, 535 ORBConstants.SC_PERSISTENT_SCID ) ; 536 scr.registerServerRequestDispatcher( sd, 537 ORBConstants.IISC_TRANSIENT_SCID ) ; 538 scr.registerServerRequestDispatcher( sd, 539 ORBConstants.IISC_PERSISTENT_SCID ) ; 540 scr.registerServerRequestDispatcher( sd, 541 ORBConstants.MINSC_TRANSIENT_SCID ) ; 542 scr.registerServerRequestDispatcher( sd, 543 ORBConstants.MINSC_PERSISTENT_SCID ) ; 544 545 orb.setINSDelegate( 546 RequestDispatcherDefault.makeINSServerRequestDispatcher( orb ) ) ; 547 548 LocalClientRequestDispatcherFactory lcsf = 550 RequestDispatcherDefault.makeJIDLLocalClientRequestDispatcherFactory( 551 orb ) ; 552 scr.registerLocalClientRequestDispatcherFactory( lcsf, 553 ORBConstants.TOA_SCID ) ; 554 555 lcsf = 556 RequestDispatcherDefault.makePOALocalClientRequestDispatcherFactory( 557 orb ) ; 558 scr.registerLocalClientRequestDispatcherFactory( lcsf, 559 ORBConstants.TRANSIENT_SCID ) ; 560 scr.registerLocalClientRequestDispatcherFactory( lcsf, 561 ORBConstants.PERSISTENT_SCID ) ; 562 563 lcsf = RequestDispatcherDefault. 564 makeFullServantCacheLocalClientRequestDispatcherFactory( orb ) ; 565 scr.registerLocalClientRequestDispatcherFactory( lcsf, 566 ORBConstants.SC_TRANSIENT_SCID ) ; 567 scr.registerLocalClientRequestDispatcherFactory( lcsf, 568 ORBConstants.SC_PERSISTENT_SCID ) ; 569 570 lcsf = RequestDispatcherDefault. 571 makeInfoOnlyServantCacheLocalClientRequestDispatcherFactory( orb ) ; 572 scr.registerLocalClientRequestDispatcherFactory( lcsf, 573 ORBConstants.IISC_TRANSIENT_SCID ) ; 574 scr.registerLocalClientRequestDispatcherFactory( lcsf, 575 ORBConstants.IISC_PERSISTENT_SCID ) ; 576 577 lcsf = RequestDispatcherDefault. 578 makeMinimalServantCacheLocalClientRequestDispatcherFactory( orb ) ; 579 scr.registerLocalClientRequestDispatcherFactory( lcsf, 580 ORBConstants.MINSC_TRANSIENT_SCID ) ; 581 scr.registerLocalClientRequestDispatcherFactory( lcsf, 582 ORBConstants.MINSC_PERSISTENT_SCID ) ; 583 584 588 CorbaServerRequestDispatcher bootsd = 589 RequestDispatcherDefault.makeBootstrapServerRequestDispatcher( 590 orb ) ; 591 scr.registerServerRequestDispatcher( bootsd, "INIT" ) ; 592 scr.registerServerRequestDispatcher( bootsd, "TINI" ) ; 593 594 ObjectAdapterFactory oaf = OADefault.makeTOAFactory( orb ) ; 596 scr.registerObjectAdapterFactory( oaf, ORBConstants.TOA_SCID ) ; 597 598 oaf = OADefault.makePOAFactory( orb ) ; 599 scr.registerObjectAdapterFactory( oaf, ORBConstants.TRANSIENT_SCID ) ; 600 scr.registerObjectAdapterFactory( oaf, ORBConstants.PERSISTENT_SCID ) ; 601 scr.registerObjectAdapterFactory( oaf, ORBConstants.SC_TRANSIENT_SCID ) ; 602 scr.registerObjectAdapterFactory( oaf, ORBConstants.SC_PERSISTENT_SCID ) ; 603 scr.registerObjectAdapterFactory( oaf, ORBConstants.IISC_TRANSIENT_SCID ) ; 604 scr.registerObjectAdapterFactory( oaf, ORBConstants.IISC_PERSISTENT_SCID ) ; 605 scr.registerObjectAdapterFactory( oaf, ORBConstants.MINSC_TRANSIENT_SCID ) ; 606 scr.registerObjectAdapterFactory( oaf, ORBConstants.MINSC_PERSISTENT_SCID ) ; 607 } 608 } 609 610 | Popular Tags |