1. /*
  2. * @(#)POAImpl.java 1.138 04/03/01
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.oa.poa;
  8. import java.util.Collection ;
  9. import java.util.Set ;
  10. import java.util.HashSet ;
  11. import java.util.Map ;
  12. import java.util.HashMap ;
  13. import java.util.Iterator ;
  14. import org.omg.CORBA.Policy ;
  15. import org.omg.CORBA.SystemException ;
  16. import org.omg.PortableServer.POA ;
  17. import org.omg.PortableServer.Servant ;
  18. import org.omg.PortableServer.POAManager ;
  19. import org.omg.PortableServer.AdapterActivator ;
  20. import org.omg.PortableServer.ServantManager ;
  21. import org.omg.PortableServer.ForwardRequest ;
  22. import org.omg.PortableServer.ThreadPolicy;
  23. import org.omg.PortableServer.LifespanPolicy;
  24. import org.omg.PortableServer.IdUniquenessPolicy;
  25. import org.omg.PortableServer.IdAssignmentPolicy;
  26. import org.omg.PortableServer.ImplicitActivationPolicy;
  27. import org.omg.PortableServer.ServantRetentionPolicy;
  28. import org.omg.PortableServer.RequestProcessingPolicy;
  29. import org.omg.PortableServer.ThreadPolicyValue ;
  30. import org.omg.PortableServer.LifespanPolicyValue ;
  31. import org.omg.PortableServer.IdUniquenessPolicyValue ;
  32. import org.omg.PortableServer.IdAssignmentPolicyValue ;
  33. import org.omg.PortableServer.ImplicitActivationPolicyValue ;
  34. import org.omg.PortableServer.ServantRetentionPolicyValue ;
  35. import org.omg.PortableServer.RequestProcessingPolicyValue ;
  36. import org.omg.PortableServer.POAPackage.AdapterAlreadyExists ;
  37. import org.omg.PortableServer.POAPackage.AdapterNonExistent ;
  38. import org.omg.PortableServer.POAPackage.InvalidPolicy ;
  39. import org.omg.PortableServer.POAPackage.WrongPolicy ;
  40. import org.omg.PortableServer.POAPackage.WrongAdapter ;
  41. import org.omg.PortableServer.POAPackage.NoServant ;
  42. import org.omg.PortableServer.POAPackage.ServantAlreadyActive ;
  43. import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ;
  44. import org.omg.PortableServer.POAPackage.ServantNotActive ;
  45. import org.omg.PortableServer.POAPackage.ObjectNotActive ;
  46. import org.omg.PortableInterceptor.ObjectReferenceFactory ;
  47. import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
  48. import org.omg.PortableInterceptor.NON_EXISTENT ;
  49. import org.omg.IOP.TAG_INTERNET_IOP ;
  50. import com.sun.corba.se.spi.copyobject.CopierManager ;
  51. import com.sun.corba.se.spi.copyobject.ObjectCopier ;
  52. import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
  53. import com.sun.corba.se.spi.oa.OADestroyed ;
  54. import com.sun.corba.se.spi.oa.OAInvocationInfo ;
  55. import com.sun.corba.se.spi.oa.ObjectAdapter ;
  56. import com.sun.corba.se.spi.oa.ObjectAdapterBase ;
  57. import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
  58. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  59. import com.sun.corba.se.spi.ior.ObjectId ;
  60. import com.sun.corba.se.spi.ior.ObjectAdapterId ;
  61. import com.sun.corba.se.spi.ior.IOR ;
  62. import com.sun.corba.se.spi.ior.IORFactories ;
  63. import com.sun.corba.se.spi.ior.IORTemplate ;
  64. import com.sun.corba.se.spi.ior.IORTemplateList ;
  65. import com.sun.corba.se.spi.ior.TaggedProfile ;
  66. import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
  67. import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  68. import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
  69. import com.sun.corba.se.spi.orb.ORB ;
  70. import com.sun.corba.se.spi.protocol.ForwardException ;
  71. import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
  72. import com.sun.corba.se.impl.ior.POAObjectKeyTemplate ;
  73. import com.sun.corba.se.impl.ior.ObjectAdapterIdArray ;
  74. import com.sun.corba.se.impl.orbutil.ORBUtility;
  75. import com.sun.corba.se.impl.orbutil.ORBConstants;
  76. import com.sun.corba.se.impl.orbutil.concurrent.Sync ;
  77. import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
  78. import com.sun.corba.se.impl.orbutil.concurrent.ReentrantMutex ;
  79. import com.sun.corba.se.impl.orbutil.concurrent.CondVar ;
  80. /**
  81. * POAImpl is the implementation of the Portable Object Adapter. It
  82. * contains an implementation of the POA interfaces specified in
  83. * COBRA 2.3.1 chapter 11 (formal/99-10-07). This implementation
  84. * is moving to comply with CORBA 3.0 due to the many clarifications
  85. * that have been made to the POA semantics since CORBA 2.3.1.
  86. * Specific comments have been added where 3.0 applies, but note that
  87. * we do not have the new 3.0 APIs yet.
  88. */
  89. public class POAImpl extends ObjectAdapterBase implements POA
  90. {
  91. private boolean debug ;
  92. /* POA creation takes place in 2 stages: first, the POAImpl constructor is
  93. called, then the initialize method is called. This separation is
  94. needed because an AdapterActivator does not know the POAManager or
  95. the policies when
  96. the unknown_adapter method is invoked. However, the POA must be created
  97. before the unknown_adapter method is invoked, so that the parent knows
  98. when concurrent attempts are made to create the same POA.
  99. Calling the POAImpl constructor results in a new POA in state STATE_START.
  100. Calling initialize( POAManager, Policies ) results in state STATE_RUN.
  101. Calling destroy results in STATE_DESTROY, which marks the beginning of
  102. POA destruction.
  103. */
  104. // Notes on concurrency.
  105. // The POA requires careful design for concurrency management to correctly
  106. // implement the specification and avoid deadlocks. The order of acquiring
  107. // locks must respect the following locking hierarchy:
  108. //
  109. // 1. Lock POAs before POAManagers
  110. // 2. Lock a POA before locking its child POA
  111. //
  112. // Also note that there are 3 separate conditions on which threads may wait
  113. // in the POA, as defined by invokeCV, beingDestroyedCV, and
  114. // adapterActivatorCV. This means that (for this reason as well as others)
  115. // we cannot simply use the standard Java synchronized primitive.
  116. // This implementation uses a modified version of Doug Lea's
  117. // util.concurrent (version 1.3.0) that supports reentrant
  118. // mutexes to handle the locking. This will all be replaced by the new JSR
  119. // 166 concurrency primitives in J2SE 1.5 and later once the ORB moves to
  120. // J2SE 1.5.
  121. // POA state constants
  122. //
  123. // Note that ordering is important here: we must have the state defined in
  124. // this order so that ordered comparison is possible.
  125. // DO NOT CHANGE THE VALUES OF THE STATE CONSTANTS!!! In particular, the
  126. // initialization related states must be lower than STATE_RUN.
  127. //
  128. // POA is created in STATE_START
  129. //
  130. // Valid state transitions:
  131. //
  132. // START to INIT after find_POA constructor call
  133. // START to RUN after initialize completes
  134. // INIT to INIT_DONE after initialize completes
  135. // INIT to DESTROYED after failed unknown_adapter
  136. // INIT_DONE to RUN after successful unknown_adapter
  137. // STATE_RUN to STATE_DESTROYING after start of destruction
  138. // STATE_DESTROYING to STATE_DESTROYED after destruction completes.
  139. private static final int STATE_START = 0 ; // constructor complete
  140. private static final int STATE_INIT = 1 ; // waiting for adapter activator
  141. private static final int STATE_INIT_DONE = 2 ; // adapter activator called create_POA
  142. private static final int STATE_RUN = 3 ; // initialized and running
  143. private static final int STATE_DESTROYING = 4 ; // being destroyed
  144. private static final int STATE_DESTROYED = 5 ; // destruction complete
  145. private String stateToString()
  146. {
  147. switch (state) {
  148. case STATE_START :
  149. return "START" ;
  150. case STATE_INIT :
  151. return "INIT" ;
  152. case STATE_INIT_DONE :
  153. return "INIT_DONE" ;
  154. case STATE_RUN :
  155. return "RUN" ;
  156. case STATE_DESTROYING :
  157. return "DESTROYING" ;
  158. case STATE_DESTROYED :
  159. return "DESTROYED" ;
  160. default :
  161. return "UNKNOWN(" + state + ")" ;
  162. }
  163. }
  164. // Current state of the POA
  165. private int state ;
  166. // The POA request handler that performs all policy specific operations
  167. // Note that POAImpl handles all synchronization, so mediator is (mostly)
  168. // unsynchronized.
  169. private POAPolicyMediator mediator;
  170. // Representation of object adapter ID
  171. private int numLevels; // counts depth of tree. Root = 1.
  172. private ObjectAdapterId poaId ; // the actual object adapter ID for this POA
  173. private String name; // the name of this POA
  174. private POAManagerImpl manager; // This POA's POAManager
  175. private int uniquePOAId ; // ID for this POA that is unique relative
  176. // to the POAFactory, which has the same
  177. // lifetime as the ORB.
  178. private POAImpl parent; // The POA that created this POA.
  179. private Map children; // Map from name to POA of POAs created by
  180. // this POA.
  181. private AdapterActivator activator;
  182. private int invocationCount ; // pending invocations on this POA.
  183. // Data used to control POA concurrency
  184. // XXX revisit for JSR 166
  185. // Master lock for all POA synchronization. See lock and unlock.
  186. // package private for access by AOMEntry.
  187. Sync poaMutex ;
  188. // Wait on this CV for AdapterActivator upcalls to complete
  189. private CondVar adapterActivatorCV ;
  190. // Wait on this CV for all active invocations to complete
  191. private CondVar invokeCV ;
  192. // Wait on this CV for the destroy method to complete doing its work
  193. private CondVar beingDestroyedCV ;
  194. // thread local variable to store a boolean to detect deadlock in
  195. // POA.destroy().
  196. protected ThreadLocal isDestroying ;
  197. // This includes the most important information for debugging
  198. // POA problems.
  199. public String toString()
  200. {
  201. return "POA[" + poaId.toString() +
  202. ", uniquePOAId=" + uniquePOAId +
  203. ", state=" + stateToString() +
  204. ", invocationCount=" + invocationCount + "]" ;
  205. }
  206. // package private for mediator implementations.
  207. boolean getDebug()
  208. {
  209. return debug ;
  210. }
  211. // package private for access to servant to POA map
  212. static POAFactory getPOAFactory( ORB orb )
  213. {
  214. return (POAFactory)orb.getRequestDispatcherRegistry().
  215. getObjectAdapterFactory( ORBConstants.TRANSIENT_SCID ) ;
  216. }
  217. // package private so that POAFactory can access it.
  218. static POAImpl makeRootPOA( ORB orb )
  219. {
  220. POAManagerImpl poaManager = new POAManagerImpl( getPOAFactory( orb ),
  221. orb.getPIHandler() ) ;
  222. POAImpl result = new POAImpl( ORBConstants.ROOT_POA_NAME,
  223. null, orb, STATE_START ) ;
  224. result.initialize( poaManager, Policies.rootPOAPolicies ) ;
  225. return result ;
  226. }
  227. // package private so that POAPolicyMediatorBase can access it.
  228. int getPOAId()
  229. {
  230. return uniquePOAId ;
  231. }
  232. // package private so that POAPolicyMediator can access it.
  233. void lock()
  234. {
  235. SyncUtil.acquire( poaMutex ) ;
  236. if (debug) {
  237. ORBUtility.dprint( this, "LOCKED poa " + this ) ;
  238. }
  239. }
  240. // package private so that POAPolicyMediator can access it.
  241. void unlock()
  242. {
  243. if (debug) {
  244. ORBUtility.dprint( this, "UNLOCKED poa " + this ) ;
  245. }
  246. poaMutex.release() ;
  247. }
  248. // package private so that DelegateImpl can access it.
  249. Policies getPolicies()
  250. {
  251. return mediator.getPolicies() ;
  252. }
  253. // Note that the parent POA must be locked when this constructor is called.
  254. private POAImpl( String name, POAImpl parent, ORB orb, int initialState )
  255. {
  256. super( orb ) ;
  257. debug = orb.poaDebugFlag ;
  258. if (debug) {
  259. ORBUtility.dprint( this, "Creating POA with name=" + name +
  260. " parent=" + parent ) ;
  261. }
  262. this.state = initialState ;
  263. this.name = name ;
  264. this.parent = parent;
  265. children = new HashMap();
  266. activator = null ;
  267. // This was done in initialize, but I moved it here
  268. // to get better searchability when tracing.
  269. uniquePOAId = getPOAFactory( orb ).newPOAId() ;
  270. if (parent == null) {
  271. // This is the root POA, which counts as 1 level
  272. numLevels = 1 ;
  273. } else {
  274. // My level is one more than that of my parent
  275. numLevels = parent.numLevels + 1 ;
  276. parent.children.put(name, this);
  277. }
  278. // Get an array of all of the POA names in order to
  279. // create the poaid.
  280. String[] names = new String[ numLevels ] ;
  281. POAImpl poaImpl = this ;
  282. int ctr = numLevels - 1 ;
  283. while (poaImpl != null) {
  284. names[ctr--] = poaImpl.name ;
  285. poaImpl = poaImpl.parent ;
  286. }
  287. poaId = new ObjectAdapterIdArray( names ) ;
  288. invocationCount = 0;
  289. poaMutex = new ReentrantMutex( orb.poaConcurrencyDebugFlag ) ;
  290. adapterActivatorCV = new CondVar( poaMutex,
  291. orb.poaConcurrencyDebugFlag ) ;
  292. invokeCV = new CondVar( poaMutex,
  293. orb.poaConcurrencyDebugFlag ) ;
  294. beingDestroyedCV = new CondVar( poaMutex,
  295. orb.poaConcurrencyDebugFlag ) ;
  296. isDestroying = new ThreadLocal () {
  297. protected java.lang.Object initialValue() {
  298. return Boolean.FALSE;
  299. }
  300. };
  301. }
  302. // The POA lock must be held when this method is called.
  303. private void initialize( POAManagerImpl manager, Policies policies )
  304. {
  305. if (debug) {
  306. ORBUtility.dprint( this, "Initializing poa " + this +
  307. " with POAManager=" + manager + " policies=" + policies ) ;
  308. }
  309. this.manager = manager;
  310. manager.addPOA(this);
  311. mediator = POAPolicyMediatorFactory.create( policies, this ) ;
  312. // Construct the object key template
  313. int serverid = mediator.getServerId() ;
  314. int scid = mediator.getScid() ;
  315. String orbId = getORB().getORBData().getORBId();
  316. ObjectKeyTemplate oktemp = new POAObjectKeyTemplate( getORB(),
  317. scid, serverid, orbId, poaId ) ;
  318. if (debug) {
  319. ORBUtility.dprint( this, "Initializing poa: oktemp=" + oktemp ) ;
  320. }
  321. // Note that parent == null iff this is the root POA.
  322. // This was used to avoid executing interceptors on the RootPOA.
  323. // That is no longer necessary.
  324. boolean objectAdapterCreated = true; // parent != null ;
  325. // XXX extract codebase from policies and pass into initializeTemplate
  326. // after the codebase policy change is finalized.
  327. initializeTemplate( oktemp, objectAdapterCreated,
  328. policies,
  329. null, // codebase
  330. null, // manager id
  331. oktemp.getObjectAdapterId()
  332. ) ;
  333. if (state == STATE_START)
  334. state = STATE_RUN ;
  335. else if (state == STATE_INIT)
  336. state = STATE_INIT_DONE ;
  337. else
  338. throw lifecycleWrapper().illegalPoaStateTrans() ;
  339. }
  340. // The poaMutex must be held when this method is called
  341. private boolean waitUntilRunning()
  342. {
  343. if (debug) {
  344. ORBUtility.dprint( this,
  345. "Calling waitUntilRunning on poa " + this ) ;
  346. }
  347. while (state < STATE_RUN) {
  348. try {
  349. adapterActivatorCV.await() ;
  350. } catch (InterruptedException exc) {
  351. // NO-OP
  352. }
  353. }
  354. if (debug) {
  355. ORBUtility.dprint( this,
  356. "Exiting waitUntilRunning on poa " + this ) ;
  357. }
  358. // Note that a POA could be destroyed while in STATE_INIT due to a
  359. // failure in the AdapterActivator upcall.
  360. return (state == STATE_RUN) ;
  361. }
  362. // This method checks that the AdapterActivator finished the
  363. // initialization of a POA activated in find_POA. This is
  364. // determined by checking the state of the POA. If the state is
  365. // STATE_INIT, the AdapterActivator did not complete the
  366. // inialization. In this case, we destroy the POA that was
  367. // partially created and return false. Otherwise, we return true.
  368. // In any case, we must wake up all threads waiting for the adapter
  369. // activator, either to continue their invocations, or to return
  370. // errors to their client.
  371. //
  372. // The poaMutex must NOT be held when this method is called.
  373. private boolean destroyIfNotInitDone()
  374. {
  375. try {
  376. lock() ;
  377. if (debug) {
  378. ORBUtility.dprint( this,
  379. "Calling destroyIfNotInitDone on poa " + this ) ;
  380. }
  381. boolean success = (state == STATE_INIT_DONE) ;
  382. if (success)
  383. state = STATE_RUN ;
  384. else {
  385. // Don't just use destroy, because the check for
  386. // deadlock is too general, and can prevent this from
  387. // functioning properly.
  388. DestroyThread destroyer = new DestroyThread( false, debug );
  389. destroyer.doIt( this, true ) ;
  390. }
  391. return success ;
  392. } finally {
  393. adapterActivatorCV.broadcast() ;
  394. if (debug) {
  395. ORBUtility.dprint( this,
  396. "Exiting destroyIfNotInitDone on poa " + this ) ;
  397. }
  398. unlock() ;
  399. }
  400. }
  401. private byte[] internalReferenceToId(
  402. org.omg.CORBA.Object reference ) throws WrongAdapter
  403. {
  404. IOR ior = ORBUtility.getIOR( reference ) ;
  405. IORTemplateList thisTemplate = ior.getIORTemplates() ;
  406. ObjectReferenceFactory orf = getCurrentFactory() ;
  407. IORTemplateList poaTemplate =
  408. IORFactories.getIORTemplateList( orf ) ;
  409. if (!poaTemplate.isEquivalent( thisTemplate ))
  410. throw new WrongAdapter();
  411. // Extract the ObjectId from the first TaggedProfile in the IOR.
  412. // If ior was created in this POA, the same ID was used for
  413. // every profile through the profile templates in the currentFactory,
  414. // so we will get the same result from any profile.
  415. Iterator iter = ior.iterator() ;
  416. if (!iter.hasNext())
  417. throw iorWrapper().noProfilesInIor() ;
  418. TaggedProfile prof = (TaggedProfile)(iter.next()) ;
  419. ObjectId oid = prof.getObjectId() ;
  420. return oid.getId();
  421. }
  422. // Converted from anonymous class to local class
  423. // so that we can call performDestroy() directly.
  424. static class DestroyThread extends Thread {
  425. private boolean wait ;
  426. private boolean etherealize ;
  427. private boolean debug ;
  428. private POAImpl thePoa ;
  429. public DestroyThread( boolean etherealize, boolean debug )
  430. {
  431. this.etherealize = etherealize ;
  432. this.debug = debug ;
  433. }
  434. public void doIt( POAImpl thePoa, boolean wait )
  435. {
  436. if (debug) {
  437. ORBUtility.dprint( this,
  438. "Calling DestroyThread.doIt(thePOA=" + thePoa +
  439. " wait=" + wait + " etherealize=" + etherealize ) ;
  440. }
  441. this.thePoa = thePoa ;
  442. this.wait = wait ;
  443. if (wait) {
  444. run() ;
  445. } else {
  446. // Catch exceptions since setDaemon can cause a
  447. // security exception to be thrown under netscape
  448. // in the Applet mode
  449. try { setDaemon(true); } catch (Exception e) {}
  450. start() ;
  451. }
  452. }
  453. public void run()
  454. {
  455. Set destroyedPOATemplates = new HashSet() ;
  456. performDestroy( thePoa, destroyedPOATemplates );
  457. Iterator iter = destroyedPOATemplates.iterator() ;
  458. ObjectReferenceTemplate[] orts = new ObjectReferenceTemplate[
  459. destroyedPOATemplates.size() ] ;
  460. int index = 0 ;
  461. while (iter.hasNext())
  462. orts[ index++ ] = (ObjectReferenceTemplate)iter.next();
  463. thePoa.getORB().getPIHandler().adapterStateChanged( orts,
  464. NON_EXISTENT.value ) ;
  465. }
  466. // Returns true if destruction must be completed, false
  467. // if not, which means that another thread is already
  468. // destroying poa.
  469. private boolean prepareForDestruction( POAImpl poa,
  470. Set destroyedPOATemplates )
  471. {
  472. POAImpl[] childPoas = null ;
  473. // Note that we do not synchronize on this, since this is
  474. // the PerformDestroy instance, not the POA.
  475. try {
  476. poa.lock() ;
  477. if (debug) {
  478. ORBUtility.dprint( this,
  479. "Calling performDestroy on poa " + poa ) ;
  480. }
  481. if (poa.state <= STATE_RUN) {
  482. poa.state = STATE_DESTROYING ;
  483. } else {
  484. // destroy may be called multiple times, and each call
  485. // is allowed to proceed with its own setting of the wait
  486. // flag, but the etherealize value is used from the first
  487. // call to destroy. Also all children should be destroyed
  488. // before the parent POA. If the poa is already destroyed,
  489. // we can just return. If the poa has started destruction,
  490. // but not completed, and wait is true, we need to wait
  491. // until destruction is complete, then just return.
  492. if (wait)
  493. while (poa.state != STATE_DESTROYED) {
  494. try {
  495. poa.beingDestroyedCV.await() ;
  496. } catch (InterruptedException exc) {
  497. // NO-OP
  498. }
  499. }
  500. return false ;
  501. }
  502. poa.isDestroying.set(Boolean.TRUE);
  503. // Make a copy since we can't hold the lock while destroying
  504. // the children, and an iterator is not deletion-safe.
  505. childPoas = (POAImpl[])poa.children.values().toArray(
  506. new POAImpl[0] );
  507. } finally {
  508. poa.unlock() ;
  509. }
  510. // We are not holding the POA mutex here to avoid holding it
  511. // while destroying the POA's children, since this may involve
  512. // upcalls to etherealize methods.
  513. for (int ctr=0; ctr<childPoas.length; ctr++ ) {
  514. performDestroy( childPoas[ctr], destroyedPOATemplates ) ;
  515. }
  516. return true ;
  517. }
  518. public void performDestroy( POAImpl poa, Set destroyedPOATemplates )
  519. {
  520. if (!prepareForDestruction( poa, destroyedPOATemplates ))
  521. return ;
  522. // NOTE: If we are here, poa is in STATE_DESTROYING state. All
  523. // other state checks are taken care of in prepareForDestruction.
  524. // No other threads may either be starting new invocations
  525. // by calling enter or starting to destroy poa. There may
  526. // still be pending invocations.
  527. POAImpl parent = poa.parent ;
  528. boolean isRoot = parent == null ;
  529. try {
  530. // Note that we must lock the parent before the child.
  531. // The parent lock is required (if poa is not the root)
  532. // to safely remove poa from parent's children Map.
  533. if (!isRoot)
  534. parent.lock() ;
  535. try {
  536. poa.lock() ;
  537. completeDestruction( poa, parent,
  538. destroyedPOATemplates ) ;
  539. } finally {
  540. poa.unlock() ;
  541. if (isRoot)
  542. // We have just destroyed the root POA, so we need to
  543. // make sure that the next call to
  544. // resolve_initial_reference( "RootPOA" )
  545. // will recreate a valid root POA.
  546. poa.manager.getFactory().registerRootPOA() ;
  547. }
  548. } finally {
  549. if (!isRoot) {
  550. parent.unlock() ;
  551. poa.parent = null ;
  552. }
  553. }
  554. }
  555. private void completeDestruction( POAImpl poa, POAImpl parent,
  556. Set destroyedPOATemplates )
  557. {
  558. if (debug) {
  559. ORBUtility.dprint( this,
  560. "Calling completeDestruction on poa " + poa ) ;
  561. }
  562. try {
  563. while (poa.invocationCount != 0) {
  564. try {
  565. poa.invokeCV.await() ;
  566. } catch (InterruptedException ex) {
  567. // NO-OP
  568. }
  569. }
  570. if (poa.mediator != null) {
  571. if (etherealize)
  572. poa.mediator.etherealizeAll();
  573. poa.mediator.clearAOM() ;
  574. }
  575. if (poa.manager != null)
  576. poa.manager.removePOA(poa);
  577. if (parent != null)
  578. parent.children.remove( poa.name ) ;
  579. destroyedPOATemplates.add( poa.getAdapterTemplate() ) ;
  580. } catch (Throwable thr) {
  581. if (thr instanceof ThreadDeath)
  582. throw (ThreadDeath)thr ;
  583. poa.lifecycleWrapper().unexpectedException( thr, poa.toString() ) ;
  584. } finally {
  585. poa.state = STATE_DESTROYED ;
  586. poa.beingDestroyedCV.broadcast();
  587. poa.isDestroying.set(Boolean.FALSE);
  588. if (debug) {
  589. ORBUtility.dprint( this,
  590. "Exiting completeDestruction on poa " + poa ) ;
  591. }
  592. }
  593. }
  594. }
  595. void etherealizeAll()
  596. {
  597. try {
  598. lock() ;
  599. if (debug) {
  600. ORBUtility.dprint( this,
  601. "Calling etheralizeAll on poa " + this ) ;
  602. }
  603. mediator.etherealizeAll() ;
  604. } finally {
  605. if (debug) {
  606. ORBUtility.dprint( this,
  607. "Exiting etheralizeAll on poa " + this ) ;
  608. }
  609. unlock() ;
  610. }
  611. }
  612. //*******************************************************************
  613. // Public POA API
  614. //*******************************************************************
  615. /**
  616. * <code>create_POA</code>
  617. * <b>Section 3.3.8.2</b>
  618. */
  619. public POA create_POA(String name, POAManager
  620. theManager, Policy[] policies) throws AdapterAlreadyExists,
  621. InvalidPolicy
  622. {
  623. try {
  624. lock() ;
  625. if (debug) {
  626. ORBUtility.dprint( this, "Calling create_POA(name=" + name +
  627. " theManager=" + theManager + " policies=" + policies +
  628. ") on poa " + this ) ;
  629. }
  630. // We cannot create children of a POA that is (being) destroyed.
  631. // This has been added to the CORBA 3.0 spec.
  632. if (state > STATE_RUN)
  633. throw omgLifecycleWrapper().createPoaDestroy() ;
  634. POAImpl poa = (POAImpl)(children.get(name)) ;
  635. if (poa == null) {
  636. poa = new POAImpl( name, this, getORB(), STATE_START ) ;
  637. }
  638. try {
  639. poa.lock() ;
  640. if (debug) {
  641. ORBUtility.dprint( this,
  642. "Calling create_POA: new poa is " + poa ) ;
  643. }
  644. if ((poa.state != STATE_START) && (poa.state != STATE_INIT))
  645. throw new AdapterAlreadyExists();
  646. POAManagerImpl newManager = (POAManagerImpl)theManager ;
  647. if (newManager == null)
  648. newManager = new POAManagerImpl( manager.getFactory(),
  649. manager.getPIHandler() );
  650. int defaultCopierId =
  651. getORB().getCopierManager().getDefaultId() ;
  652. Policies POAPolicies =
  653. new Policies( policies, defaultCopierId ) ;
  654. poa.initialize( newManager, POAPolicies ) ;
  655. return poa;
  656. } finally {
  657. poa.unlock() ;
  658. }
  659. } finally {
  660. unlock() ;
  661. }
  662. }
  663. /**
  664. * <code>find_POA</code>
  665. * <b>Section 3.3.8.3</b>
  666. */
  667. public POA find_POA(String name, boolean activate)
  668. throws AdapterNonExistent
  669. {
  670. POAImpl found = null ;
  671. AdapterActivator act = null ;
  672. lock() ;
  673. if (debug) {
  674. ORBUtility.dprint( this, "Calling find_POA(name=" + name +
  675. " activate=" + activate + ") on poa " + this ) ;
  676. }
  677. found = (POAImpl) children.get(name);
  678. if (found != null) {
  679. if (debug) {
  680. ORBUtility.dprint( this,
  681. "Calling find_POA: found poa " + found ) ;
  682. }
  683. try {
  684. found.lock() ;
  685. // Do not hold the parent POA lock while
  686. // waiting for child to complete initialization.
  687. unlock() ;
  688. // Make sure that the child has completed its initialization,
  689. // if it was created by an AdapterActivator, otherwise throw
  690. // a standard TRANSIENT exception with minor code 4 (see
  691. // CORBA 3.0 11.3.9.3, in reference to unknown_adapter)
  692. if (!found.waitUntilRunning())
  693. throw omgLifecycleWrapper().poaDestroyed() ;
  694. // Note that found may be in state DESTROYING or DESTROYED at
  695. // this point. That's OK, since destruction could start at
  696. // any time.
  697. } finally {
  698. found.unlock() ;
  699. }
  700. } else {
  701. try {
  702. if (debug) {
  703. ORBUtility.dprint( this,
  704. "Calling find_POA: no poa found" ) ;
  705. }
  706. if (activate && (activator != null)) {
  707. // Create a child, but don't initialize it. The newly
  708. // created POA will be in state STATE_START, which will
  709. // cause other calls to find_POA that are creating the same
  710. // POA to block on the waitUntilRunning call above.
  711. // Initialization must be completed by a call to create_POA
  712. // inside the unknown_adapter upcall. Note that
  713. // this.poaMutex must be held here so that this.children
  714. // can be safely updated. The state is set to STATE_INIT
  715. // so that initialize can make the correct state transition
  716. // when create_POA is called inside the AdapterActivator.
  717. // This avoids activating the new POA too soon
  718. // by transitioning to STATE_RUN after unknown_adapter
  719. // returns.
  720. found = new POAImpl( name, this, getORB(), STATE_INIT ) ;
  721. if (debug) {
  722. ORBUtility.dprint( this,
  723. "Calling find_POA: created poa " + found ) ;
  724. }
  725. act = activator ;
  726. } else {
  727. throw new AdapterNonExistent();
  728. }
  729. } finally {
  730. unlock() ;
  731. }
  732. }
  733. // assert (found != null)
  734. // assert not holding this.poaMutex OR found.poaMutex
  735. // We must not hold either this.poaMutex or found.poaMutex here while
  736. // waiting for intialization of found to complete to prevent possible
  737. // deadlocks.
  738. if (act != null) {
  739. boolean status = false ;
  740. boolean adapterResult = false ;
  741. if (debug) {
  742. ORBUtility.dprint( this,
  743. "Calling find_POA: calling AdapterActivator" ) ;
  744. }
  745. try {
  746. // Prevent more than one thread at a time from executing in act
  747. // in case act is shared between multiple POAs.
  748. synchronized (act) {
  749. status = act.unknown_adapter(this, name);
  750. }
  751. } catch (SystemException exc) {
  752. throw omgLifecycleWrapper().adapterActivatorException( exc,
  753. name, poaId.toString() ) ;
  754. } catch (Throwable thr) {
  755. // ignore most non-system exceptions, but log them for
  756. // diagnostic purposes.
  757. lifecycleWrapper().unexpectedException( thr, this.toString() ) ;
  758. if (thr instanceof ThreadDeath)
  759. throw (ThreadDeath)thr ;
  760. } finally {
  761. // At this point, we have completed adapter activation.
  762. // Whether this was successful or not, we must call
  763. // destroyIfNotInitDone so that calls to enter() and create_POA()
  764. // that are waiting can execute again. Failing to do this
  765. // will cause the system to hang in complex tests.
  766. adapterResult = found.destroyIfNotInitDone() ;
  767. }
  768. if (status) {
  769. if (!adapterResult)
  770. throw omgLifecycleWrapper().adapterActivatorException( name,
  771. poaId.toString() ) ;
  772. } else {
  773. if (debug) {
  774. ORBUtility.dprint( this,
  775. "Calling find_POA: AdapterActivator returned false" ) ;
  776. }
  777. // OMG Issue 3740 is resolved to throw AdapterNonExistent if
  778. // unknown_adapter() returns false.
  779. throw new AdapterNonExistent();
  780. }
  781. }
  782. return found;
  783. }
  784. /**
  785. * <code>destroy</code>
  786. * <b>Section 3.3.8.4</b>
  787. */
  788. public void destroy(boolean etherealize, boolean wait_for_completion)
  789. {
  790. // This is to avoid deadlock
  791. if (wait_for_completion && getORB().isDuringDispatch()) {
  792. throw lifecycleWrapper().destroyDeadlock() ;
  793. }
  794. DestroyThread destroyer = new DestroyThread( etherealize, debug );
  795. destroyer.doIt( this, wait_for_completion ) ;
  796. }
  797. /**
  798. * <code>create_thread_policy</code>
  799. * <b>Section 3.3.8.5</b>
  800. */
  801. public ThreadPolicy create_thread_policy(
  802. ThreadPolicyValue value)
  803. {
  804. return new ThreadPolicyImpl(value);
  805. }
  806. /**
  807. * <code>create_lifespan_policy</code>
  808. * <b>Section 3.3.8.5</b>
  809. */
  810. public LifespanPolicy create_lifespan_policy(
  811. LifespanPolicyValue value)
  812. {
  813. return new LifespanPolicyImpl(value);
  814. }
  815. /**
  816. * <code>create_id_uniqueness_policy</code>
  817. * <b>Section 3.3.8.5</b>
  818. */
  819. public IdUniquenessPolicy create_id_uniqueness_policy(
  820. IdUniquenessPolicyValue value)
  821. {
  822. return new IdUniquenessPolicyImpl(value);
  823. }
  824. /**
  825. * <code>create_id_assignment_policy</code>
  826. * <b>Section 3.3.8.5</b>
  827. */
  828. public IdAssignmentPolicy create_id_assignment_policy(
  829. IdAssignmentPolicyValue value)
  830. {
  831. return new IdAssignmentPolicyImpl(value);
  832. }
  833. /**
  834. * <code>create_implicit_activation_policy</code>
  835. * <b>Section 3.3.8.5</b>
  836. */
  837. public ImplicitActivationPolicy create_implicit_activation_policy(
  838. ImplicitActivationPolicyValue value)
  839. {
  840. return new ImplicitActivationPolicyImpl(value);
  841. }
  842. /**
  843. * <code>create_servant_retention_policy</code>
  844. * <b>Section 3.3.8.5</b>
  845. */
  846. public ServantRetentionPolicy create_servant_retention_policy(
  847. ServantRetentionPolicyValue value)
  848. {
  849. return new ServantRetentionPolicyImpl(value);
  850. }
  851. /**
  852. * <code>create_request_processing_policy</code>
  853. * <b>Section 3.3.8.5</b>
  854. */
  855. public RequestProcessingPolicy create_request_processing_policy(
  856. RequestProcessingPolicyValue value)
  857. {
  858. return new RequestProcessingPolicyImpl(value);
  859. }
  860. /**
  861. * <code>the_name</code>
  862. * <b>Section 3.3.8.6</b>
  863. */
  864. public String the_name()
  865. {
  866. try {
  867. lock() ;
  868. return name;
  869. } finally {
  870. unlock() ;
  871. }
  872. }
  873. /**
  874. * <code>the_parent</code>
  875. * <b>Section 3.3.8.7</b>
  876. */
  877. public POA the_parent()
  878. {
  879. try {
  880. lock() ;
  881. return parent;
  882. } finally {
  883. unlock() ;
  884. }
  885. }
  886. /**
  887. * <code>the_children</code>
  888. */
  889. public org.omg.PortableServer.POA[] the_children()
  890. {
  891. try {
  892. lock() ;
  893. Collection coll = children.values() ;
  894. int size = coll.size() ;
  895. POA[] result = new POA[ size ] ;
  896. int index = 0 ;
  897. Iterator iter = coll.iterator() ;
  898. while (iter.hasNext()) {
  899. POA poa = (POA)(iter.next()) ;
  900. result[ index++ ] = poa ;
  901. }
  902. return result ;
  903. } finally {
  904. unlock() ;
  905. }
  906. }
  907. /**
  908. * <code>the_POAManager</code>
  909. * <b>Section 3.3.8.8</b>
  910. */
  911. public POAManager the_POAManager()
  912. {
  913. try {
  914. lock() ;
  915. return manager;
  916. } finally {
  917. unlock() ;
  918. }
  919. }
  920. /**
  921. * <code>the_activator</code>
  922. * <b>Section 3.3.8.9</b>
  923. */
  924. public AdapterActivator the_activator()
  925. {
  926. try {
  927. lock() ;
  928. return activator;
  929. } finally {
  930. unlock() ;
  931. }
  932. }
  933. /**
  934. * <code>the_activator</code>
  935. * <b>Section 3.3.8.9</b>
  936. */
  937. public void the_activator(AdapterActivator activator)
  938. {
  939. try {
  940. lock() ;
  941. if (debug) {
  942. ORBUtility.dprint( this, "Calling the_activator on poa " +
  943. this + " activator=" + activator ) ;
  944. }
  945. this.activator = activator;
  946. } finally {
  947. unlock() ;
  948. }
  949. }
  950. /**
  951. * <code>get_servant_manager</code>
  952. * <b>Section 3.3.8.10</b>
  953. */
  954. public ServantManager get_servant_manager() throws WrongPolicy
  955. {
  956. try {
  957. lock() ;
  958. return mediator.getServantManager() ;
  959. } finally {
  960. unlock() ;
  961. }
  962. }
  963. /**
  964. * <code>set_servant_manager</code>
  965. * <b>Section 3.3.8.10</b>
  966. */
  967. public void set_servant_manager(ServantManager servantManager)
  968. throws WrongPolicy
  969. {
  970. try {
  971. lock() ;
  972. if (debug) {
  973. ORBUtility.dprint( this, "Calling set_servant_manager on poa " +
  974. this + " servantManager=" + servantManager ) ;
  975. }
  976. mediator.setServantManager( servantManager ) ;
  977. } finally {
  978. unlock() ;
  979. }
  980. }
  981. /**
  982. * <code>get_servant</code>
  983. * <b>Section 3.3.8.12</b>
  984. */
  985. public Servant get_servant() throws NoServant, WrongPolicy
  986. {
  987. try {
  988. lock() ;
  989. return mediator.getDefaultServant() ;
  990. } finally {
  991. unlock() ;
  992. }
  993. }
  994. /**
  995. * <code>set_servant</code>
  996. * <b>Section 3.3.8.13</b>
  997. */
  998. public void set_servant(Servant defaultServant)
  999. throws WrongPolicy
  1000. {
  1001. try {
  1002. lock() ;
  1003. if (debug) {
  1004. ORBUtility.dprint( this, "Calling set_servant on poa " +
  1005. this + " defaultServant=" + defaultServant ) ;
  1006. }
  1007. mediator.setDefaultServant( defaultServant ) ;
  1008. } finally {
  1009. unlock() ;
  1010. }
  1011. }
  1012. /**
  1013. * <code>activate_object</code>
  1014. * <b>Section 3.3.8.14</b>
  1015. */
  1016. public byte[] activate_object(Servant servant)
  1017. throws ServantAlreadyActive, WrongPolicy
  1018. {
  1019. try {
  1020. lock() ;
  1021. if (debug) {
  1022. ORBUtility.dprint( this,
  1023. "Calling activate_object on poa " + this +
  1024. " (servant=" + servant + ")" ) ;
  1025. }
  1026. // Allocate a new system-generated object-id.
  1027. // This will throw WrongPolicy if not SYSTEM_ID
  1028. // policy.
  1029. byte[] id = mediator.newSystemId();
  1030. try {
  1031. mediator.activateObject( id, servant ) ;
  1032. } catch (ObjectAlreadyActive oaa) {
  1033. // This exception can not occur in this case,
  1034. // since id is always brand new.
  1035. //
  1036. }
  1037. return id ;
  1038. } finally {
  1039. if (debug) {
  1040. ORBUtility.dprint( this,
  1041. "Exiting activate_object on poa " + this ) ;
  1042. }
  1043. unlock() ;
  1044. }
  1045. }
  1046. /**
  1047. * <code>activate_object_with_id</code>
  1048. * <b>Section 3.3.8.15</b>
  1049. */
  1050. public void activate_object_with_id(byte[] id,
  1051. Servant servant)
  1052. throws ObjectAlreadyActive, ServantAlreadyActive, WrongPolicy
  1053. {
  1054. try {
  1055. lock() ;
  1056. if (debug) {
  1057. ORBUtility.dprint( this,
  1058. "Calling activate_object_with_id on poa " + this +
  1059. " (servant=" + servant + " id=" + id + ")" ) ;
  1060. }
  1061. // Clone the id to avoid possible errors due to aliasing
  1062. // (e.g. the client passes the id in and then changes it later).
  1063. byte[] idClone = (byte[])(id.clone()) ;
  1064. mediator.activateObject( idClone, servant ) ;
  1065. } finally {
  1066. if (debug) {
  1067. ORBUtility.dprint( this,
  1068. "Exiting activate_object_with_id on poa " + this ) ;
  1069. }
  1070. unlock() ;
  1071. }
  1072. }
  1073. /**
  1074. * <code>deactivate_object</code>
  1075. * <b>3.3.8.16</b>
  1076. */
  1077. public void deactivate_object(byte[] id)
  1078. throws ObjectNotActive, WrongPolicy
  1079. {
  1080. try {
  1081. lock() ;
  1082. if (debug) {
  1083. ORBUtility.dprint( this,
  1084. "Calling deactivate_object on poa " + this +
  1085. " (id=" + id + ")" ) ;
  1086. }
  1087. mediator.deactivateObject( id ) ;
  1088. } finally {
  1089. if (debug) {
  1090. ORBUtility.dprint( this,
  1091. "Exiting deactivate_object on poa " + this ) ;
  1092. }
  1093. unlock() ;
  1094. }
  1095. }
  1096. /**
  1097. * <code>create_reference</code>
  1098. * <b>3.3.8.17</b>
  1099. */
  1100. public org.omg.CORBA.Object create_reference(String repId)
  1101. throws WrongPolicy
  1102. {
  1103. try {
  1104. lock() ;
  1105. if (debug) {
  1106. ORBUtility.dprint( this, "Calling create_reference(repId=" +
  1107. repId + ") on poa " + this ) ;
  1108. }
  1109. return makeObject( repId, mediator.newSystemId()) ;
  1110. } finally {
  1111. unlock() ;
  1112. }
  1113. }
  1114. /**
  1115. * <code>create_reference_with_id</code>
  1116. * <b>3.3.8.18</b>
  1117. */
  1118. public org.omg.CORBA.Object
  1119. create_reference_with_id(byte[] oid, String repId)
  1120. {
  1121. try {
  1122. lock() ;
  1123. if (debug) {
  1124. ORBUtility.dprint( this,
  1125. "Calling create_reference_with_id(oid=" +
  1126. oid + " repId=" + repId + ") on poa " + this ) ;
  1127. }
  1128. // Clone the id to avoid possible errors due to aliasing
  1129. // (e.g. the client passes the id in and then changes it later).
  1130. byte[] idClone = (byte[])(oid.clone()) ;
  1131. return makeObject( repId, idClone ) ;
  1132. } finally {
  1133. unlock() ;
  1134. }
  1135. }
  1136. /**
  1137. * <code>servant_to_id</code>
  1138. * <b>3.3.8.19</b>
  1139. */
  1140. public byte[] servant_to_id(Servant servant)
  1141. throws ServantNotActive, WrongPolicy
  1142. {
  1143. try {
  1144. lock() ;
  1145. if (debug) {
  1146. ORBUtility.dprint( this, "Calling servant_to_id(servant=" +
  1147. servant + ") on poa " + this ) ;
  1148. }
  1149. return mediator.servantToId( servant ) ;
  1150. } finally {
  1151. unlock() ;
  1152. }
  1153. }
  1154. /**
  1155. * <code>servant_to_reference</code>
  1156. * <b>3.3.8.20</b>
  1157. */
  1158. public org.omg.CORBA.Object servant_to_reference(Servant servant)
  1159. throws ServantNotActive, WrongPolicy
  1160. {
  1161. try {
  1162. lock() ;
  1163. if (debug) {
  1164. ORBUtility.dprint( this,
  1165. "Calling servant_to_reference(servant=" +
  1166. servant + ") on poa " + this ) ;
  1167. }
  1168. byte[] oid = mediator.servantToId(servant);
  1169. String repId = servant._all_interfaces( this, oid )[0] ;
  1170. return create_reference_with_id(oid, repId);
  1171. } finally {
  1172. unlock() ;
  1173. }
  1174. }
  1175. /**
  1176. * <code>reference_to_servant</code>
  1177. * <b>3.3.8.21</b>
  1178. */
  1179. public Servant reference_to_servant(org.omg.CORBA.Object reference)
  1180. throws ObjectNotActive, WrongPolicy, WrongAdapter
  1181. {
  1182. try {
  1183. lock() ;
  1184. if (debug) {
  1185. ORBUtility.dprint( this,
  1186. "Calling reference_to_servant(reference=" +
  1187. reference + ") on poa " + this ) ;
  1188. }
  1189. if ( state >= STATE_DESTROYING ) {
  1190. throw lifecycleWrapper().adapterDestroyed() ;
  1191. }
  1192. // reference_to_id should throw WrongAdapter
  1193. // if the objref was not created by this POA
  1194. byte [] id = internalReferenceToId(reference);
  1195. return mediator.idToServant( id ) ;
  1196. } finally {
  1197. unlock() ;
  1198. }
  1199. }
  1200. /**
  1201. * <code>reference_to_id</code>
  1202. * <b>3.3.8.22</b>
  1203. */
  1204. public byte[] reference_to_id(org.omg.CORBA.Object reference)
  1205. throws WrongAdapter, WrongPolicy
  1206. {
  1207. try {
  1208. lock() ;
  1209. if (debug) {
  1210. ORBUtility.dprint( this, "Calling reference_to_id(reference=" +
  1211. reference + ") on poa " + this ) ;
  1212. }
  1213. if( state >= STATE_DESTROYING ) {
  1214. throw lifecycleWrapper().adapterDestroyed() ;
  1215. }
  1216. return internalReferenceToId( reference ) ;
  1217. } finally {
  1218. unlock() ;
  1219. }
  1220. }
  1221. /**
  1222. * <code>id_to_servant</code>
  1223. * <b>3.3.8.23</b>
  1224. */
  1225. public Servant id_to_servant(byte[] id)
  1226. throws ObjectNotActive, WrongPolicy
  1227. {
  1228. try {
  1229. lock() ;
  1230. if (debug) {
  1231. ORBUtility.dprint( this, "Calling id_to_servant(id=" +
  1232. id + ") on poa " + this ) ;
  1233. }
  1234. if( state >= STATE_DESTROYING ) {
  1235. throw lifecycleWrapper().adapterDestroyed() ;
  1236. }
  1237. return mediator.idToServant( id ) ;
  1238. } finally {
  1239. unlock() ;
  1240. }
  1241. }
  1242. /**
  1243. * <code>id_to_reference</code>
  1244. * <b>3.3.8.24</b>
  1245. */
  1246. public org.omg.CORBA.Object id_to_reference(byte[] id)
  1247. throws ObjectNotActive, WrongPolicy
  1248. {
  1249. try {
  1250. lock() ;
  1251. if (debug) {
  1252. ORBUtility.dprint( this, "Calling id_to_reference(id=" +
  1253. id + ") on poa " + this ) ;
  1254. }
  1255. if( state >= STATE_DESTROYING ) {
  1256. throw lifecycleWrapper().adapterDestroyed() ;
  1257. }
  1258. Servant s = mediator.idToServant( id ) ;
  1259. String repId = s._all_interfaces( this, id )[0] ;
  1260. return makeObject(repId, id );
  1261. } finally {
  1262. unlock() ;
  1263. }
  1264. }
  1265. /**
  1266. * <code>id</code>
  1267. * <b>11.3.8.26 in ptc/00-08-06</b>
  1268. */
  1269. public byte[] id()
  1270. {
  1271. try {
  1272. lock() ;
  1273. return getAdapterId() ;
  1274. } finally {
  1275. unlock() ;
  1276. }
  1277. }
  1278. //***************************************************************
  1279. //Implementation of ObjectAdapter interface
  1280. //***************************************************************
  1281. public Policy getEffectivePolicy( int type )
  1282. {
  1283. return mediator.getPolicies().get_effective_policy( type ) ;
  1284. }
  1285. public int getManagerId()
  1286. {
  1287. return manager.getManagerId() ;
  1288. }
  1289. public short getState()
  1290. {
  1291. return manager.getORTState() ;
  1292. }
  1293. public String[] getInterfaces( java.lang.Object servant, byte[] objectId )
  1294. {
  1295. Servant serv = (Servant)servant ;
  1296. return serv._all_interfaces( this, objectId ) ;
  1297. }
  1298. protected ObjectCopierFactory getObjectCopierFactory()
  1299. {
  1300. int copierId = mediator.getPolicies().getCopierId() ;
  1301. CopierManager cm = getORB().getCopierManager() ;
  1302. return cm.getObjectCopierFactory( copierId ) ;
  1303. }
  1304. public void enter() throws OADestroyed
  1305. {
  1306. try {
  1307. lock() ;
  1308. if (debug) {
  1309. ORBUtility.dprint( this, "Calling enter on poa " + this ) ;
  1310. }
  1311. // Avoid deadlock if this is the thread that is processing the
  1312. // POA.destroy because this is the only thread that can notify
  1313. // waiters on beingDestroyedCV. This can happen if an
  1314. // etherealize upcall invokes a method on a colocated object
  1315. // served by this POA.
  1316. while ((state == STATE_DESTROYING) &&
  1317. (isDestroying.get() == Boolean.FALSE)) {
  1318. try {
  1319. beingDestroyedCV.await();
  1320. } catch (InterruptedException ex) {
  1321. // NO-OP
  1322. }
  1323. }
  1324. if (!waitUntilRunning())
  1325. throw new OADestroyed() ;
  1326. invocationCount++;
  1327. } finally {
  1328. if (debug) {
  1329. ORBUtility.dprint( this, "Exiting enter on poa " + this ) ;
  1330. }
  1331. unlock() ;
  1332. }
  1333. manager.enter();
  1334. }
  1335. public void exit()
  1336. {
  1337. try {
  1338. lock() ;
  1339. if (debug) {
  1340. ORBUtility.dprint( this, "Calling exit on poa " + this ) ;
  1341. }
  1342. invocationCount--;
  1343. if ((invocationCount == 0) && (state == STATE_DESTROYING)) {
  1344. invokeCV.broadcast();
  1345. }
  1346. } finally {
  1347. if (debug) {
  1348. ORBUtility.dprint( this, "Exiting exit on poa " + this ) ;
  1349. }
  1350. unlock() ;
  1351. }
  1352. manager.exit();
  1353. }
  1354. public void getInvocationServant( OAInvocationInfo info )
  1355. {
  1356. try {
  1357. lock() ;
  1358. if (debug) {
  1359. ORBUtility.dprint( this,
  1360. "Calling getInvocationServant on poa " + this ) ;
  1361. }
  1362. java.lang.Object servant = null ;
  1363. try {
  1364. servant = mediator.getInvocationServant( info.id(),
  1365. info.getOperation() );
  1366. } catch (ForwardRequest freq) {
  1367. throw new ForwardException( getORB(), freq.forward_reference ) ;
  1368. }
  1369. info.setServant( servant ) ;
  1370. } finally {
  1371. if (debug) {
  1372. ORBUtility.dprint( this,
  1373. "Exiting getInvocationServant on poa " + this ) ;
  1374. }
  1375. unlock() ;
  1376. }
  1377. }
  1378. public org.omg.CORBA.Object getLocalServant( byte[] objectId )
  1379. {
  1380. return null ;
  1381. }
  1382. /** Called from the subcontract to let this POA cleanup after an
  1383. * invocation. Note: If getServant was called, then returnServant
  1384. * MUST be called, even in the case of exceptions. This may be
  1385. * called multiple times for a single request.
  1386. */
  1387. public void returnServant()
  1388. {
  1389. try {
  1390. lock() ;
  1391. if (debug) {
  1392. ORBUtility.dprint( this,
  1393. "Calling returnServant on poa " + this ) ;
  1394. }
  1395. mediator.returnServant();
  1396. } catch (Throwable thr) {
  1397. if (debug) {
  1398. ORBUtility.dprint( this,
  1399. "Exception " + thr + " in returnServant on poa " + this ) ;
  1400. }
  1401. if (thr instanceof Error)
  1402. throw (Error)thr ;
  1403. else if (thr instanceof RuntimeException)
  1404. throw (RuntimeException)thr ;
  1405. } finally {
  1406. if (debug) {
  1407. ORBUtility.dprint( this,
  1408. "Exiting returnServant on poa " + this ) ;
  1409. }
  1410. unlock() ;
  1411. }
  1412. }
  1413. }