poaorb.java
来自「java jdk 1.4的源码」· Java 代码 · 共 988 行 · 第 1/3 页
JAVA
988 行
/* * @(#)POAORB.java 1.116 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.POA;import java.util.*;import java.net.InetAddress;import org.omg.PortableServer.*;import org.omg.CORBA.ORBPackage.InvalidName;import org.omg.CORBA.Any;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.INITIALIZE;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.NVList;import org.omg.CORBA.ORBPackage.InvalidName ;import org.omg.CORBA.WrongTransaction;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CORBA.portable.RemarshalException;import org.omg.CosNaming.NamingContext;import com.sun.corba.se.internal.core.*;import com.sun.corba.se.internal.ior.IIOPProfile;import com.sun.corba.se.internal.iiop.Connection;import com.sun.corba.se.internal.ior.IORTemplate;import com.sun.corba.se.internal.iiop.messages.ReplyMessage;import com.sun.corba.se.internal.orbutil.ORBUtility; //d11638import com.sun.corba.se.internal.orbutil.ORBConstants; import com.sun.corba.se.internal.orbutil.ORBClassLoader; import com.sun.corba.se.internal.corba.ClientDelegate;import com.sun.corba.se.internal.corba.CORBAObjectImpl;import com.sun.corba.se.internal.corba.RequestImpl;import com.sun.corba.se.internal.corba.ServerDelegate;import com.sun.corba.se.internal.Activation.BootStrapActivation;import com.sun.corba.se.ActivationIDL.Activator;import com.sun.corba.se.ActivationIDL.ActivatorHelper;import com.sun.corba.se.ActivationIDL.Locator;import com.sun.corba.se.ActivationIDL.LocatorHelper;import com.sun.corba.se.ActivationIDL.IIOP_CLEAR_TEXT;import com.sun.corba.se.ActivationIDL.EndPointInfo;public class POAORB extends com.sun.corba.se.internal.iiop.ORB{ public static final int DefaultSCID = ORBConstants.TransientSCID; // This is the mapping from subcontract-class to subcontract-ids. private String[] scTable[] = { {ORBConstants.GenericPOAClient, ORBConstants.GenericPOAServer, Integer.toString(ORBConstants.TransientSCID)}, {ORBConstants.GenericPOAClient, ORBConstants.GenericPOAServer, Integer.toString(ORBConstants.PersistentSCID)}, {ORBConstants.ServantCachePOAClient, ORBConstants.GenericPOAServer, Integer.toString(ORBConstants.SCTransientSCID)}, {ORBConstants.ServantCachePOAClient, ORBConstants.GenericPOAServer, Integer.toString(ORBConstants.SCPersistentSCID)}, }; // Information required for supporting persistence/activation: // orbdPort is port at which ORBD listens. This is embedded in persistent // objrefs so that ORBD gets invocations first and has a chance to activate // this server if necessary. //private int orbdPort=0; - Note: orbd ports now live in the GIOP endpoint list private boolean orbdPortInitialized=false; private boolean persistentPortInitialized=false; private int persistentServerId=0; boolean persistentServerIdInitialized=false; private String persistentServerName = null; private int persistentServerPort; private EndPoint serverEndPoint; // Stuff for supporting activation thru orbd private boolean serverIsORBActivated = false; private BadServerIdHandler badServerIdHandler = null; private String badServerIdHandlerClass = null; // POA stuff POAImpl rootPOA; org.omg.PortableServer.Current poaCurrent; Set poaManagers = Collections.synchronizedSet(new HashSet(4)); DelegateImpl delegateImpl; // Combined list of initialization props, applet params, commandline args protected Properties allProps = new Properties(); // List of property names recognized by this ORB. private static final String[] POAORBPropertyNames = { ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY, ORBConstants.SERVER_ID_PROPERTY, ORBConstants.BAD_SERVER_ID_HANDLER_CLASS_PROPERTY, ORBConstants.ACTIVATED_PROPERTY }; // This method creates the root POA. Note that this has the crucial // side-effect of starting the transport, which allocates server sockets // for listening for incoming requests. This is done indirectly // when the root POA creates its ior template, which requires an IIOP // address, which gets host and port, which starts the transport. protected POAImpl makeRootPOA( ) { POAManagerImpl poaManager = new POAManagerImpl( this ) ; POAImpl result = new POAImpl( ORBConstants.ROOT_POA_NAME, poaManager, Policies.rootPOAPolicies, null, null, this ) ; return result; } /** Default constructor. Called from org.omg.CORBA.ORB.init(). * This is the only constructor, and it must be followed by * the appropriate set_parameters() call from org.omg.CORBA.ORB.init(). */ public POAORB() { super(); // We delay the evaluation of makeRootPOA until // a call to resolve_initial_references( "RootPOA" ). // The Future guarantees that makeRootPOA is only called once. Closure rpClosure = new Closure() { public Object evaluate() { return POAORB.this.makeRootPOA() ; } } ; registerInitialReference( ORBConstants.ROOT_POA_NAME, new Future( rpClosure ) ) ; poaCurrent = new POACurrent(this); registerInitialReference( ORBConstants.POA_CURRENT_NAME, new Constant( poaCurrent ) ) ; }/****************************************************************************** * The following methods deal with ORB initialization and property parsing etc. * Only the first two set_parameters() are public; rest are internal methods. ******************************************************************************/ /** * Initialize any necessary ORB state by parsing passed parameters/props. * Called from org.omg.CORBA.ORB.init(...). * @param args String arguments typcially from the main() method * @param props Properties that are specific to the application */ protected void set_parameters(String[] args, java.util.Properties props) { super.set_parameters(args, props); initializePOA( ); // The InetAddress objects are used to compare ORBInitialHost and // LocalHost. If these two are equal and persistentServerPort == ORBInitialPort // then BootStrap activation is started. ORB will act as ORBD+ORB try{ if( ( persistentServerPort == ORBInitialPort ) && ( ORBInitialPort != 0 ) && getLocalHostName().equals(getHostName( ORBInitialHost )) ) // This means that the ORB is started without ORBD and is listening // both BootStrap and other requests in one port { // BootStrapActivation calls getInitialService( "<ServiceName>") // and initializes all the services for resolve_initial_references to // work BootStrapActivation theActivation = new BootStrapActivation( this ); theActivation.start( ); } } catch( Exception e ){ // If there is any exception here, do pointout it is a Bootstrap // initialization error. throw new INITIALIZE(MinorCodes.BOOTSTRAP_ERROR, CompletionStatus.COMPLETED_NO ); } // Get all properties and store them for later use. if( props != null ) { allProps = (Properties)props.clone(); } initPostProcessing(); } private String getHostName(String host) throws java.net.UnknownHostException { return InetAddress.getByName( host ).getHostAddress(); } /* keeping a copy of the getLocalHostName so that it can only be called * internally and the unauthorized clients cannot have access to the * localHost information, originally, the above code was calling getLocalHostName * from Connection.java. If the hostname is cached in Connection.java, then * it is a security hole, since any unauthorized client has access to * the host information. With this change it is used internally so the * security problem is resolved. Also in Connection.java, the getLocalHost() * implementation has changed to always call the * InetAddress.getLocalHost().getHostAddress() */ private static String localHostString = null; private String getLocalHostName() { if (localHostString != null) { return localHostString; } else { try { synchronized (com.sun.corba.se.internal.POA.POAORB.class){ if ( localHostString == null ) localHostString = InetAddress.getLocalHost().getHostAddress(); return localHostString; } } catch (Exception ex) { throw new INTERNAL( com.sun.corba.se.internal.orbutil.MinorCodes.GET_LOCAL_HOST_FAILED, CompletionStatus.COMPLETED_NO ); } } } /** * Initialize any necessary ORB state by parsing passed parameters/props. * Called from org.omg.CORBA.ORB.init(...). * @param app the applet * @param props Properties that are specific to the application/applet */ protected void set_parameters(java.applet.Applet app, java.util.Properties props) { super.set_parameters(app, props); initializePOA() ; // We will not support single address mode in Applets, // since Applets cannot act as ORBD. // Get all properties and store them for use later. if( props != null ) { allProps = (Properties)props.clone(); } initPostProcessing(); } /** Return a list of property names that this ORB is interested in. * This may be overridden by subclasses, but subclasses must call * super.getPropertyNames() to get all names. * Called from super.set_parameters() for both application and applets. */ protected String[] getPropertyNames() { String[] names = super.getPropertyNames(); String[] result = ORBUtility.concatenateStringArrays( names, POAORBPropertyNames ) ; if (ORBInitDebug) dprint( "getPropertyNames returns " + ORBUtility.objectToString( result ) ) ; return result ; } /** Set ORB internal variables using the properties specified. * Called from super.set_parameters() for both application and applets. */ protected void parseProperties(java.util.Properties props) { super.parseProperties(props); // get persistent server port String serverPortStr = props.getProperty( ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY ) ; if (serverPortStr != null) { setPersistentServerPort(Integer.valueOf(serverPortStr).intValue()); } // get persistent ServerId String persServerIdStr = props.getProperty( ORBConstants.SERVER_ID_PROPERTY ) ; if (persServerIdStr != null) { setPersistentServerId(Integer.valueOf(persServerIdStr).intValue()); } // // BadServerIdHandler // badServerIdHandlerClass = props.getProperty( ORBConstants.BAD_SERVER_ID_HANDLER_CLASS_PROPERTY ); // determine whether the server was ORB activated String activatedStr = props.getProperty( ORBConstants.ACTIVATED_PROPERTY ) ; if (activatedStr != null) { serverIsORBActivated = true; } // get all properties and store them for use later. Enumeration e = props.keys(); while ( e.hasMoreElements() ) { Object key = e.nextElement(); allProps.put(key, props.getProperty((String)key)); } } private void initializePOA( ) { // register subcontracts in the subcontractRegistry // this is overridden in the derived subclass to // register it's own subcontracts if any initSubcontractRegistry(); delegateImpl = new DelegateImpl(this); } /** Do miscellaneous other initialization for subcontracts, registration * with ORBD, POA, etc. */ protected void initPostProcessing() { // determine the ORBD port so that persistent objrefs can be // created. if (serverIsORBActivated) { try { Locator locator = LocatorHelper.narrow( resolve_initial_references( ORBConstants.SERVER_LOCATOR_NAME )) ; Collection serverEndpoints = getServerEndpoints(); Iterator iterator = serverEndpoints.iterator(); while (iterator.hasNext()) { EndPoint ep = (EndPoint) iterator.next(); // REVISIT - use exception instead of -1. int port = locator.getEndpoint(ep.getType()); if (port == -1) { port = locator.getEndpoint(EndPoint.IIOP_CLEAR_TEXT);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?