interceptorinvoker.java
来自「java jdk 1.4的源码」· Java 代码 · 共 610 行 · 第 1/2 页
JAVA
610 行
/* * @(#)InterceptorInvoker.java 1.29 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.corba.se.internal.Interceptors;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.ServerRequestInfo;import org.omg.PortableInterceptor.ServerRequestInterceptor;import com.sun.corba.se.internal.corba.ClientDelegate;import com.sun.corba.se.internal.core.ClientSubcontract;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.POA.POAImpl;import com.sun.corba.se.internal.ior.IORTemplate; import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.ORB ;import org.omg.CORBA.SystemException;import org.omg.CORBA.portable.Delegate;import org.omg.CORBA.portable.ObjectImpl; /** * 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 PIORB. */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 PIORB 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 poaImpl The POA associated with the IOR interceptor. */ void invokeIORInterceptors( POAImpl poaImpl ) { // If invocation is not yet enabled, don't do anything. if( enabled ) { // Create IORInfo object to pass to IORInterceptors: IORInfoImpl info = new IORInfoImpl( orb, poaImpl ); // 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. } } } } /* ********************************************************************** * 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 ); updateClientDelegateForwardRequest( 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 ); } // Only step through the interceptors whose starting points // have successfully returned. // Unlike the previous loop, this one counts backwards for a // reason - we must execute these in the reverse order of the // starting points. for( int i = (flowStackIndex - 1); i >= 0; i-- ) { try { switch( endingPointCall ) { case ClientRequestInfoImpl.CALL_RECEIVE_REPLY: clientInterceptors[i].receive_reply( info ); break; case ClientRequestInfoImpl.CALL_RECEIVE_EXCEPTION: clientInterceptors[i].receive_exception( info ); break; case ClientRequestInfoImpl.CALL_RECEIVE_OTHER: clientInterceptors[i].receive_other( info ); break; } } catch( ForwardRequest e ) { // as per PI spec (orbos/99-12-02 sec 5.2.1.), if // interception point throws a ForwardException, // ending point call changes to receive_other. endingPointCall = ClientRequestInfoImpl.CALL_RECEIVE_OTHER; info.setEndingPointCall( endingPointCall ); info.setReplyStatus( LOCATION_FORWARD.value ); info.setForwardRequest( e ); updateClientDelegateForwardRequest( info ); } catch( SystemException e ) { // as per PI spec (orbos/99-12-02 sec 5.2.1.), if // interception point throws a SystemException, // ending point call changes to receive_exception. endingPointCall = ClientRequestInfoImpl.CALL_RECEIVE_EXCEPTION; info.setEndingPointCall( endingPointCall ); info.setReplyStatus( SYSTEM_EXCEPTION.value ); info.setException( e );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?