piorb.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,284 行 · 第 1/4 页
JAVA
1,284 行
/* * @(#)PIORB.java 1.63 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.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.Delegate;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CORBA.portable.RemarshalException;import com.sun.corba.se.internal.corba.ClientDelegate;import com.sun.corba.se.internal.corba.RequestImpl;import com.sun.corba.se.internal.core.ClientResponse;import com.sun.corba.se.internal.core.ClientRequest;import com.sun.corba.se.internal.core.ClientSubcontract;import com.sun.corba.se.internal.core.InternalRuntimeForwardRequest;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.core.ServerRequest;import com.sun.corba.se.internal.core.ServiceContexts;import com.sun.corba.se.internal.core.Constant;import com.sun.corba.se.internal.iiop.Connection;import com.sun.corba.se.internal.iiop.IIOPConnection;import com.sun.corba.se.internal.iiop.IIOPOutputStream;import com.sun.corba.se.internal.iiop.messages.ReplyMessage;import com.sun.corba.se.internal.ior.IIOPProfile;import com.sun.corba.se.internal.ior.IORTemplate;import com.sun.corba.se.internal.orbutil.ORBConstants;import com.sun.corba.se.internal.orbutil.ORBClassLoader;import com.sun.corba.se.internal.POA.POAImpl;import com.sun.corba.se.internal.POA.POAORB;import com.sun.corba.se.internal.orbutil.ORBUtility;import org.omg.IOP.CodecFactory;import org.omg.PortableInterceptor.ForwardRequest;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 java.util.*;import java.io.IOException;/** * Extends the POAORB to provide portable interceptor functionality. */public class PIORB extends POAORB{ // 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 actual instances of the initializers. Some elements mat be null // if there were errors finding or instantiating intializers. These // entries should be ignored. ORBInitializer[] orbInitializers = 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; // List of property name prefixes recognized by this ORB. private static final String[] PIORBPropertyNamePrefixes = { ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX }; // 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; 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 simulate a Stack here instead of using java.util.Stack because // java.util.Stack is thread-safe, negatively impacting performance. // We use an ArrayList instead since it is not thread-safe. // RequestInfoStack is used quite frequently. private final class RequestInfoStack { // The stack for RequestInfo objects. private final ArrayList stack = new ArrayList(); // 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; // Tests if this stack is empty. public final boolean empty() { return stack.size() == 0; } // Looks at the object at the top of this stack without removing it // from the stack. public final Object peek() { int len = stack.size(); if( len == 0 ) throw new EmptyStackException(); return stack.get( len - 1 ); } // Removes the object at the top of this stack and returns that // object as the value of this function. public final Object pop() { Object obj; int len = stack.size(); if( len == 0 ) throw new EmptyStackException(); obj = stack.get( len - 1 ); stack.remove( len - 1 ); return obj; } // Pushes an item onto the top of the stack public final Object push( Object item ) { stack.add( item ); return item; } } /** * Default constructor. * This is the only constructor, and it must be followed by * the appropriate set_parameters() call. */ public PIORB() { super(); // Create codec factory: codecFactory = new CodecFactoryImpl( this ); // Create new interceptor list: interceptorList = new InterceptorList(); // Create a new PICurrent. current = new PICurrent( this ); // Create new interceptor invoker, initially disabled: interceptorInvoker = new InterceptorInvoker( this, interceptorList, current ); // Register the PI current and Codec factory objects registerInitialReference( ORBConstants.PI_CURRENT_NAME, new Constant( current ) ) ; registerInitialReference( ORBConstants.CODEC_FACTORY_NAME, new Constant( codecFactory ) ) ; } /** * Do miscellaneous initialization for subcontracts. This is called * after set_parameters() in the POAORB. It is used here to create * the CodecFactory. */ protected void initPostProcessing() { // Allow POAORB to do post-processing initialization super.initPostProcessing(); // If we have any orb initializers, make use of them: if( orbInitializers != 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 ); hasClientInterceptors = interceptorList.hasInterceptorsOfType( InterceptorList.INTERCEPTOR_TYPE_CLIENT ); 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" */ public void destroy() { super.destroy(); interceptorList.destroyAll(); } /* ********************************************************************** * The following methods deal with ORB initialization and property * parsing, etc. ************************************************************************/ /** * Return a list of property names prefixes that this ORB is interested in. * This may be overridden by subclasses, but subclasses must call * super.getPropertyNamePrefixes() to get all names. * Called from super.set_parameters() for both application and applets. */ protected String[] getPropertyNamePrefixes() { String[] names = super.getPropertyNamePrefixes(); // Add names that we are interested in int supercount = names.length; String[] allnames = new String[supercount + PIORBPropertyNamePrefixes.length]; for ( int i=0; i<supercount; i++ ) allnames[i] = names[i]; for ( int i=0; i<PIORBPropertyNamePrefixes.length; i++ ) allnames[i+supercount] = PIORBPropertyNamePrefixes[i]; if (ORBInitDebug) { dprint( "getPropertyNamePrefixes returns " + ORBUtility.objectToString( allnames ) ) ; } return allnames; } /** * Initialize any necessary ORB state; get attributes if possible. * Called from org.omg.CORBA.ORB.init(). This method is overridden
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?