📄 pihandlerimpl.java
字号:
/* * @(#)PIHandlerImpl.java 1.36 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 java.util.*;import java.io.IOException; import org.omg.CORBA.Any;import org.omg.CORBA.BAD_PARAM;import org.omg.CORBA.BAD_POLICY;import org.omg.CORBA.BAD_INV_ORDER;import org.omg.CORBA.COMM_FAILURE;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.NVList;import org.omg.CORBA.OBJECT_NOT_EXIST;import org.omg.CORBA.ORBPackage.InvalidName;import org.omg.CORBA.SystemException;import org.omg.CORBA.UserException;import org.omg.CORBA.UNKNOWN;import org.omg.CORBA.portable.ApplicationException;import org.omg.CORBA.portable.RemarshalException;import org.omg.IOP.CodecFactory;import org.omg.PortableInterceptor.ForwardRequest;import org.omg.PortableInterceptor.Current;import org.omg.PortableInterceptor.Interceptor;import org.omg.PortableInterceptor.LOCATION_FORWARD;import org.omg.PortableInterceptor.ORBInitializer;import org.omg.PortableInterceptor.ORBInitInfo;import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;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.PolicyFactory;import org.omg.PortableInterceptor.ObjectReferenceTemplate ;import com.sun.corba.se.pept.encoding.OutputObject;import com.sun.corba.se.spi.ior.IOR;import com.sun.corba.se.spi.ior.ObjectKeyTemplate;import com.sun.corba.se.spi.oa.ObjectAdapter;import com.sun.corba.se.spi.orb.ORB;import com.sun.corba.se.spi.orbutil.closure.ClosureFactory;import com.sun.corba.se.spi.protocol.CorbaMessageMediator;import com.sun.corba.se.spi.protocol.ForwardException;import com.sun.corba.se.spi.protocol.PIHandler;import com.sun.corba.se.spi.logging.CORBALogDomains;import com.sun.corba.se.impl.logging.InterceptorsSystemException;import com.sun.corba.se.impl.logging.ORBUtilSystemException;import com.sun.corba.se.impl.logging.OMGSystemException;import com.sun.corba.se.impl.corba.RequestImpl;import com.sun.corba.se.impl.orbutil.ORBClassLoader;import com.sun.corba.se.impl.orbutil.ORBConstants;import com.sun.corba.se.impl.orbutil.ORBUtility;import com.sun.corba.se.impl.orbutil.StackImpl;import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;/** * Provides portable interceptor functionality. */public class PIHandlerImpl implements PIHandler { // REVISIT - delete these after framework merging. boolean printPushPopEnabled = false; int pushLevel = 0; private void printPush() { if (! printPushPopEnabled) return; printSpaces(pushLevel); pushLevel++; System.out.println("PUSH"); } private void printPop() { if (! printPushPopEnabled) return; pushLevel--; printSpaces(pushLevel); System.out.println("POP"); } private void printSpaces(int n) { for (int i = 0; i < n; i++) { System.out.print(" "); } } private ORB orb ; InterceptorsSystemException wrapper ; ORBUtilSystemException orbutilWrapper ; OMGSystemException omgWrapper ; // A unique id used in ServerRequestInfo. // This does not correspond to the GIOP request id. private int serverRequestIdCounter = 0; // Stores the codec factory for producing codecs CodecFactory codecFactory = null; // The arguments passed to the application's main method. May be null. // This is used for ORBInitializers and set from set_parameters. String[] arguments = null; // The list of portable interceptors, organized by type: private InterceptorList interceptorList; // Cached information for optimization - do we have any interceptors // registered of the given types? Set during ORB initialization. private boolean hasIORInterceptors; private boolean hasClientInterceptors; // temp always true private boolean hasServerInterceptors; // The class responsible for invoking interceptors private InterceptorInvoker interceptorInvoker; // There will be one PICurrent instantiated for every ORB. private PICurrent current; // This table contains a list of PolicyFactories registered using // ORBInitInfo.registerPolicyFactory() method. // Key for the table is PolicyType which is an Integer // Value is PolicyFactory. private HashMap policyFactoryTable; // Table to convert from a ReplyMessage.? to a PI replyStatus short. // Note that this table relies on the order and constants of // ReplyMessage not to change. private final static short REPLY_MESSAGE_TO_PI_REPLY_STATUS[] = { SUCCESSFUL.value, // = ReplyMessage.NO_EXCEPTION USER_EXCEPTION.value, // = ReplyMessage.USER_EXCEPTION SYSTEM_EXCEPTION.value, // = ReplyMessage.SYSTEM_EXCEPTION LOCATION_FORWARD.value, // = ReplyMessage.LOCATION_FORWARD LOCATION_FORWARD.value, // = ReplyMessage.LOCATION_FORWARD_PERM TRANSPORT_RETRY.value // = ReplyMessage.NEEDS_ADDRESSING_MODE }; // ThreadLocal containing a stack to store client request info objects // and a disable count. private ThreadLocal threadLocalClientRequestInfoStack = new ThreadLocal() { protected Object initialValue() { return new RequestInfoStack(); } }; // ThreadLocal containing the current server request info object. private ThreadLocal threadLocalServerRequestInfoStack = new ThreadLocal() { protected Object initialValue() { return new RequestInfoStack(); } }; // Class to contain all ThreadLocal data for ClientRequestInfo // maintenance. // // We use an ArrayList instead since it is not thread-safe. // RequestInfoStack is used quite frequently. private final class RequestInfoStack extends Stack { // Number of times a request has been made to disable interceptors. // When this reaches 0, interception hooks are disabled. Any higher // value indicates they are enabled. // NOTE: The is only currently used on the client side. public int disableCount = 0; } public PIHandlerImpl( ORB orb, String[] args ) { this.orb = orb ; wrapper = InterceptorsSystemException.get( orb, CORBALogDomains.RPC_PROTOCOL ) ; orbutilWrapper = ORBUtilSystemException.get( orb, CORBALogDomains.RPC_PROTOCOL ) ; omgWrapper = OMGSystemException.get( orb, CORBALogDomains.RPC_PROTOCOL ) ; arguments = args ; // Create codec factory: codecFactory = new CodecFactoryImpl( orb ); // Create new interceptor list: interceptorList = new InterceptorList( wrapper ); // Create a new PICurrent. current = new PICurrent( orb ); // Create new interceptor invoker, initially disabled: interceptorInvoker = new InterceptorInvoker( orb, interceptorList, current ); // Register the PI current and Codec factory objects orb.getLocalResolver().register( ORBConstants.PI_CURRENT_NAME, ClosureFactory.makeConstant( current ) ) ; orb.getLocalResolver().register( ORBConstants.CODEC_FACTORY_NAME, ClosureFactory.makeConstant( codecFactory ) ) ; } public void initialize() { // If we have any orb initializers, make use of them: if( orb.getORBData().getORBInitializers() != null ) { // Create the ORBInitInfo object to pass to ORB intializers: ORBInitInfoImpl orbInitInfo = createORBInitInfo(); // Make sure get_slot and set_slot are not called from within // ORB initializers: current.setORBInitializing( true ); // Call pre_init on all ORB initializers: preInitORBInitializers( orbInitInfo ); // Call post_init on all ORB initializers: postInitORBInitializers( orbInitInfo ); // Proprietary: sort interceptors: interceptorList.sortInterceptors(); // Re-enable get_slot and set_slot to be called from within // ORB initializers: current.setORBInitializing( false ); // Ensure nobody makes any more calls on this object. orbInitInfo.setStage( ORBInitInfoImpl.STAGE_CLOSED ); // Set cached flags indicating whether we have interceptors // registered of a given type. hasIORInterceptors = interceptorList.hasInterceptorsOfType( InterceptorList.INTERCEPTOR_TYPE_IOR ); // XXX This must always be true, so that using the new generic // RPC framework can pass info between the PI stack and the // framework invocation stack. Temporary until Harold fixes // this. Note that this must never be true until after the // ORBInitializer instances complete executing. //hasClientInterceptors = interceptorList.hasInterceptorsOfType( //InterceptorList.INTERCEPTOR_TYPE_CLIENT ); hasClientInterceptors = true; hasServerInterceptors = interceptorList.hasInterceptorsOfType( InterceptorList.INTERCEPTOR_TYPE_SERVER ); // Enable interceptor invoker (not necessary if no interceptors // are registered). This should be the last stage of ORB // initialization. interceptorInvoker.setEnabled( true ); } } /** * ptc/00-08-06 p 205: "When an application calls ORB::destroy, the ORB * 1) waits for all requests in progress to complete * 2) calls the Interceptor::destroy operation for each interceptor * 3) completes destruction of the ORB" * * This must be called at the end of ORB.destroy. Note that this is not * part of the PIHandler interface, since ORBImpl implements the ORB interface. */ public void destroyInterceptors() { interceptorList.destroyAll(); } public void objectAdapterCreated( ObjectAdapter oa ) { if (!hasIORInterceptors) return ; interceptorInvoker.objectAdapterCreated( oa ) ; } public void adapterManagerStateChanged( int managerId, short newState ) { if (!hasIORInterceptors) return ; interceptorInvoker.adapterManagerStateChanged( managerId, newState ) ; } public void adapterStateChanged( ObjectReferenceTemplate[] templates, short newState ) { if (!hasIORInterceptors) return ; interceptorInvoker.adapterStateChanged( templates, newState ) ; } /* ***************** * Client PI hooks *****************/ public void disableInterceptorsThisThread() { if( !hasClientInterceptors ) return; RequestInfoStack infoStack = (RequestInfoStack)threadLocalClientRequestInfoStack.get(); infoStack.disableCount++; } public void enableInterceptorsThisThread() { if( !hasClientInterceptors ) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -