piorb.java

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

JAVA
1,284
字号
     * so that we may remember the commandline arguments passed to the     * application instantiating this ORB.  This is later available by a call     * to ORBInitInfo.arguments() for ORBInitializers.     *     * @param params command-line arguments for the application's main method.     *     may be <code>null</code>.     * "-param-name" and "param-value" strings.     * @param props the application properties     */    protected void set_parameters (String[] params, Properties props) {	this.arguments = params;	super.set_parameters( params, props );    }     /**     * Set ORB internal variables using the properties specified.     * Called from super.set_parameters() for both applications and applets.     */    protected void parseProperties( Properties props ) {	super.parseProperties( props );	// Read in PI orb initializers and instantiate them:	registerORBInitializers( props );    }    /**     * Register and instantiate ORB initializers, as per PI spec,      * ptc/00-08-06, section 21.7.3.1     */    private void registerORBInitializers( Properties props ) {	// Find all property names that begin with the orb init prefix	// and add to the orb initializers list.	String orbInitPrefix = ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX;	Enumeration propertyNames = props.propertyNames();	ArrayList initializerList = new ArrayList();	while( propertyNames.hasMoreElements() ) {	    String propertyName = (String)propertyNames.nextElement();	    if( propertyName.startsWith( orbInitPrefix ) ) {		// Extract orb initializer name from property:		String initClassName = propertyName.substring( 		    orbInitPrefix.length() );		try {                    Class initClass = ORBClassLoader.loadClass( initClassName );		    // For security reasons avoid creating an instance 		    // if this class is one that would fail the class cast 		    // to ORBInitializer anyway.		    if( ORBInitializer.class.isAssignableFrom( initClass ) ) {			// Now that we have a class object, instantiate one and			// remember it:			if( initClass != null ) {			    ORBInitializer initializer = 				(ORBInitializer)initClass.newInstance();			    initializerList.add( initializer );			}		    }		}		catch( Exception e ) {		    // As per ptc/00-08-06, section 21.7.3.1., "If there		    // are any exceptions the ORB shall ignore them and		    // proceed."		}	    } // end if this property starts with prefix	} // end while there are more properties	if( initializerList.size() > 0 ) {	    orbInitializers = (ORBInitializer[])initializerList.toArray( 		new ORBInitializer[0] );	}	else {	    orbInitializers = null;	}    }    /*     **************************************************************************     *  The following methods are the implementations for the Portable     *  Interceptors hooks found in POAORB and corba.ORB.       *     *  They are made final for security purposes - someone could otherwise      *  derive from PIORB and get sensitive information and intercept     *  the interceptors themselves.  This way, there is     *  no convenient way to get sensitive information and have PI      *  functionality at the same time (though they could inherit from POAORB     *  and get sensitive information, they would have to re-implement      *  Portable Interceptors to get sensitive information and still have     *  PI functionality).     *************************************************************************/    /**     * Overridden from POAORB.     * Called when a new POA is created.     *     * @param poaImpl The POAImpl associated with these IOR Interceptor.     */    final protected void invokeIORInterceptors( POAImpl poaImpl ) {	if( !hasIORInterceptors ) return;	// Forward request to interceptor invoker:	interceptorInvoker.invokeIORInterceptors( poaImpl );    }        /*     *****************     * Client PI hooks     *****************/    /**     * Overridden from corba.ORB.     * Called for pseudo-ops to temporarily disable portable interceptor     * hooks for calls on this thread.  Keeps track of the number of     * times this is called and increments the disabledCount.     */    final protected void disableInterceptorsThisThread() {	if( !hasClientInterceptors ) return;        RequestInfoStack infoStack =             (RequestInfoStack)threadLocalClientRequestInfoStack.get();        infoStack.disableCount++;    }        /**     * Overridden from corba.ORB.     * Called for pseudo-ops to re-enable portable interceptor     * hooks for calls on this thread.  Decrements the disabledCount.     * If disabledCount is 0, interceptors are re-enabled.     */    final protected void enableInterceptorsThisThread() {	if( !hasClientInterceptors ) return;        RequestInfoStack infoStack =             (RequestInfoStack)threadLocalClientRequestInfoStack.get();        infoStack.disableCount--;    }        /**     * Overridden from corba.ORB.     * Called when the send_request or send_poll portable interception point      * is to be invoked for all appropriate client-side request interceptors.     * Happens on any orb-mediated call.     *     * @exception RemarhsalException - Thrown when this request needs to     *     be retried.     */    final protected void invokeClientPIStartingPoint()         throws RemarshalException    {	if( !hasClientInterceptors ) return;        if( !isClientPIEnabledForThisThread() ) return;        // Invoke the starting interception points and record exception        // and reply status info in the info object:        ClientRequestInfoImpl info = peekClientRequestInfoImplStack();        interceptorInvoker.invokeClientInterceptorStartingPoint( info );                // Check reply status.  If we will not have another chance later        // to invoke the client ending points, do it now.        short replyStatus = info.getReplyStatus();        if( (replyStatus == SYSTEM_EXCEPTION.value) ||            (replyStatus == LOCATION_FORWARD.value) )        {	    // Note: Transport retry cannot happen here since this happens	    // before the request hits the wire.            Exception exception = invokeClientPIEndingPoint(                 convertPIReplyStatusToReplyMessage( replyStatus ),                info.getException() );            if( exception == null ) {                // Do not throw anything.  Otherwise, it must be a                // SystemException, UserException or RemarshalException.            }            if( exception instanceof SystemException ) {                throw (SystemException)exception;            }            else if( exception instanceof RemarshalException ) {                throw (RemarshalException)exception;            }            else if( (exception instanceof UserException) ||		     (exception instanceof ApplicationException) ) 	    {                // It should not be possible for an interceptor to throw 		// a UserException.  By asserting instead of throwing the		// UserException, we need not declare anything but 		// RemarshalException in the throws clause.		throw new INTERNAL( 		    "Assertion failed: Interceptor set exception to " +		    "UserException or ApplicationException.", 		    MinorCodes.EXCEPTION_INVALID, 		    CompletionStatus.COMPLETED_NO );            }        }	else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {	    throw new INTERNAL( 		"Assertion failed: Reply status is initialized but not " +		"SYSTEM_EXCEPTION, or LOCATION_FORWARD_*.", 		MinorCodes.REPLY_STATUS_NOTINIT, 		CompletionStatus.COMPLETED_NO );	}    }        /**     * Overridden from corba.ORB.     * Called when the appropriate client ending interception point is     * to be invoked for all apporpriate client-side request interceptors.     *     * @param replyStatus One of the constants in iiop.messages.ReplyMessage     *     indicating which reply status to set.     * @param exception The exception before ending interception points have     *     been invoked, or null if no exception at the moment.     * @return The exception to be thrown, after having gone through     *     all ending points, or null if there is no exception to be     *     thrown.  Note that this exception can be either the same or     *     different from the exception set using setClientPIException.     *     There are four possible return types: null (no exception),      *     SystemException, UserException, or RemarshalException.     */    final protected Exception invokeClientPIEndingPoint(        int replyStatus, Exception exception )    {	if( !hasClientInterceptors ) return exception;        if( !isClientPIEnabledForThisThread() ) return exception;        // Translate ReplyMessage.replyStatus into PI replyStatus:	// Note: this is also an assertion to make sure a valid replyStatus	// is passed in (IndexOutOfBoundsException will be thrown otherwise)        short piReplyStatus = REPLY_MESSAGE_TO_PI_REPLY_STATUS[replyStatus];                // Invoke the ending interception points and record exception        // and reply status info in the info object:        ClientRequestInfoImpl info = peekClientRequestInfoImplStack();        info.setReplyStatus( piReplyStatus );        info.setException( exception );        interceptorInvoker.invokeClientInterceptorEndingPoint( info );	piReplyStatus = info.getReplyStatus();        // Check reply status:        if( (piReplyStatus == LOCATION_FORWARD.value) ||            (piReplyStatus == TRANSPORT_RETRY.value) )         {            // If this is a forward or a retry, reset and reuse             // info object:            info.reset();            info.setRetryRequest( true );            // ... and return a RemarshalException so the orb internals know            exception = new RemarshalException();        }        else if( (piReplyStatus == SYSTEM_EXCEPTION.value) ||                 (piReplyStatus == USER_EXCEPTION.value) ) 	{            exception = info.getException();        }                return exception;    }        /**     * Overridden from corba.ORB.     * <p>     * Invoked when a request is about to be created.  Must be called before     * any of the setClientPI* methods so that a new info object can be     * prepared for information collection.     * <p>     * Happens on any orb-mediated call.  Note that this method may be     * called multiple times if a request is retried.     * <p>     * This call is essentially required so we can maintain the same info     * object across invocations.  This is not required by the current spec,     * but we will eventually need this functionality for things like     * invocation ids.     * <p>     * On a DII request, initiate is called twice (once in doInvocation so     * we can set the RequestImpl object, and once in      * ClientDelegate.createRequest.  In this case, we must ignore the second     * initiate call.     */    final protected void initiateClientPIRequest( boolean diiRequest ) {	if( !hasClientInterceptors ) return;        if( !isClientPIEnabledForThisThread() ) return;	// Get the most recent info object from the thread local 	// ClientRequestInfoImpl stack:	RequestInfoStack infoStack = 	    (RequestInfoStack)threadLocalClientRequestInfoStack.get();	ClientRequestInfoImpl info = null;	if( !infoStack.empty() ) info = 	    (ClientRequestInfoImpl)infoStack.peek();	if( !diiRequest && (info != null) && info.isDIIInitiate() ) {	    // In RequestImpl.doInvocation we already called 	    // initiateClientPIRequest( true ), so ignore this initiate.	    info.setDIIInitiate( false );	}	else {	    // If there is no info object or if we are not retrying a request,	    // push a new ClientRequestInfoImpl on the stack:	    if( (info == null) || !info.getRetryRequest() ) {		info = new ClientRequestInfoImpl( this );		infoStack.push( info );		// Note: the entry count is automatically initialized to 0.	    }	    	    // Reset the retry request flag so that recursive calls will	    // push a new info object, and bump up entry count so we know	    // when to pop this info object:	    info.setRetryRequest( false );	    info.incrementEntryCount();	    // If this is a DII request, make sure we ignore the next initiate.	    if( diiRequest ) {		info.setDIIInitiate( true );	    }	}    }        /**     * Overridden from corba.ORB.     * Invoked when a request is about to be cleaned up.  Must be called     * after ending points are called so that the info object on the stack     * can be deinitialized and popped from the stack at the appropriate

⌨️ 快捷键说明

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