poaimpl.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,329 行 · 第 1/3 页

JAVA
1,329
字号
	    {		if (servantManager == null)		    objAdapter(MinorCodes.POA_NO_SERVANT_MANAGER,			       CompletionStatus.COMPLETED_NO);	    		if (! (servantManager instanceof ServantLocator) )		    objAdapter(MinorCodes.POA_BAD_SERVANT_MANAGER,			       CompletionStatus.COMPLETED_NO);		ServantLocator locator = (ServantLocator) servantManager;                // Try - finally is J2EE requirement.                Servant servant;                try{                    servant = locator.preinvoke(id, this, operation,                                                 cookieHolder);                    if (servant == null) {			if (! isSpecial) {			    objectNotExist(MinorCodes.NULL_SERVANT,					   CompletionStatus.COMPLETED_NO);			} else {			    return null;			}                    }                } finally {                    orb.getCurrent().setPreInvokeCalled();                }		setDelegate(servant, id);		// Note: locator.postinvoke is called in internalReturnServant		return servant;	    }	else if (!policies.retainServants() && policies.useDefaultServant())	    {		if (defaultServant != null)		    return defaultServant;		else		    objAdapter(MinorCodes.POA_NO_DEFAULT_SERVANT,			       CompletionStatus.COMPLETED_NO);	    }	else	    throw new INTERNAL(MinorCodes.POA_INTERNAL_GET_SERVANT_ERROR,			       CompletionStatus.COMPLETED_NO);	return null; // to keep javac happy    }    void etherealizeAll() {	if (policies.retainServants() && policies.useServantManager()	    && servantManager != null)  {	    Enumeration keys = activeObjectMap.keys();	    while ( keys.hasMoreElements() ) {		byte[] id = (byte[])keys.nextElement();		Servant servant = activeObjectMap.get(id);		boolean remaining_activations;		if (activeObjectMap.hasMultipleIDs(servant))		    remaining_activations = true;		else		    remaining_activations = false;		synchronized (servantManager) {		    ((ServantActivator)		     servantManager).etherealize(id, this,						 servant,						 true,						 remaining_activations);		}	    }	}    }        /**     * <code>create_POA</code>     * <b>Section 3.3.8.2</b>     */    public synchronized POA create_POA(String name,				       POAManager manager,				       Policy[] policies)	throws AdapterAlreadyExists, InvalidPolicy {	return create_POA(name, (POAManagerImpl) manager,			  new Policies(policies));          }    /**     * <code>find_POA</code>     * <b>Section 3.3.8.3</b>     */    public synchronized POA find_POA(String name, boolean activate)	throws AdapterNonExistent     {	POA found = (POA) children.get(name);	if (found != null)	    return found;	else if (activate) {	    if (activator == null)		adapterNonExistent();	    else {		boolean status;		try {		    // this song and dance of creating a CV and then		    // notifying it is necessary to ensure that		    // invocations on the created child POA are queued		    // until unknown_adapter returns (see POAImpl.enter)		    adapterActivatorCV = new java.lang.Object();		    status = activator.unknown_adapter(this, name);		    synchronized (adapterActivatorCV) {			adapterActivatorCV.notifyAll();			adapterActivatorCV = null;		    }		} catch (SystemException ex) {		    if (orb.poaDebugFlag)			ORBUtility.dprint( this, 			    "System exception in unknown_adapter call", 			    ex ) ;		    objAdapter(MinorCodes.ADAPTER_ACTIVATOR_EXCEPTION,			       CompletionStatus.COMPLETED_NO);		    return null;		}		if (status == false) {                    // OMG Issue 3740 is resolved to throw AdapterNonExistent if                    // unknown_adapter() returns false.	            adapterNonExistent();                }		return (POA) children.get(name);	    }	}	adapterNonExistent();	return null;		// to keep javac quiet    }    /**     * <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 && orb.isProcessingInvocation()) {            throw new BAD_INV_ORDER(                "Request to destroy POA with waiting for completion while servicing a request",                0,                CompletionStatus.COMPLETED_NO);        }        destroyInternal(etherealize, wait_for_completion);    }    // Split destroy into destroy and destroyInternal.    // This guarantees to have at most one DestroyThread started    // if wait_for_completion == false. The recursive call to destroyInternal    // uses "true" for all children which avoids starting new DestroyThreads.    //    void destroyInternal(boolean etherealize, boolean wait_for_completion) {        // According to spec, the destroy may be called multiple time, and        // it is allowed to proceed with it's 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.        synchronized (this) {            if (!destroyed) {                destroyed = true;            }            if (beingDestroyedCV == null) {                beingDestroyedCV = new java.lang.Object();            }            if (!etherealizeFlag) {                etherealizeValue = etherealize;                etherealizeFlag = true;            }        }        // Converted from anonymous class to local class        // so that we can call performDestroy() directly.        class DestroyThread extends Thread {	    private POAImpl poa ;	    public DestroyThread( POAImpl poa )	    {		this.poa = poa ;	    }            public void run() {                performDestroy();            }            public void performDestroy() {                poa.isDestroying.set(Boolean.TRUE);		// Make sure that we have a copy of the children, notoy		// an Iterator, otherwise ConcurrentModificationException can		// occur.		java.lang.Object[] childPoas = null ;		synchronized (poa) {		    childPoas = poa.children.values().toArray() ;		}		for (int ctr=0; ctr<childPoas.length; ctr++) {		    POAImpl cpoa = (POAImpl)(childPoas[ctr]) ;                    // use wait_for_completion == true on the recursive destroy call so that                    // only a single DestroyThread is actually started.		    cpoa.destroyInternal( etherealizeValue, true ) ;		}                if (etherealizeValue)                    poa.etherealizeAll();                // this check is required, because activeObjectMap would                // be null for nonRetain  Policy                if (activeObjectMap != null) {                    poa.activeObjectMap.clear();                    poa.activeObjectMap = null;                }            }        };        DestroyThread destroyer = new DestroyThread( this );        if (wait_for_completion) {            // No need to start a new thread if we wait anyway.            // In this case the current thread does the work.            destroyer.performDestroy();        } else {            // Catch exceptions since setDaemon can cause a            // security exception to be thrown under netscape            // in the Applet mode            try { destroyer.setDaemon(true); } catch (Exception e) {}            // start a new thread            destroyer.start();        }	if (wait_for_completion) {	    while (nInvocations != 0) {	        try {		    synchronized (invokeCV) {                        invokeCV.wait();		    }	        } catch (InterruptedException ex) { } 	    }	}        manager.removePOA(this);			if (parent != null) {            parent.removeChild(name);	}	synchronized (beingDestroyedCV) {	    beingDestroyedCV.notifyAll();	    beingDestroyedCV = null;            isDestroying.set(Boolean.FALSE);	}    }    // XXX: Do the policy factory methods need to be synchronized?    /**     * <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);    }        /****** not needed for now	    public TransactionPolicy	    create_transaction_policy(TransactionPolicyValue	    value) {	    return new TransactionPolicyImpl(value);	    }    ********/    /**     * <code>the_name</code>     * <b>Section 3.3.8.6</b>     */    public String the_name() {	return name;    }    /**     * <code>the_parent</code>     * <b>Section 3.3.8.7</b>     */    public POA the_parent()     {	return parent;    }    public POAView getParent()     {	return parent;    }    public int getNumLevels()     {	return numLevels ;    }    /**     * <code>the_children</code>     */    synchronized public org.omg.PortableServer.POA[] the_children() {	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 ;    }    /**     * <code>the_POAManager</code>     * <b>Section 3.3.8.8</b>     */    public POAManager the_POAManager() {	return manager;    }    /**     * <code>the_activator</code>     * <b>Section 3.3.8.9</b>     */    public AdapterActivator the_activator() {	return activator;    }        /**     * <code>the_activator</code>     * <b>Section 3.3.8.9</b>     */    public void the_activator(AdapterActivator			      activator) {	this.activator = activator;    }    /**     * <code>get_servant_manager</code>     * <b>Section 3.3.8.10</b>     */    public ServantManager get_servant_manager()	throws WrongPolicy {	if (!policies.useServantManager())	    wrongPolicy();	return servantManager;    }    // XXX: Need to sort this out w.r.t ServantActivator and    //      ServantLocator.        /**     * <code>set_servant_manager</code>     * <b>Section 3.3.8.10</b>     */    public synchronized void set_servant_manager(ServantManager servantManager)	throws WrongPolicy {        if ( this.servantManager != null ) {            throw new BAD_INV_ORDER( MinorCodes.SERVANT_MANAGER_ALREADY_SET,                                     CompletionStatus.COMPLETED_NO );        }	if (!policies.useServantManager()) {	    wrongPolicy();        }	this.servantManager = servantManager;    }	    /**     * <code>get_servant</code>     * <b>Section 3.3.8.12</b>     */    public Servant get_servant()	throws NoServant, WrongPolicy {	if (!policies.useDefaultServant())	    wrongPolicy();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?