1. /*
  2. * @(#)POAORB.java 1.116 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. package com.sun.corba.se.internal.POA;
  8. import java.util.*;
  9. import java.net.InetAddress;
  10. import org.omg.PortableServer.*;
  11. import org.omg.CORBA.ORBPackage.InvalidName;
  12. import org.omg.CORBA.Any;
  13. import org.omg.CORBA.CompletionStatus;
  14. import org.omg.CORBA.INITIALIZE;
  15. import org.omg.CORBA.INTERNAL;
  16. import org.omg.CORBA.NVList;
  17. import org.omg.CORBA.ORBPackage.InvalidName ;
  18. import org.omg.CORBA.WrongTransaction;
  19. import org.omg.CORBA.portable.ObjectImpl;
  20. import org.omg.CORBA.portable.RemarshalException;
  21. import org.omg.CosNaming.NamingContext;
  22. import com.sun.corba.se.internal.core.*;
  23. import com.sun.corba.se.internal.ior.IIOPProfile;
  24. import com.sun.corba.se.internal.iiop.Connection;
  25. import com.sun.corba.se.internal.ior.IORTemplate;
  26. import com.sun.corba.se.internal.iiop.messages.ReplyMessage;
  27. import com.sun.corba.se.internal.orbutil.ORBUtility; //d11638
  28. import com.sun.corba.se.internal.orbutil.ORBConstants;
  29. import com.sun.corba.se.internal.orbutil.ORBClassLoader;
  30. import com.sun.corba.se.internal.corba.ClientDelegate;
  31. import com.sun.corba.se.internal.corba.CORBAObjectImpl;
  32. import com.sun.corba.se.internal.corba.RequestImpl;
  33. import com.sun.corba.se.internal.corba.ServerDelegate;
  34. import com.sun.corba.se.internal.Activation.BootStrapActivation;
  35. import com.sun.corba.se.ActivationIDL.Activator;
  36. import com.sun.corba.se.ActivationIDL.ActivatorHelper;
  37. import com.sun.corba.se.ActivationIDL.Locator;
  38. import com.sun.corba.se.ActivationIDL.LocatorHelper;
  39. import com.sun.corba.se.ActivationIDL.IIOP_CLEAR_TEXT;
  40. import com.sun.corba.se.ActivationIDL.EndPointInfo;
  41. public class POAORB extends com.sun.corba.se.internal.iiop.ORB
  42. {
  43. public static final int DefaultSCID = ORBConstants.TransientSCID;
  44. // This is the mapping from subcontract-class to subcontract-ids.
  45. private String[] scTable[] = {
  46. {ORBConstants.GenericPOAClient, ORBConstants.GenericPOAServer,
  47. Integer.toString(ORBConstants.TransientSCID)},
  48. {ORBConstants.GenericPOAClient, ORBConstants.GenericPOAServer,
  49. Integer.toString(ORBConstants.PersistentSCID)},
  50. {ORBConstants.ServantCachePOAClient, ORBConstants.GenericPOAServer,
  51. Integer.toString(ORBConstants.SCTransientSCID)},
  52. {ORBConstants.ServantCachePOAClient, ORBConstants.GenericPOAServer,
  53. Integer.toString(ORBConstants.SCPersistentSCID)},
  54. };
  55. // Information required for supporting persistence/activation:
  56. // orbdPort is port at which ORBD listens. This is embedded in persistent
  57. // objrefs so that ORBD gets invocations first and has a chance to activate
  58. // this server if necessary.
  59. //private int orbdPort=0; - Note: orbd ports now live in the GIOP endpoint list
  60. private boolean orbdPortInitialized=false;
  61. private boolean persistentPortInitialized=false;
  62. private int persistentServerId=0;
  63. boolean persistentServerIdInitialized=false;
  64. private String persistentServerName = null;
  65. private int persistentServerPort;
  66. private EndPoint serverEndPoint;
  67. // Stuff for supporting activation thru orbd
  68. private boolean serverIsORBActivated = false;
  69. private BadServerIdHandler badServerIdHandler = null;
  70. private String badServerIdHandlerClass = null;
  71. // POA stuff
  72. POAImpl rootPOA;
  73. org.omg.PortableServer.Current poaCurrent;
  74. Set poaManagers = Collections.synchronizedSet(new HashSet(4));
  75. DelegateImpl delegateImpl;
  76. // Combined list of initialization props, applet params, commandline args
  77. protected Properties allProps = new Properties();
  78. // List of property names recognized by this ORB.
  79. private static final String[] POAORBPropertyNames = {
  80. ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,
  81. ORBConstants.SERVER_ID_PROPERTY,
  82. ORBConstants.BAD_SERVER_ID_HANDLER_CLASS_PROPERTY,
  83. ORBConstants.ACTIVATED_PROPERTY
  84. };
  85. // This method creates the root POA. Note that this has the crucial
  86. // side-effect of starting the transport, which allocates server sockets
  87. // for listening for incoming requests. This is done indirectly
  88. // when the root POA creates its ior template, which requires an IIOP
  89. // address, which gets host and port, which starts the transport.
  90. protected POAImpl makeRootPOA( )
  91. {
  92. POAManagerImpl poaManager = new POAManagerImpl( this ) ;
  93. POAImpl result = new POAImpl( ORBConstants.ROOT_POA_NAME,
  94. poaManager, Policies.rootPOAPolicies, null, null, this ) ;
  95. return result;
  96. }
  97. /** Default constructor. Called from org.omg.CORBA.ORB.init().
  98. * This is the only constructor, and it must be followed by
  99. * the appropriate set_parameters() call from org.omg.CORBA.ORB.init().
  100. */
  101. public POAORB()
  102. {
  103. super();
  104. // We delay the evaluation of makeRootPOA until
  105. // a call to resolve_initial_references( "RootPOA" ).
  106. // The Future guarantees that makeRootPOA is only called once.
  107. Closure rpClosure = new Closure() {
  108. public Object evaluate() {
  109. return POAORB.this.makeRootPOA() ;
  110. }
  111. } ;
  112. registerInitialReference( ORBConstants.ROOT_POA_NAME,
  113. new Future( rpClosure ) ) ;
  114. poaCurrent = new POACurrent(this);
  115. registerInitialReference( ORBConstants.POA_CURRENT_NAME,
  116. new Constant( poaCurrent ) ) ;
  117. }
  118. /******************************************************************************
  119. * The following methods deal with ORB initialization and property parsing etc.
  120. * Only the first two set_parameters() are public; rest are internal methods.
  121. ******************************************************************************/
  122. /**
  123. * Initialize any necessary ORB state by parsing passed parameters/props.
  124. * Called from org.omg.CORBA.ORB.init(...).
  125. * @param args String arguments typcially from the main() method
  126. * @param props Properties that are specific to the application
  127. */
  128. protected void set_parameters(String[] args, java.util.Properties props)
  129. {
  130. super.set_parameters(args, props);
  131. initializePOA( );
  132. // The InetAddress objects are used to compare ORBInitialHost and
  133. // LocalHost. If these two are equal and persistentServerPort == ORBInitialPort
  134. // then BootStrap activation is started. ORB will act as ORBD+ORB
  135. try{
  136. if( ( persistentServerPort == ORBInitialPort )
  137. && ( ORBInitialPort != 0 )
  138. && getLocalHostName().equals(getHostName( ORBInitialHost )) )
  139. // This means that the ORB is started without ORBD and is listening
  140. // both BootStrap and other requests in one port
  141. {
  142. // BootStrapActivation calls getInitialService( "<ServiceName>")
  143. // and initializes all the services for resolve_initial_references to
  144. // work
  145. BootStrapActivation theActivation =
  146. new BootStrapActivation( this );
  147. theActivation.start( );
  148. }
  149. } catch( Exception e ){
  150. // If there is any exception here, do pointout it is a Bootstrap
  151. // initialization error.
  152. throw new INITIALIZE(MinorCodes.BOOTSTRAP_ERROR,
  153. CompletionStatus.COMPLETED_NO );
  154. }
  155. // Get all properties and store them for later use.
  156. if( props != null ) {
  157. allProps = (Properties)props.clone();
  158. }
  159. initPostProcessing();
  160. }
  161. private String getHostName(String host) throws java.net.UnknownHostException {
  162. return InetAddress.getByName( host ).getHostAddress();
  163. }
  164. /* keeping a copy of the getLocalHostName so that it can only be called
  165. * internally and the unauthorized clients cannot have access to the
  166. * localHost information, originally, the above code was calling getLocalHostName
  167. * from Connection.java. If the hostname is cached in Connection.java, then
  168. * it is a security hole, since any unauthorized client has access to
  169. * the host information. With this change it is used internally so the
  170. * security problem is resolved. Also in Connection.java, the getLocalHost()
  171. * implementation has changed to always call the
  172. * InetAddress.getLocalHost().getHostAddress()
  173. */
  174. private static String localHostString = null;
  175. private String getLocalHostName() {
  176. if (localHostString != null) {
  177. return localHostString;
  178. } else {
  179. try {
  180. synchronized (com.sun.corba.se.internal.POA.POAORB.class){
  181. if ( localHostString == null )
  182. localHostString = InetAddress.getLocalHost().getHostAddress();
  183. return localHostString;
  184. }
  185. } catch (Exception ex) {
  186. throw new INTERNAL(
  187. com.sun.corba.se.internal.orbutil.MinorCodes.GET_LOCAL_HOST_FAILED,
  188. CompletionStatus.COMPLETED_NO );
  189. }
  190. }
  191. }
  192. /**
  193. * Initialize any necessary ORB state by parsing passed parameters/props.
  194. * Called from org.omg.CORBA.ORB.init(...).
  195. * @param app the applet
  196. * @param props Properties that are specific to the application/applet
  197. */
  198. protected void set_parameters(java.applet.Applet app, java.util.Properties props)
  199. {
  200. super.set_parameters(app, props);
  201. initializePOA() ;
  202. // We will not support single address mode in Applets,
  203. // since Applets cannot act as ORBD.
  204. // Get all properties and store them for use later.
  205. if( props != null ) {
  206. allProps = (Properties)props.clone();
  207. }
  208. initPostProcessing();
  209. }
  210. /** Return a list of property names that this ORB is interested in.
  211. * This may be overridden by subclasses, but subclasses must call
  212. * super.getPropertyNames() to get all names.
  213. * Called from super.set_parameters() for both application and applets.
  214. */
  215. protected String[] getPropertyNames()
  216. {
  217. String[] names = super.getPropertyNames();
  218. String[] result = ORBUtility.concatenateStringArrays( names,
  219. POAORBPropertyNames ) ;
  220. if (ORBInitDebug)
  221. dprint( "getPropertyNames returns " +
  222. ORBUtility.objectToString( result ) ) ;
  223. return result ;
  224. }
  225. /** Set ORB internal variables using the properties specified.
  226. * Called from super.set_parameters() for both application and applets.
  227. */
  228. protected void parseProperties(java.util.Properties props)
  229. {
  230. super.parseProperties(props);
  231. // get persistent server port
  232. String serverPortStr = props.getProperty(
  233. ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY ) ;
  234. if (serverPortStr != null) {
  235. setPersistentServerPort(Integer.valueOf(serverPortStr).intValue());
  236. }
  237. // get persistent ServerId
  238. String persServerIdStr = props.getProperty( ORBConstants.SERVER_ID_PROPERTY ) ;
  239. if (persServerIdStr != null) {
  240. setPersistentServerId(Integer.valueOf(persServerIdStr).intValue());
  241. }
  242. //
  243. // BadServerIdHandler
  244. //
  245. badServerIdHandlerClass = props.getProperty(
  246. ORBConstants.BAD_SERVER_ID_HANDLER_CLASS_PROPERTY );
  247. // determine whether the server was ORB activated
  248. String activatedStr = props.getProperty( ORBConstants.ACTIVATED_PROPERTY ) ;
  249. if (activatedStr != null) {
  250. serverIsORBActivated = true;
  251. }
  252. // get all properties and store them for use later.
  253. Enumeration e = props.keys();
  254. while ( e.hasMoreElements() ) {
  255. Object key = e.nextElement();
  256. allProps.put(key, props.getProperty((String)key));
  257. }
  258. }
  259. private void initializePOA( )
  260. {
  261. // register subcontracts in the subcontractRegistry
  262. // this is overridden in the derived subclass to
  263. // register it's own subcontracts if any
  264. initSubcontractRegistry();
  265. delegateImpl = new DelegateImpl(this);
  266. }
  267. /** Do miscellaneous other initialization for subcontracts, registration
  268. * with ORBD, POA, etc.
  269. */
  270. protected void initPostProcessing()
  271. {
  272. // determine the ORBD port so that persistent objrefs can be
  273. // created.
  274. if (serverIsORBActivated) {
  275. try {
  276. Locator locator = LocatorHelper.narrow(
  277. resolve_initial_references( ORBConstants.SERVER_LOCATOR_NAME )) ;
  278. Collection serverEndpoints = getServerEndpoints();
  279. Iterator iterator = serverEndpoints.iterator();
  280. while (iterator.hasNext()) {
  281. EndPoint ep = (EndPoint) iterator.next();
  282. // REVISIT - use exception instead of -1.
  283. int port = locator.getEndpoint(ep.getType());
  284. if (port == -1) {
  285. port = locator.getEndpoint(EndPoint.IIOP_CLEAR_TEXT);
  286. if (port == -1) {
  287. throw new Exception("ORBD must support IIOP_CLEAR_TEXT");
  288. }
  289. }
  290. ep.setLocatorPort(port);
  291. }
  292. orbdPortInitialized = true;
  293. } catch (Exception ex) {
  294. throw new INITIALIZE(MinorCodes.ORBD_ERROR,
  295. CompletionStatus.COMPLETED_MAYBE);
  296. }
  297. }
  298. initServices();
  299. // Register back with the Activator (ORBD).
  300. // This is done at the end so that ORBD will not reply to the
  301. // client until this server has finished all initialization.
  302. if (serverIsORBActivated) {
  303. try {
  304. Activator activator = ActivatorHelper.narrow(
  305. resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )) ;
  306. Collection serverEndpoints =
  307. getServerGIOP().getServerEndpoints();
  308. EndPointInfo[] endpointList =
  309. new EndPointInfo[serverEndpoints.size()];
  310. Iterator iterator = serverEndpoints.iterator();
  311. int i = 0;
  312. while (iterator.hasNext()) {
  313. EndPoint ep = (EndPoint) iterator.next();
  314. endpointList[i] =
  315. new EndPointInfo(ep.getType(), ep.getPort());
  316. i++;
  317. }
  318. activator.registerEndpoints(
  319. getPersistentServerId(), orbId, endpointList);
  320. } catch (Exception ex) {
  321. throw new INITIALIZE(MinorCodes.ORBD_ERROR,
  322. CompletionStatus.COMPLETED_MAYBE);
  323. }
  324. }
  325. }
  326. // Convenience package method for getting poaCurrent
  327. public POACurrent getCurrent()
  328. {
  329. return (POACurrent)poaCurrent;
  330. }
  331. /******************************************************************************
  332. * The following internal methods are accessors/modifiers for ORB internal
  333. * variables.
  334. ******************************************************************************/
  335. /** Return the persistent-server-id of this server. This id is the same
  336. * across multiple activations of this server. This is in contrast to
  337. * com.sun.corba.se.internal.iiop.ORB.getTransientServerId() which returns a transient
  338. * id that is guaranteed to be different across multiple activations of
  339. * this server. The user/environment is required to supply the
  340. * persistent-server-id every time this server is started, in
  341. * the ORBServerId parameter, System properties, or other means.
  342. * The user is also required to ensure that no two persistent servers
  343. * on the same host have the same server-id.
  344. */
  345. public int getPersistentServerId()
  346. {
  347. if ( persistentServerIdInitialized )
  348. return persistentServerId;
  349. else
  350. throw new INITIALIZE(
  351. "Persistent Server Id not initialized",
  352. MinorCodes.PERSISTENT_SERVERID_NOT_SET,
  353. CompletionStatus.COMPLETED_MAYBE);
  354. }
  355. /** Set the persistent-server-id of this server. This id is the same
  356. * across multiple activations of this server. The id can be set to any
  357. * integer value other than 0. This id must be set before any persistent
  358. * objects can be created.
  359. */
  360. public void setPersistentServerId(int id)
  361. {
  362. persistentServerId = id;
  363. persistentServerIdInitialized = true;
  364. }
  365. public boolean getPersistentServerIdInitialized()
  366. {
  367. return persistentServerIdInitialized;
  368. }
  369. public void setPersistentServerPort(int sp)
  370. {
  371. if ( persistentPortInitialized )
  372. throw new INTERNAL(MinorCodes.PERSISTENT_SERVERPORT_ERROR,
  373. CompletionStatus.COMPLETED_MAYBE);
  374. // Create an endpoint for the port.
  375. // Note: for transient servers, a ServerSocket is created lazily,
  376. // only when an objref is created, which allows the ORB to work in
  377. // applets which do not allow ServerSockets to be created.
  378. // But for persistent servers, it is possible that the server is
  379. // servicing a persistent objref which was created on a previous
  380. // incarnation. Hence we have to create the ServerSocket now.
  381. // getEndpoint is defined in com.sun.corba.se.internal.iiop.GIOPImpl;
  382. // it creates the ServerSocket, listenerThread and sets listenerPort.
  383. // Changed on 11/24 to unify the port for Alliance delivery
  384. // With this change the POAORB can work without ORBD and it
  385. // will listen all the requests on one port if ORBInitialPort = ORBServerPort.
  386. // Start the Listener thread only of the ports are different, otherwise
  387. // it will be started from the BootStrapServer.
  388. if( sp != ORBInitialPort )
  389. {
  390. ServerGIOP sgiop = getServerGIOP();
  391. serverEndPoint = sgiop.getEndpoint(EndPoint.IIOP_CLEAR_TEXT, sp, null);
  392. }
  393. persistentServerPort = sp;
  394. persistentPortInitialized = true;
  395. }
  396. public org.omg.CORBA.Object getInitialService( String theKey )
  397. {
  398. // Simply return Null, If the end user wants to replace
  399. // any of the initial Service then this method has to be
  400. // overridden and a particular service handle shold be
  401. // returned based upon the Key.
  402. // This method is useful for replacing Sun's NameService
  403. // with Vendor's NameService
  404. return null;
  405. }
  406. public int getPersistentServerPort(String socketType)
  407. {
  408. if ( orbdPortInitialized ) // this server is activated by orbd
  409. return getServerGIOP().getPersistentServerPort(socketType);
  410. else if ( persistentPortInitialized ) // this is a user-activated server
  411. return persistentServerPort;
  412. else
  413. throw new INITIALIZE("Persistent Server Port not initialized",
  414. MinorCodes.PERSISTENT_SERVERPORT_NOT_SET,
  415. CompletionStatus.COMPLETED_MAYBE);
  416. }
  417. // This overrides iiop.ORB.getServerPort.
  418. public int getServerPort(String socketType)
  419. {
  420. if ( serverIsORBActivated ) {
  421. return getPersistentServerPort(socketType);
  422. } else {
  423. return super.getServerPort(socketType);
  424. }
  425. }
  426. public EndPoint getServerEndpoint()
  427. {
  428. if ( serverEndPoint == null ) { // create one
  429. ServerGIOP sgiop = getServerGIOP();
  430. sgiop.initEndpoints();
  431. serverEndPoint = sgiop.getDefaultEndpoint();
  432. }
  433. return serverEndPoint;
  434. }
  435. public Collection getServerEndpoints()
  436. {
  437. getServerGIOP().initEndpoints();
  438. return getServerGIOP().getServerEndpoints();
  439. }
  440. /**
  441. * The bad server id handler is used by the Locator to
  442. * send back the location of a persistant server to the client.
  443. */
  444. public BadServerIdHandler getBadServerIdHandler()
  445. {
  446. return badServerIdHandler;
  447. }
  448. public void setBadServerIdHandler(BadServerIdHandler handler)
  449. {
  450. badServerIdHandler = handler;
  451. }
  452. public String getBadServerIdHandlerClass()
  453. {
  454. return badServerIdHandlerClass;
  455. }
  456. protected void removePoaManager(POAManager manager) {
  457. poaManagers.remove(manager);
  458. }
  459. protected void addPoaManager(POAManager manager) {
  460. poaManagers.add(manager);
  461. }
  462. public synchronized POA getRootPOA()
  463. {
  464. if (rootPOA == null) {
  465. try {
  466. Object obj = resolve_initial_references(
  467. ORBConstants.ROOT_POA_NAME ) ;
  468. rootPOA = (POAImpl)obj ;
  469. } catch (InvalidName inv) {
  470. throw new INTERNAL() ;
  471. }
  472. }
  473. return rootPOA;
  474. }
  475. public String getORBId() {
  476. return orbId;
  477. }
  478. /******************************************************************************
  479. * The following public methods are for ORB shutdown.
  480. *
  481. ******************************************************************************/
  482. /** This method shuts down the ORB and causes orb.run() to return.
  483. * It will cause all POAManagers to be deactivated, which in turn
  484. * will cause all POAs to be deactivated.
  485. */
  486. protected void shutdownServants(boolean wait_for_completion) {
  487. // It is important to copy the list of POAManagers first because
  488. // pm.deactivate removes itself from poaManagers!
  489. Iterator managers = (new HashSet(poaManagers)).iterator();
  490. while ( managers.hasNext() ) {
  491. try {
  492. ((POAManager)managers.next()).deactivate(true, wait_for_completion);
  493. } catch ( org.omg.PortableServer.POAManagerPackage.AdapterInactive e ) {}
  494. }
  495. super.shutdownServants(wait_for_completion);
  496. }
  497. /** This method always returns false because the ORB never needs the
  498. * main thread to do work.
  499. */
  500. public boolean work_pending()
  501. {
  502. checkShutdownState();
  503. return false;
  504. }
  505. /** This method does nothing. It is not required by the spec to do anything!
  506. */
  507. public void perform_work()
  508. {
  509. checkShutdownState();
  510. }
  511. synchronized boolean isProcessingInvocation() {
  512. return isProcessingInvocation.get() == Boolean.TRUE;
  513. }
  514. //
  515. // Client side service context interceptors
  516. //
  517. /**
  518. * Called before the arguments are marshalled and before the
  519. * request is sent. A derived class may override this hook to view the
  520. * service contexts that the ORB has prepared for this request. The
  521. * overriding method may also add new service contexts.
  522. * Note: this hook may be invoked concurrently by multiple threads.
  523. * However, ServiceContexts objects are not shared between threads.
  524. */
  525. protected void sendingRequestServiceContexts( ServiceContexts scs )
  526. {
  527. }
  528. /**
  529. * Called after the ORB receives a reply, before result is
  530. * unmarshalled. A derived class may override this hook to view the
  531. * service contexts that the ORB has received in this reply. The
  532. * overriding method should only view the received service contexts.
  533. * The contents of scs will be further processed by the ORB after
  534. * receivedServiceContexts returns.
  535. * Note: this hook may be invoked concurrently by multiple threads.
  536. * However, ServiceContexts objects are not shared between threads.
  537. */
  538. protected void receivedReplyServiceContexts(ServiceContexts scs)
  539. {
  540. }
  541. //
  542. // Server side service context interceptors
  543. //
  544. /**
  545. * Called after the ORB receives a request, before arguments are
  546. * unmarshalled. A derived class may override this hook to view the
  547. * service contexts that the ORB has received in this request. The
  548. * overriding method should only view the received service contexts.
  549. * The contents of scs will be further processed by the ORB after
  550. * receivedServiceContexts returns.
  551. * Note: this hook may be invoked concurrently by multiple threads.
  552. * However, ServiceContexts objects are not shared between threads.
  553. */
  554. protected void receivedRequestServiceContexts(ServiceContexts scs)
  555. {
  556. }
  557. /**
  558. * Called before the arguments are marshalled and before the
  559. * reply is sent. A derived class may override this hook to view the
  560. * service contexts that the ORB has prepared for this reply. The
  561. * overriding method may also add new service contexts.
  562. * Note: this hook may be invoked concurrently by multiple threads.
  563. * However, ServiceContexts objects are not shared between threads.
  564. */
  565. protected void sendingReplyServiceContexts(ServiceContexts scs)
  566. {
  567. }
  568. // Hook that can be overridden in a derived class to add more specific
  569. // subcontracts to the SubContractRegistry
  570. protected void initSubcontractRegistry() {
  571. for (int i =0; i<scTable.length;i++) {
  572. try {
  573. int scid = Integer.parseInt(scTable[i][2]);
  574. Class clientSCclass = ORBClassLoader.loadClass(scTable[i][0]);
  575. subcontractRegistry.registerClient(clientSCclass, scid);
  576. String serverSCclass = scTable[i][1];
  577. ServerSubcontract sc = (ServerSubcontract)
  578. ORBClassLoader.loadClass(serverSCclass).newInstance();
  579. sc.setOrb(this);
  580. sc.setId(scid);
  581. subcontractRegistry.registerServer(sc, scid);
  582. } catch (Exception exc) {
  583. if (subcontractDebugFlag)
  584. exc.printStackTrace();
  585. }
  586. }
  587. }
  588. // Hook to enable the subclassed ORBs to initialize their services
  589. // after POA creation
  590. protected void initServices()
  591. {
  592. }
  593. // Hook to enable the subclassed ORBs to put additional service
  594. // contexts while building a reply
  595. protected void getServiceSpecificServiceContexts(int scid,
  596. ServerRequest serverRequest,
  597. ServiceContexts contexts)
  598. {
  599. }
  600. public GenericPOAServerSC getServerSubcontract(POAImpl poa)
  601. {
  602. // here return the GenericPOAServerSC, and it takes care of handling
  603. // non-transactional cases
  604. Policies policies = poa.getPolicies();
  605. ServerSubcontract subcontract;
  606. if ( !policies.isPersistent() )
  607. subcontract = subcontractRegistry.getServerSubcontract(
  608. ORBConstants.TransientSCID);
  609. else
  610. subcontract = subcontractRegistry.getServerSubcontract(
  611. ORBConstants.PersistentSCID);
  612. return (GenericPOAServerSC) subcontract;
  613. }
  614. protected IOR objectReferenceCreated( IOR ior )
  615. {
  616. return ior ;
  617. }
  618. public boolean isLocalServerId( int subcontractId, int serverId )
  619. {
  620. if ((subcontractId < ORBConstants.FIRST_POA_SCID) ||
  621. (subcontractId > ORBConstants.MAX_POA_SCID))
  622. return super.isLocalServerId( subcontractId, serverId ) ;
  623. if (GenericPOAServerSC.isTransient( subcontractId ))
  624. return (serverId == getTransientServerId()) ;
  625. else if (persistentServerIdInitialized)
  626. return (serverId == getPersistentServerId()) ;
  627. else
  628. return false ;
  629. }
  630. //==============================================================================
  631. // In support of the Servant to be implemented by org.omg.CORBA_2_3.ORB s.
  632. //==============================================================================
  633. public void set_delegate(java.lang.Object servant){
  634. checkShutdownState();
  635. ((org.omg.PortableServer.Servant)servant)
  636. ._set_delegate(new DelegateImpl(this));
  637. }
  638. /**************************************************************************
  639. *
  640. * The following method is a hook for Portable IOR Interceptors
  641. *
  642. *************************************************************************/
  643. /**
  644. * Called when a new POA is created. This hook is empty in POAORB,
  645. * but will be filled in in PIORB. This allows us to ship both with and
  646. * without Portable Interceptor support without need to change any code.
  647. *
  648. * @param poaImpl The POAImpl associated with the interceptors to be
  649. * invoked.
  650. */
  651. protected void invokeIORInterceptors( POAImpl poaImpl ) {
  652. }
  653. /*
  654. **************************************************************************
  655. * The following methods are hooks for Portable Interceptors.
  656. * They have empty method bodies so that we may ship with or without
  657. * PI support. The actual implementations can be found in
  658. * Interceptors.PIORB. The uppermost implementations can be found
  659. * in corba.ORB. Some are explicitly overridden here in protected
  660. * scope so that we can access them from the classes in the POA package.
  661. *************************************************************************/
  662. /*
  663. *****************
  664. * Client PI hooks
  665. *****************/
  666. /**
  667. * Overridden from corba.ORB.
  668. * See description in corba.ORB.
  669. */
  670. protected void disableInterceptorsThisThread() {
  671. super.disableInterceptorsThisThread();
  672. }
  673. /**
  674. * Overridden from corba.ORB.
  675. * See description in corba.ORB.
  676. */
  677. protected void enableInterceptorsThisThread() {
  678. super.enableInterceptorsThisThread();
  679. }
  680. /**
  681. * Overridden from corba.ORB.
  682. * See description in corba.ORB.
  683. */
  684. protected void invokeClientPIStartingPoint()
  685. throws RemarshalException
  686. {
  687. super.invokeClientPIStartingPoint();
  688. }
  689. /**
  690. * Overridden from corba.ORB.
  691. * See description in corba.ORB.
  692. */
  693. protected Exception invokeClientPIEndingPoint(
  694. int replyStatus, Exception exception )
  695. {
  696. return super.invokeClientPIEndingPoint( replyStatus, exception );
  697. }
  698. /**
  699. * Overridden from corba.ORB.
  700. * See description in corba.ORB.
  701. */
  702. protected void initiateClientPIRequest( boolean diiRequest ) {
  703. super.initiateClientPIRequest( diiRequest );
  704. }
  705. /**
  706. * Overridden from corba.ORB.
  707. * See description in corba.ORB.
  708. */
  709. protected void cleanupClientPIRequest() {
  710. super.cleanupClientPIRequest();
  711. }
  712. /**
  713. * Overridden from corba.ORB.
  714. * See description in corba.ORB.
  715. */
  716. protected void setClientPIInfo( Connection connection,
  717. ClientDelegate delegate,
  718. IOR effectiveTarget,
  719. IIOPProfile profile,
  720. int requestId,
  721. String opName,
  722. boolean isOneWay,
  723. ServiceContexts svc )
  724. {
  725. super.setClientPIInfo( connection, delegate, effectiveTarget, profile,
  726. requestId, opName, isOneWay, svc );
  727. }
  728. /**
  729. * Overridden from corba.ORB.
  730. * See description in corba.ORB.
  731. */
  732. protected void setClientPIInfo( ClientResponse response ) {
  733. super.setClientPIInfo( response );
  734. }
  735. /**
  736. * Overridden from corba.ORB.
  737. * See description in corba.ORB.
  738. */
  739. protected void setClientPIInfo( RequestImpl requestImpl ) {
  740. super.setClientPIInfo( requestImpl );
  741. }
  742. /**
  743. * Overridden from corba.ORB.
  744. * See description in corba.ORB.
  745. */
  746. protected void sendCancelRequestIfFinalFragmentNotSent() {
  747. super.sendCancelRequestIfFinalFragmentNotSent();
  748. }
  749. /*
  750. *****************
  751. * Server PI hooks
  752. *****************/
  753. /**
  754. * Overridden from corba.ORB.
  755. * See description in corba.ORB.
  756. */
  757. protected void invokeServerPIStartingPoint()
  758. throws InternalRuntimeForwardRequest
  759. {
  760. super.invokeServerPIStartingPoint();
  761. }
  762. /**
  763. * Overridden from corba.ORB.
  764. * See description in corba.ORB.
  765. */
  766. protected void invokeServerPIIntermediatePoint()
  767. throws InternalRuntimeForwardRequest
  768. {
  769. super.invokeServerPIIntermediatePoint();
  770. }
  771. /**
  772. * Overridden from corba.ORB.
  773. * See description in corba.ORB.
  774. */
  775. protected void invokeServerPIEndingPoint( ReplyMessage replyMessage )
  776. throws InternalRuntimeForwardRequest
  777. {
  778. super.invokeServerPIEndingPoint( replyMessage );
  779. }
  780. /**
  781. * Overridden from corba.ORB.
  782. * See description in corba.ORB.
  783. */
  784. protected void initializeServerPIInfo( ServerRequest request,
  785. java.lang.Object poaimpl, byte[] objectId, byte[] adapterId )
  786. {
  787. super.initializeServerPIInfo( request, poaimpl, objectId, adapterId );
  788. }
  789. /**
  790. * Overridden from corba.ORB.
  791. * See description in corba.ORB.
  792. */
  793. protected void setServerPIInfo( java.lang.Object servant,
  794. String targetMostDerivedInterface )
  795. {
  796. super.setServerPIInfo( servant, targetMostDerivedInterface );
  797. }
  798. /**
  799. * Overridden from corba.ORB.
  800. * See description in corba.ORB.
  801. */
  802. protected void setServerPIInfo( Exception exception ) {
  803. super.setServerPIInfo( exception );
  804. }
  805. /**
  806. * Overridden from corba.ORB.
  807. * See description in corba.ORB.
  808. */
  809. protected void setServerPIInfo( NVList arguments ) {
  810. super.setServerPIInfo( arguments );
  811. }
  812. /**
  813. * Overridden from corba.ORB.
  814. * See description in corba.ORB.
  815. */
  816. protected void setServerPIExceptionInfo( Any exception ) {
  817. super.setServerPIExceptionInfo( exception );
  818. }
  819. /**
  820. * Overridden from corba.ORB.
  821. * See description in corba.ORB.
  822. */
  823. protected void setServerPIInfo( Any result ) {
  824. super.setServerPIInfo( result );
  825. }
  826. /**
  827. * Overridden from corba.ORB.
  828. * See description in corba.ORB.
  829. */
  830. protected void cleanupServerPIRequest() {
  831. super.cleanupServerPIRequest();
  832. }
  833. /*
  834. **************************************************************************
  835. * End Portable Interceptors Hooks
  836. *************************************************************************/
  837. // Check if the target objref has non-transactional SCID even though
  838. // servant is transactional. If so, throw return new IOR to be forwarded.
  839. public IOR checkTransactional( Servant servant, byte[] oid,
  840. POAImpl poa, int targetScid )
  841. {
  842. return null ;
  843. }
  844. // Hook for client subcontract to obtain Tx service context
  845. // for sending request
  846. public ServiceContext getTxServiceContext( int RequestId )
  847. {
  848. return null ;
  849. }
  850. // Hook for client subcontract to handle Tx service context
  851. // in received reply
  852. public void handleTxServiceContext( ServiceContexts scs,
  853. Exception exception, int requestId ) throws WrongTransaction
  854. {
  855. // NO-OP here
  856. }
  857. public void dump( String type )
  858. {
  859. if (type.equals( "serverSubcontract" ) )
  860. subcontractRegistry.dumpServers() ;
  861. }
  862. }