servermanagerimpl.java

来自「JAVA 所有包」· Java 代码 · 共 629 行 · 第 1/2 页

JAVA
629
字号
/* * @(#)ServerManagerImpl.java	1.49 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.activation;/** * * @author      Rohit Garg * @author      Ken Cavanaugh * @author      Hemanth Puttaswamy * @since       JDK1.2 */import java.lang.reflect.Constructor;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.NoSuchElementException;import org.omg.CORBA.OBJECT_NOT_EXIST;import org.omg.CORBA.SystemException;import com.sun.corba.se.spi.activation.EndPointInfo;import com.sun.corba.se.spi.activation.IIOP_CLEAR_TEXT;import com.sun.corba.se.spi.activation.ORBPortInfo;import com.sun.corba.se.spi.activation.Repository;import com.sun.corba.se.spi.activation.LocatorPackage.ServerLocation;import com.sun.corba.se.spi.activation.LocatorPackage.ServerLocationPerORB;import com.sun.corba.se.spi.activation.RepositoryPackage.ServerDef;import com.sun.corba.se.spi.activation._ServerManagerImplBase;import com.sun.corba.se.spi.activation.ServerAlreadyActive;import com.sun.corba.se.spi.activation.ServerAlreadyInstalled;import com.sun.corba.se.spi.activation.ServerAlreadyUninstalled;import com.sun.corba.se.spi.activation.ServerNotRegistered;import com.sun.corba.se.spi.activation.ORBAlreadyRegistered;import com.sun.corba.se.spi.activation.ServerHeldDown;import com.sun.corba.se.spi.activation.ServerNotActive;import com.sun.corba.se.spi.activation.NoSuchEndPoint;import com.sun.corba.se.spi.activation.InvalidORBid;import com.sun.corba.se.spi.activation.Server;import com.sun.corba.se.spi.activation.IIOP_CLEAR_TEXT;import com.sun.corba.se.spi.ior.IORTemplate ;import com.sun.corba.se.spi.ior.IOR ;import com.sun.corba.se.spi.ior.ObjectKey ;import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;import com.sun.corba.se.spi.ior.IORFactories ;import com.sun.corba.se.spi.ior.iiop.GIOPVersion ;import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;import com.sun.corba.se.spi.orb.ORB ;import com.sun.corba.se.spi.protocol.ForwardException;import com.sun.corba.se.spi.transport.CorbaTransportManager;import com.sun.corba.se.spi.logging.CORBALogDomains ;import com.sun.corba.se.impl.logging.ActivationSystemException ;import com.sun.corba.se.impl.oa.poa.BadServerIdHandler;import com.sun.corba.se.impl.orbutil.ORBConstants;import com.sun.corba.se.impl.orbutil.ORBClassLoader;import com.sun.corba.se.impl.orbutil.ORBUtility;import com.sun.corba.se.impl.util.Utility;public class ServerManagerImpl extends _ServerManagerImplBase    implements BadServerIdHandler{    // Using HashMap, since synchronization should be done by the calling    // routines    HashMap serverTable;    Repository repository;    CorbaTransportManager transportManager;    int initialPort;    ORB orb;    ActivationSystemException wrapper;    String dbDirName;    boolean debug = false ;     private int serverStartupDelay;    ServerManagerImpl(ORB orb, CorbaTransportManager transportManager,		      Repository repository, String dbDirName, boolean debug)    {        this.orb = orb;	wrapper = ActivationSystemException.get( orb, CORBALogDomains.ORBD_ACTIVATOR ) ;        this.transportManager = transportManager; // REVISIT - NOT USED.	this.repository = repository;	this.dbDirName = dbDirName;	this.debug = debug ;	LegacyServerSocketEndPointInfo endpoint =	    orb.getLegacyServerSocketManager()	        .legacyGetEndpoint(LegacyServerSocketEndPointInfo.BOOT_NAMING);	initialPort = ((SocketOrChannelAcceptor)endpoint)	    .getServerSocket().getLocalPort();        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            }        }        Class cls = orb.getORBData( ).getBadServerIdHandler();        if( cls == null ) {            orb.setBadServerIdHandler( this );        } else {	    orb.initBadServerIdHandler() ;        }        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 wrapper.serverNotExpectedToRegister() ;            } 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 wrapper.serverNotExpectedToRegister() ;            } else {		if (debug)		    System.out.println(			"ServerManagerImpl: registerEndpoints for server Id " +			serverId + " called.  This server is now active." ) ;		entry.registerPorts( orbId, endpointList );               	    }	}    }    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    {        Integer key = new Integer(serverId);	ServerTableEntry entry = null ;	synchronized (serverTable) {

⌨️ 快捷键说明

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