📄 poaimpl.java
字号:
// Note that we do not synchronize on this, since this is // the PerformDestroy instance, not the POA. try { poa.lock() ; if (debug) { ORBUtility.dprint( this, "Calling performDestroy on poa " + poa ) ; } if (poa.state <= STATE_RUN) { poa.state = STATE_DESTROYING ; } else { // destroy may be called multiple times, and each call // is allowed to proceed with its own setting of the wait // flag, but the etherealize value is used from the first // call to destroy. Also all children should be destroyed // before the parent POA. If the poa is already destroyed, // we can just return. If the poa has started destruction, // but not completed, and wait is true, we need to wait // until destruction is complete, then just return. if (wait) while (poa.state != STATE_DESTROYED) { try { poa.beingDestroyedCV.await() ; } catch (InterruptedException exc) { // NO-OP } } return false ; } poa.isDestroying.set(Boolean.TRUE); // Make a copy since we can't hold the lock while destroying // the children, and an iterator is not deletion-safe. childPoas = (POAImpl[])poa.children.values().toArray( new POAImpl[0] ); } finally { poa.unlock() ; } // We are not holding the POA mutex here to avoid holding it // while destroying the POA's children, since this may involve // upcalls to etherealize methods. for (int ctr=0; ctr<childPoas.length; ctr++ ) { performDestroy( childPoas[ctr], destroyedPOATemplates ) ; } return true ; } public void performDestroy( POAImpl poa, Set destroyedPOATemplates ) { if (!prepareForDestruction( poa, destroyedPOATemplates )) return ; // NOTE: If we are here, poa is in STATE_DESTROYING state. All // other state checks are taken care of in prepareForDestruction. // No other threads may either be starting new invocations // by calling enter or starting to destroy poa. There may // still be pending invocations. POAImpl parent = poa.parent ; boolean isRoot = parent == null ; try { // Note that we must lock the parent before the child. // The parent lock is required (if poa is not the root) // to safely remove poa from parent's children Map. if (!isRoot) parent.lock() ; try { poa.lock() ; completeDestruction( poa, parent, destroyedPOATemplates ) ; } finally { poa.unlock() ; if (isRoot) // We have just destroyed the root POA, so we need to // make sure that the next call to // resolve_initial_reference( "RootPOA" ) // will recreate a valid root POA. poa.manager.getFactory().registerRootPOA() ; } } finally { if (!isRoot) { parent.unlock() ; poa.parent = null ; } } } private void completeDestruction( POAImpl poa, POAImpl parent, Set destroyedPOATemplates ) { if (debug) { ORBUtility.dprint( this, "Calling completeDestruction on poa " + poa ) ; } try { while (poa.invocationCount != 0) { try { poa.invokeCV.await() ; } catch (InterruptedException ex) { // NO-OP } } if (poa.mediator != null) { if (etherealize) poa.mediator.etherealizeAll(); poa.mediator.clearAOM() ; } if (poa.manager != null) poa.manager.removePOA(poa); if (parent != null) parent.children.remove( poa.name ) ; destroyedPOATemplates.add( poa.getAdapterTemplate() ) ; } catch (Throwable thr) { if (thr instanceof ThreadDeath) throw (ThreadDeath)thr ; poa.lifecycleWrapper().unexpectedException( thr, poa.toString() ) ; } finally { poa.state = STATE_DESTROYED ; poa.beingDestroyedCV.broadcast(); poa.isDestroying.set(Boolean.FALSE); if (debug) { ORBUtility.dprint( this, "Exiting completeDestruction on poa " + poa ) ; } } } } void etherealizeAll() { try { lock() ; if (debug) { ORBUtility.dprint( this, "Calling etheralizeAll on poa " + this ) ; } mediator.etherealizeAll() ; } finally { if (debug) { ORBUtility.dprint( this, "Exiting etheralizeAll on poa " + this ) ; } unlock() ; } } //******************************************************************* // Public POA API //******************************************************************* /** * <code>create_POA</code> * <b>Section 3.3.8.2</b> */ public POA create_POA(String name, POAManager theManager, Policy[] policies) throws AdapterAlreadyExists, InvalidPolicy { try { lock() ; if (debug) { ORBUtility.dprint( this, "Calling create_POA(name=" + name + " theManager=" + theManager + " policies=" + policies + ") on poa " + this ) ; } // We cannot create children of a POA that is (being) destroyed. // This has been added to the CORBA 3.0 spec. if (state > STATE_RUN) throw omgLifecycleWrapper().createPoaDestroy() ; POAImpl poa = (POAImpl)(children.get(name)) ; if (poa == null) { poa = new POAImpl( name, this, getORB(), STATE_START ) ; } try { poa.lock() ; if (debug) { ORBUtility.dprint( this, "Calling create_POA: new poa is " + poa ) ; } if ((poa.state != STATE_START) && (poa.state != STATE_INIT)) throw new AdapterAlreadyExists(); POAManagerImpl newManager = (POAManagerImpl)theManager ; if (newManager == null) newManager = new POAManagerImpl( manager.getFactory(), manager.getPIHandler() ); int defaultCopierId = getORB().getCopierManager().getDefaultId() ; Policies POAPolicies = new Policies( policies, defaultCopierId ) ; poa.initialize( newManager, POAPolicies ) ; return poa; } finally { poa.unlock() ; } } finally { unlock() ; } } /** * <code>find_POA</code> * <b>Section 3.3.8.3</b> */ public POA find_POA(String name, boolean activate) throws AdapterNonExistent { POAImpl found = null ; AdapterActivator act = null ; lock() ; if (debug) { ORBUtility.dprint( this, "Calling find_POA(name=" + name + " activate=" + activate + ") on poa " + this ) ; } found = (POAImpl) children.get(name); if (found != null) { if (debug) { ORBUtility.dprint( this, "Calling find_POA: found poa " + found ) ; } try { found.lock() ; // Do not hold the parent POA lock while // waiting for child to complete initialization. unlock() ; // Make sure that the child has completed its initialization, // if it was created by an AdapterActivator, otherwise throw // a standard TRANSIENT exception with minor code 4 (see // CORBA 3.0 11.3.9.3, in reference to unknown_adapter) if (!found.waitUntilRunning()) throw omgLifecycleWrapper().poaDestroyed() ; // Note that found may be in state DESTROYING or DESTROYED at // this point. That's OK, since destruction could start at // any time. } finally { found.unlock() ; } } else { try { if (debug) { ORBUtility.dprint( this, "Calling find_POA: no poa found" ) ; } if (activate && (activator != null)) { // Create a child, but don't initialize it. The newly // created POA will be in state STATE_START, which will // cause other calls to find_POA that are creating the same // POA to block on the waitUntilRunning call above. // Initialization must be completed by a call to create_POA // inside the unknown_adapter upcall. Note that // this.poaMutex must be held here so that this.children // can be safely updated. The state is set to STATE_INIT // so that initialize can make the correct state transition // when create_POA is called inside the AdapterActivator. // This avoids activating the new POA too soon // by transitioning to STATE_RUN after unknown_adapter // returns. found = new POAImpl( name, this, getORB(), STATE_INIT ) ; if (debug) { ORBUtility.dprint( this, "Calling find_POA: created poa " + found ) ; } act = activator ; } else { throw new AdapterNonExistent(); } } finally { unlock() ; } } // assert (found != null) // assert not holding this.poaMutex OR found.poaMutex // We must not hold either this.poaMutex or found.poaMutex here while // waiting for intialization of found to complete to prevent possible // deadlocks. if (act != null) { boolean status = false ; boolean adapterResult = false ; if (debug) { ORBUtility.dprint( this, "Calling find_POA: calling AdapterActivator" ) ; } try { // Prevent more than one thread at a time from executing in act // in case act is shared between multiple POAs. synchronized (act) { status = act.unknown_adapter(this, name); } } catch (SystemException exc) { throw omgLifecycleWrapper().adapterActivatorException( exc, name, poaId.toString() ) ; } catch (Throwable thr) { // ignore most non-system exceptions, but log them for // diagnostic purposes. lifecycleWrapper().unexpectedException( thr, this.toString() ) ; if (thr instanceof ThreadDeath) throw (ThreadDeath)thr ; } finally { // At this point, we have completed adapter activation. // Whether this was successful or not, we must call // destroyIfNotInitDone so that calls to enter() and create_POA() // that are waiting can execute again. Failing to do this // will cause the system to hang in complex tests. adapterResult = found.destroyIfNotInitDone() ; } if (status) { if (!adapterResult) throw omgLifecycleWrapper().adapterActivatorException( name, poaId.toString() ) ; } else { if (debug) { ORBUtility.dprint( this, "Calling find_POA: AdapterActivator returned false" ) ; } // OMG Issue 3740 is resolved to throw AdapterNonExistent if // unknown_adapter() returns false. throw new AdapterNonExistent(); } } return found; } /** * <code>destroy</code> * <b>Section 3.3.8.4</b> */ public void destroy(boolean etherealize, boolean wait_for_completion) { // This is to avoid deadlock if (wait_for_completion && getORB().isDuringDispatch()) { throw lifecycleWrapper().destroyDeadlock() ; } DestroyThread destroyer = new DestroyThread( etherealize, debug ); destroyer.doIt( this, wait_for_completion ) ; } /** * <code>create_thread_policy</code> * <b>Section 3.3.8.5</b> */ public ThreadPolicy create_thread_policy( ThreadPolicyValue value) { return new ThreadPolicyImpl(value); } /** * <code>create_lifespan_policy</code> * <b>Section 3.3.8.5</b> */ public LifespanPolicy create_lifespan_policy( LifespanPolicyValue value) { return new LifespanPolicyImpl(value); } /** * <code>create_id_uniqueness_policy</code> * <b>Section 3.3.8.5</b> */ public IdUniquenessPolicy create_id_uniqueness_policy( IdUniquenessPolicyValue value) { return new IdUniquenessPolicyImpl(value); } /** * <code>create_id_assignment_policy</code> * <b>Section 3.3.8.5</b> */ public IdAssignmentPolicy create_id_assignment_policy( IdAssignmentPolicyValue value) { return new IdAssignmentPolicyImpl(value); } /** * <code>create_implicit_activation_policy</code> * <b>Section 3.3.8.5</b> */ public ImplicitActivationPolicy create_implicit_activation_policy( ImplicitActivationPolicyValue value) { return new ImplicitActivationPolicyImpl(value); } /** * <code>create_servant_retention_policy</code> * <b>Section 3.3.8.5</b> */ public ServantRetentionPolicy create_servant_retention_policy( ServantRetentionPolicyValue value) { return new ServantRetentionPolicyImpl(value); } /** * <code>create_request_processing_policy</code> * <b>Section 3.3.8.5</b> */ public RequestProcessingPolicy create_request_processing_policy( RequestProcessingPolicyValue value) { return new RequestProcessingPolicyImpl(value); } /** * <code>the_name</code> * <b>Section 3.3.8.6</b> */ public String the_name() { try { lock() ; return name; } finally { unlock() ; } } /** * <code>the_parent</code> * <b>Section 3.3.8.7</b> */ public POA the_parent() { try { lock() ; return parent; } finally { unlock() ; } } /** * <code>the_children</code> */ public org.omg.PortableServer.POA[] the_children() { try { lock() ; Collection coll = children.values() ; int size = coll.size() ; POA[] result = new POA[ size ] ; int index = 0 ; Iterator iter = coll.iterator() ; while (iter.hasNext()) { POA poa = (POA)(iter.next()) ; result[ index++ ] = poa ; } return result ; } finally { unlock() ; } } /** * <code>the_POAManager</code> * <b>Section 3.3.8.8</b> */ public POAManager the_POAManager() { try { lock() ; return manager; } finally { unlock() ; } } /** * <code>the_activator</code> * <b>Section 3.3.8.9</b> */ public AdapterActivator the_activator() { try { lock() ; return activator; } finally { unlock() ; } } /** * <code>the_activator</code> * <b>Section 3.3.8.9</b> */ public void the_activator(AdapterActivator activator) { try { lock() ; if (debug) { ORBUtility.dprint( this, "Calling the_activator on poa " + this + " activator=" + activator ) ; } this.activator = activator; } finally {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -