servermanagerimpl.java

来自「java jdk 1.4的源码」· Java 代码 · 共 616 行 · 第 1/2 页

JAVA
616
字号
/* * @(#)ServerManagerImpl.java	1.45 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.Activation;/** * * @version     1.3, 97/10/19 * @author      Rohit Garg * @since       JDK1.2 */import java.lang.reflect.Constructor;import java.util.HashMap;import java.util.Iterator;import java.util.ArrayList;import java.util.NoSuchElementException;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.OBJECT_NOT_EXIST;import org.omg.CORBA.CompletionStatus;import com.sun.corba.se.internal.core.*;import com.sun.corba.se.internal.util.Utility;import com.sun.corba.se.internal.orbutil.ORBConstants;import com.sun.corba.se.internal.orbutil.ORBClassLoader;import com.sun.corba.se.internal.POA.POAORB;import com.sun.corba.se.internal.POA.BadServerIdHandler;import com.sun.corba.se.internal.POA.ForwardException;import com.sun.corba.se.ActivationIDL.EndPointInfo;import com.sun.corba.se.ActivationIDL.IIOP_CLEAR_TEXT;import com.sun.corba.se.ActivationIDL.ORBPortInfo;import com.sun.corba.se.ActivationIDL.Repository;import com.sun.corba.se.ActivationIDL.LocatorPackage.ServerLocation;import com.sun.corba.se.ActivationIDL.LocatorPackage.ServerLocationPerORB;import com.sun.corba.se.ActivationIDL.RepositoryPackage.ServerDef;import com.sun.corba.se.ActivationIDL._ServerManagerImplBase;import com.sun.corba.se.ActivationIDL.ServerAlreadyActive;import com.sun.corba.se.ActivationIDL.ServerAlreadyInstalled;import com.sun.corba.se.ActivationIDL.ServerAlreadyUninstalled;import com.sun.corba.se.ActivationIDL.ServerNotRegistered;import com.sun.corba.se.ActivationIDL.ORBAlreadyRegistered;import com.sun.corba.se.ActivationIDL.ServerHeldDown;import com.sun.corba.se.ActivationIDL.ServerNotActive;import com.sun.corba.se.ActivationIDL.NoSuchEndPoint;import com.sun.corba.se.ActivationIDL.InvalidORBid;import com.sun.corba.se.ActivationIDL.Server;import com.sun.corba.se.ActivationIDL.IIOP_CLEAR_TEXT;import com.sun.corba.se.internal.ior.ObjectKeyFactory ;import com.sun.corba.se.internal.ior.ObjectKey ;import com.sun.corba.se.internal.ior.POAObjectKeyTemplate ;public class ServerManagerImpl extends _ServerManagerImplBase    implements BadServerIdHandler{    // Using HashMap, since synchronization should be done by the calling    // routines    HashMap serverTable;    Repository repository;    ServerGIOP sgiop;    int initialPort;    POAORB orb;    String dbDirName;    boolean debug = false ;     private int serverStartupDelay;    ServerManagerImpl(POAORB orb, ServerGIOP sgiop, Repository repository,		      String dbDirName, boolean debug)    {        this.orb        = orb;        this.sgiop      = sgiop;	this.repository = repository;	this.dbDirName = dbDirName;	this.debug = debug ;	initialPort = orb.getServerGIOP().getBootstrapEndpoint(0).getPort();        serverTable = new HashMap(256);        // The ServerStartupDelay is the delay added after the Server registers        // end point information. This is to allow the server to completely        // initialize after ORB is instantiated.        serverStartupDelay = ORBConstants.DEFAULT_SERVER_STARTUP_DELAY;        String  delay = System.getProperty( ORBConstants.SERVER_STARTUP_DELAY);        if( delay != null ) {            try {                serverStartupDelay = Integer.parseInt( delay );            } catch ( Exception e ) {                // Just use the default 1000 milliseconds as the default            }        }	BadServerIdHandler handler = null;	if (orb.getBadServerIdHandlerClass() == null) {	    handler = this;	} else {	    try {		Class[] params =		    new Class[] { org.omg.CORBA.ORB.class };		java.lang.Object[] args = new java.lang.Object[]{orb};                Class badServerIdHandlerClass                    = ORBClassLoader.loadClass(orb.getBadServerIdHandlerClass());                Constructor cons = badServerIdHandlerClass.getConstructor(params);		handler = (BadServerIdHandler) cons.newInstance(args);	    } catch (Exception e) {		throw new org.omg.CORBA.INITIALIZE(		    "Error while creating BadServerIdHandler: " + e.getMessage());	    }	}        orb.setBadServerIdHandler(handler);        ((com.sun.corba.se.internal.corba.ORB)orb).connect(this);        ProcessMonitorThread.start( serverTable );    }    public void activate(int serverId)        throws ServerAlreadyActive, ServerNotRegistered, ServerHeldDown    {        ServerLocation   location;        ServerTableEntry entry;        Integer key = new Integer(serverId);	synchronized(serverTable) {            entry = (ServerTableEntry) serverTable.get(key);	}        if (entry != null && entry.isActive()) {	    if (debug)		System.out.println( "ServerManagerImpl: activate for server Id " +				    serverId + " failed because server is already active. " +				    "entry = " + entry ) ;            throw new ServerAlreadyActive( serverId );	}        // locate the server        try {	    // We call getEntry here so that state of the entry is	    // checked for validity before we actually go and locate a server	    entry = getEntry(serverId);            if (debug)                System.out.println( "ServerManagerImpl: locateServer called with " +                                " serverId=" + serverId + " endpointType="                                + IIOP_CLEAR_TEXT.value + " block=false" ) ;	    location = locateServer(entry, IIOP_CLEAR_TEXT.value, false);	    if (debug)		System.out.println( "ServerManagerImpl: activate for server Id " +				    serverId + " found location " +				    location.hostname + " and activated it" ) ;        } catch (NoSuchEndPoint ex) {            if (debug)                System.out.println( "ServerManagerImpl: activate for server Id " +                                    " threw NoSuchEndpoint exception, which was ignored" );	}    }    public void active(int serverId, Server server) throws ServerNotRegistered    {        ServerTableEntry entry;        Integer key = new Integer(serverId);        synchronized (serverTable) {            entry = (ServerTableEntry) serverTable.get(key);            if (entry == null) {		if (debug)		    System.out.println( "ServerManagerImpl: active for server Id " +					serverId + " called, but no such server is registered." ) ;                throw (new INTERNAL(MinorCodes.SERVER_NOT_EXPECTED_TO_REGISTER,				    CompletionStatus.COMPLETED_NO));            } else {		if (debug)		    System.out.println( "ServerManagerImpl: active for server Id " +					serverId + " called.  This server is now active." ) ;		entry.register(server);	    }        }    }    public void registerEndpoints( int serverId, String orbId,	EndPointInfo [] endpointList ) throws NoSuchEndPoint, ServerNotRegistered,	ORBAlreadyRegistered    {	// orbId is ignored for now        ServerTableEntry entry;        Integer key = new Integer(serverId);        synchronized (serverTable) {            entry = (ServerTableEntry) serverTable.get(key);            if (entry == null) {		if (debug)		    System.out.println(			"ServerManagerImpl: registerEndpoint for server Id " +			serverId + " called, but no such server is registered." ) ;                throw (new INTERNAL(MinorCodes.SERVER_NOT_EXPECTED_TO_REGISTER,				    CompletionStatus.COMPLETED_NO));            } else {		if (debug)		    System.out.println(			"ServerManagerImpl: registerEndpoints for server Id " +			serverId + " called.  This server is now active." ) ;		entry.registerPorts( orbId, endpointList );               	    }	}    }    // XXX should look at the state of the server as well    public int[] getActiveServers()    {	ServerTableEntry entry;        int[] list = null;        synchronized (serverTable) {	    // unlike vectors, list is not synchronized	    ArrayList servers = new ArrayList(0);	    Iterator serverList = serverTable.keySet().iterator();	    try {	        while (serverList.hasNext()) {	            Integer key = (Integer) serverList.next();	            // get an entry	            entry = (ServerTableEntry) serverTable.get(key);		    if (entry.isValid() && entry.isActive()) {		        servers.add(entry);	            }	        }	    } catch (NoSuchElementException e) {	        // all done	    }	    // collect the active entries	    list = new int[servers.size()];	    for (int i = 0; i < servers.size(); i++) {	        entry = (ServerTableEntry) servers.get(i);		list[i] = entry.getServerId();	    }        }	if (debug) {	    StringBuffer sb = new StringBuffer() ;	    for (int ctr=0; ctr<list.length; ctr++) {		sb.append( ' ' ) ;		sb.append( list[ctr] ) ;	    }	    System.out.println( "ServerManagerImpl: getActiveServers returns" +				sb.toString() ) ;	}        return list;    }    public void shutdown(int serverId) throws ServerNotActive    {        ServerTableEntry entry;        Integer key = new Integer(serverId);	synchronized(serverTable) {            entry = (ServerTableEntry) serverTable.remove(key);            if (entry == null) {	        if (debug)		    System.out.println( "ServerManagerImpl: shutdown for server Id " +				    serverId + " throws ServerNotActive." ) ;	        throw new ServerNotActive( serverId );	    }            try {                entry.destroy();	        if (debug)		    System.out.println( "ServerManagerImpl: shutdown for server Id " +				    serverId + " completed." ) ;            } catch (Exception e) {	        if (debug)		    System.out.println( "ServerManagerImpl: shutdown for server Id " +				    serverId + " threw exception " + e ) ;	    }	}    }    private ServerTableEntry getEntry( int serverId )	throws ServerNotRegistered    {

⌨️ 快捷键说明

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