⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interceptorinvoker.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)InterceptorInvoker.java	1.33 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.corba.se.impl.interceptors;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.SystemException;import org.omg.CORBA.portable.Delegate;import org.omg.PortableInterceptor.LOCATION_FORWARD;import org.omg.PortableInterceptor.SUCCESSFUL;import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;import org.omg.PortableInterceptor.TRANSPORT_RETRY;import org.omg.PortableInterceptor.USER_EXCEPTION;import org.omg.PortableInterceptor.ClientRequestInfo;import org.omg.PortableInterceptor.ClientRequestInterceptor;import org.omg.PortableInterceptor.ForwardRequest;import org.omg.PortableInterceptor.IORInterceptor;import org.omg.PortableInterceptor.IORInterceptor_3_0;import org.omg.PortableInterceptor.ServerRequestInfo;import org.omg.PortableInterceptor.ServerRequestInterceptor;import org.omg.PortableInterceptor.ObjectReferenceTemplate;import com.sun.corba.se.spi.ior.IOR;import com.sun.corba.se.spi.oa.ObjectAdapter;import com.sun.corba.se.spi.orb.ORB;import com.sun.corba.se.impl.orbutil.ORBUtility;        /**  * Handles invocation of interceptors.  Has specific knowledge of how to * invoke IOR, ClientRequest, and ServerRequest interceptors.   * Makes use of the InterceptorList to retrieve the list of interceptors to  * be invoked.  Most methods in this class are package scope so that they * may only be called from the PIHandlerImpl. */public class InterceptorInvoker {    // The ORB    private ORB orb;        // The list of interceptors to be invoked    private InterceptorList interceptorList;    // True if interceptors are to be invoked, or false if not    // Note: This is a global enable/disable flag, whereas the enable flag    // in the RequestInfoStack in PIHandlerImpl is only for a particular Thread.    private boolean enabled = false;    // PICurrent variable.    private PICurrent current;    // NOTE: Be careful about adding additional attributes to this class.      // Multiple threads may be calling methods on this invoker at the same     // time.    /**     * Creates a new Interceptor Invoker.  Constructor is package scope so     * only the ORB can create it.  The invoker is initially disabled, and     * must be explicitly enabled using setEnabled().     */    InterceptorInvoker( ORB orb, InterceptorList interceptorList,                         PICurrent piCurrent )     {        this.orb = orb;	this.interceptorList = interceptorList;	this.enabled = false;        this.current = piCurrent;    }    /**     * Enables or disables the interceptor invoker     */    void setEnabled( boolean enabled ) {	this.enabled = enabled;    }        /*     **********************************************************************     * IOR Interceptor invocation     **********************************************************************/    /**     * Called when a new POA is created.     *     * @param oa The Object Adapter associated with the IOR interceptor.     */    void objectAdapterCreated( ObjectAdapter oa ) {	// If invocation is not yet enabled, don't do anything.	if( enabled ) {	    // Create IORInfo object to pass to IORInterceptors:	    IORInfoImpl info = new IORInfoImpl( oa );	    // Call each IORInterceptor:	    IORInterceptor[] iorInterceptors =                 (IORInterceptor[])interceptorList.getInterceptors(                 InterceptorList.INTERCEPTOR_TYPE_IOR );	    int size = iorInterceptors.length;	    // Implementation note:	    // This loop counts backwards for greater efficiency.	    // Benchmarks have shown that counting down is more efficient	    // than counting up in Java for loops, as a compare to zero is	    // faster than a subtract and compare to zero.  In this case,	    // it doesn't really matter much, but it's simply a force of habit.	    for( int i = (size - 1); i >= 0; i-- ) {		IORInterceptor interceptor = iorInterceptors[i];		try {		    interceptor.establish_components( info );	        }		catch( Exception e ) {		    // as per PI spec (orbos/99-12-02 sec 7.2.1), if		    // establish_components throws an exception, ignore it.		}	    }	    // Change the state so that only template operations are valid	    info.makeStateEstablished() ;	    for( int i = (size - 1); i >= 0; i-- ) {		IORInterceptor interceptor = iorInterceptors[i];		if (interceptor instanceof IORInterceptor_3_0) {		    IORInterceptor_3_0 interceptor30 = (IORInterceptor_3_0)interceptor ;		    // Note that exceptions here are NOT ignored, as per the		    // ORT spec (orbos/01-01-04)		    interceptor30.components_established( info );		}	    }	    // Change the state so that no operations are valid,	    // in case a reference to info escapes this scope.	    // This also completes the actions associated with the	    // template interceptors on this POA.	    info.makeStateDone() ;	}    }    void adapterManagerStateChanged( int managerId, short newState )    {	if (enabled) {	    IORInterceptor[] interceptors =                 (IORInterceptor[])interceptorList.getInterceptors(                 InterceptorList.INTERCEPTOR_TYPE_IOR );	    int size = interceptors.length;	    for( int i = (size - 1); i >= 0; i-- ) {		try {		    IORInterceptor interceptor = interceptors[i];		    if (interceptor instanceof IORInterceptor_3_0) {			IORInterceptor_3_0 interceptor30 = (IORInterceptor_3_0)interceptor ;			interceptor30.adapter_manager_state_changed( managerId, 			    newState );		    }		} catch (Exception exc) {		    // No-op: ignore exception in this case		}	    }	}    }    void adapterStateChanged( ObjectReferenceTemplate[] templates,	short newState )    {	if (enabled) {	    IORInterceptor[] interceptors =                 (IORInterceptor[])interceptorList.getInterceptors(                 InterceptorList.INTERCEPTOR_TYPE_IOR );	    int size = interceptors.length;	    for( int i = (size - 1); i >= 0; i-- ) {		try {		    IORInterceptor interceptor = interceptors[i];		    if (interceptor instanceof IORInterceptor_3_0) {			IORInterceptor_3_0 interceptor30 = (IORInterceptor_3_0)interceptor ;			interceptor30.adapter_state_changed( templates, newState );		    }		} catch (Exception exc) {		    // No-op: ignore exception in this case		}	    }	}    }    /*     **********************************************************************     * Client Interceptor invocation     **********************************************************************/    /**     * Invokes either send_request, or send_poll, depending on the value     * of info.getStartingPointCall()     */    void invokeClientInterceptorStartingPoint( ClientRequestInfoImpl info ) {	// If invocation is not yet enabled, don't do anything.	if( enabled ) {	    try {		// Make a a fresh slot table available to TSC in case		// interceptors need to make out calls.		// Client's TSC is now RSC via RequestInfo.		current.pushSlotTable( );		info.setPICurrentPushed( true );		info.setCurrentExecutionPoint( info.EXECUTION_POINT_STARTING );				// Get all ClientRequestInterceptors:		ClientRequestInterceptor[] clientInterceptors = 		    (ClientRequestInterceptor[])interceptorList.		    getInterceptors( InterceptorList.INTERCEPTOR_TYPE_CLIENT );		int size = clientInterceptors.length;		// We will assume that all interceptors returned successfully,		// and adjust the flowStackIndex to the appropriate value if		// we later discover otherwise.		int flowStackIndex = size;		boolean continueProcessing = true;			// Determine whether we are calling send_request or send_poll:		// (This is currently commented out because our ORB does not 		// yet support the Messaging specification, so send_poll will		// never occur.  Once we have implemented messaging, this may		// be uncommented.)		// int startingPointCall = info.getStartingPointCall();		for( int i = 0; continueProcessing && (i < size); i++ ) {		    try {			clientInterceptors[i].send_request( info );						// Again, it is not necessary for a switch here, since			// there is only one starting point call type (see			// above comment).						//switch( startingPointCall ) {			//case ClientRequestInfoImpl.CALL_SEND_REQUEST:			    //clientInterceptors[i].send_request( info );			    //break;			//case ClientRequestInfoImpl.CALL_SEND_POLL:			    //clientInterceptors[i].send_poll( info );			    //break;			//}		    }		    catch( ForwardRequest e ) {			// as per PI spec (orbos/99-12-02 sec 5.2.1.), if			// interception point throws a ForwardRequest, 			// no other Interceptors' send_request operations are 			// called.			flowStackIndex = i;			info.setForwardRequest( e );			info.setEndingPointCall( 			    ClientRequestInfoImpl.CALL_RECEIVE_OTHER );			info.setReplyStatus( LOCATION_FORWARD.value );						updateClientRequestDispatcherForward( info );						// For some reason, using break here causes the VM on 			// NT to lose track of the value of flowStackIndex 			// after exiting the for loop.  I changed this to 			// check a boolean value instead and it seems to work 			// fine.			continueProcessing = false;		    }		    catch( SystemException e ) {			// as per PI spec (orbos/99-12-02 sec 5.2.1.), if			// interception point throws a SystemException, 			// no other Interceptors' send_request operations are 			// called.			flowStackIndex = i;			info.setEndingPointCall( 			    ClientRequestInfoImpl.CALL_RECEIVE_EXCEPTION );			info.setReplyStatus( SYSTEM_EXCEPTION.value );			info.setException( e );			// For some reason, using break here causes the VM on 			// NT to lose track of the value of flowStackIndex 			// after exiting the for loop.  I changed this to 			// check a boolean value instead and it seems to 			// work fine.			continueProcessing = false;		    } 		}				// Remember where we left off in the flow stack:		info.setFlowStackIndex( flowStackIndex );	    }	    finally {		// Make the SlotTable fresh for the next interception point.		current.resetSlotTable( );	    }        } // end enabled check    }    /**     * Invokes either receive_reply, receive_exception, or receive_other,     * depending on the value of info.getEndingPointCall()     */    void invokeClientInterceptorEndingPoint( ClientRequestInfoImpl info ) {	// If invocation is not yet enabled, don't do anything.	if( enabled ) {	    try {		// NOTE: It is assumed someplace else prepared a		// fresh TSC slot table.		info.setCurrentExecutionPoint( info.EXECUTION_POINT_ENDING );				// Get all ClientRequestInterceptors:		ClientRequestInterceptor[] clientInterceptors = 		    (ClientRequestInterceptor[])interceptorList.		    getInterceptors( InterceptorList.INTERCEPTOR_TYPE_CLIENT );		int flowStackIndex = info.getFlowStackIndex();				// Determine whether we are calling receive_reply, 		// receive_exception, or receive_other:		int endingPointCall = info.getEndingPointCall();		// If we would be calling RECEIVE_REPLY, but this is a 		// one-way call, override this and call receive_other:		if( ( endingPointCall == 		      ClientRequestInfoImpl.CALL_RECEIVE_REPLY ) &&		    info.getIsOneWay() )		{		    endingPointCall = ClientRequestInfoImpl.CALL_RECEIVE_OTHER;		    info.setEndingPointCall( endingPointCall );

⌨️ 快捷键说明

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