FileDocCategorySizeDatePackage
S1ASThreadPoolManager.javaAPI DocGlassfish v2 API13905Wed May 23 14:45:40 BST 2007com.sun.enterprise.util

S1ASThreadPoolManager

public class S1ASThreadPoolManager extends Object implements com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolManager

Fields Summary
static Logger
_logger
private static final int
DEFAULT_NUMBER_OF_QUEUES
private static final int
DEFAULT_MIN_THREAD_COUNT
private static final int
DEFAULT_MAX_THREAD_COUNT
private static HashMap
idToIndexTable
private static HashMap
indexToIdTable
private static ArrayList
threadpoolList
private static String
defaultID
private static com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolManager
s1asThreadPoolMgr
Constructors Summary
S1ASThreadPoolManager()


	Orb orbBean = null;
	
        try {
            ServerContext serverContext = ApplicationServer.getServerContext();
             
            ConfigContext configContext = serverContext.getConfigContext();
            assert(configContext != null);
        
            // IiopService iiopServiceBean = ServerBeansFactory.getIiopServiceBean(configContext);
	    Config config = ServerBeansFactory.getConfigBean(configContext);

            assert(config != null);

            // orbBean = iiopServiceBean.getOrb();
	    com.sun.enterprise.config.serverbeans.ThreadPools 
			    threadpoolsElement = config.getThreadPools();
            assert (threadpoolsElement != null);

	    com.sun.enterprise.config.serverbeans.ThreadPool[] 
			allThreadpools = threadpoolsElement.getThreadPool();
	    for (int i = 0; i < allThreadpools.length; i++) {
		createThreadPools(allThreadpools[i], i);
	    }
	    defaultID = (String)indexToIdTable.get(new Integer(0));
        } catch (ConfigException cfe) {
            _logger.log(Level.SEVERE,"enterprise_util.orbmgr_config_excep", cfe);
        } catch (NullPointerException npe) {
            _logger.log(Level.FINE,"Server Context is NULL. Ignoring and proceeding.");
        }

	
    
Methods Summary
private voidcreateThreadPools(com.sun.enterprise.config.serverbeans.ThreadPool threadpoolBean, int index)

	String threadpoolId = null;
	String minThreadsValue, maxThreadsValue, timeoutValue, numberOfQueuesValue;
	int minThreads = DEFAULT_MIN_THREAD_COUNT;
	int maxThreads = DEFAULT_MAX_THREAD_COUNT;
	int idleTimeoutInSeconds = ORBConstants.DEFAULT_INACTIVITY_TIMEOUT;
	int numberOfQueues = DEFAULT_NUMBER_OF_QUEUES;

	try {
	    threadpoolId = threadpoolBean.getThreadPoolId();
	} catch (NullPointerException npe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
            }
	}
	try {
	    minThreadsValue = threadpoolBean.getMinThreadPoolSize();
	    minThreads = Integer.parseInt(minThreadsValue);
	} catch (NullPointerException npe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
		_logger.log(Level.WARNING, 
			"Using default value for steady-threadpool-size = " + minThreads);
            }
	} catch (NumberFormatException nfe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe);
		_logger.log(Level.WARNING, 
			"Using default value for min-threadpool-size = " + minThreads);
            }
	}
	try {
	    maxThreadsValue = threadpoolBean.getMaxThreadPoolSize();
	    maxThreads = Integer.parseInt(maxThreadsValue);
	} catch (NullPointerException npe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
		_logger.log(Level.WARNING, 
			"Using default value for max-threadpool-size = " + maxThreads);
            }
	} catch (NumberFormatException nfe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe);
		_logger.log(Level.WARNING, 
			"Using default value for max-threadpool-size = " + maxThreads);
            }
	}
	try {
	    timeoutValue = threadpoolBean.getIdleThreadTimeoutInSeconds();
	    idleTimeoutInSeconds = Integer.parseInt(timeoutValue);
	} catch (NullPointerException npe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
		_logger.log(Level.WARNING, 
			"Using default value for idle-thread-timeout-in-seconds = " + 
			idleTimeoutInSeconds);
            }
	} catch (NumberFormatException nfe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe);
		_logger.log(Level.WARNING, 
			"Using default value for idle-thread-timeout-in-seconds = " + 
			idleTimeoutInSeconds);
            }
	}

	// Currently this value is not used but when multi-queue threadpools are
	// implemented this could be used to decide which one to instantiate and
	// number of queues in the multi-queue threadpool
	try {
	    numberOfQueuesValue = threadpoolBean.getNumWorkQueues();
	    numberOfQueues = Integer.parseInt(numberOfQueuesValue);
	} catch (NullPointerException npe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
		_logger.log(Level.WARNING, 
			"Using default value for num-work-queues = " + 
			numberOfQueues);
            }
	} catch (NumberFormatException nfe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe);
		_logger.log(Level.WARNING, 
			"Using default value for num-work-queues = " + 
			numberOfQueues);
            }
	}
	
	// Mutiplied the idleTimeoutInSeconds by 1000 to convert to milliseconds
	com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool threadpool = 
	    new ThreadPoolImpl(minThreads, maxThreads, 
		    idleTimeoutInSeconds * 1000, threadpoolId,
			       ApplicationServer.getServerContext().getCommonClassLoader());


	// Add the threadpool instance to the threadpoolList
	threadpoolList.add(threadpool);

	// Associate the threadpoolId to the index passed
	idToIndexTable.put(threadpoolId, new Integer(index));

	// Associate the threadpoolId to the index passed
	indexToIdTable.put(new Integer(index), threadpoolId);
	
    
public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolgetDefaultThreadPool()
Returns the first instance of ThreadPool in the ThreadPoolManager

	try {
	    return getThreadPool(0);
	} catch (NoSuchThreadPoolException nstpe) {
	    if(_logger.isLoggable(Level.WARNING)) {
		_logger.log(Level.WARNING, "No default ThreadPool defined ", nstpe);
            }
	}
	return null;
    
public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolgetThreadPool(java.lang.String id)
This method will return an instance of the threadpool given a threadpoolId, that can be used by any component in the app. server.

throws
NoSuchThreadPoolException thrown when invalid threadpoolId is passed as a parameter


	Integer i = (Integer)idToIndexTable.get(id);
	if (i == null) {
	    throw new NoSuchThreadPoolException();
	}
	try {
	    com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool threadpool =
		(com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool)
		threadpoolList.get(i.intValue());
	    return threadpool;
	} catch (IndexOutOfBoundsException iobe) {
	    throw new NoSuchThreadPoolException();
	}
    
public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolgetThreadPool(int numericIdForThreadpool)
This method will return an instance of the threadpool given a numeric threadpoolId. This method will be used by the ORB to support the functionality of dedicated threadpool for EJB beans

throws
NoSuchThreadPoolException thrown when invalidnumericIdForThreadpool is passed as a parameter

 

	try {
	    com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool threadpool =
		(com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool)
		threadpoolList.get(numericIdForThreadpool);
	    return threadpool;
	} catch (IndexOutOfBoundsException iobe) {
	    throw new NoSuchThreadPoolException();
	}
    
public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolChoosergetThreadPoolChooser(int componentIndex)
Return an instance of ThreadPoolChooser based on the componentIndex that was passed as argument. This is added for improved performance so that the caller does not have to pay the cost of computing hashcode for the componentId

	//FIXME: This method is not used, but should be fixed once
	//ORB's nio select starts working and we start using ThreadPoolChooser
	//This will be mostly used by the ORB
	return null;
    
public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolChoosergetThreadPoolChooser(java.lang.String componentId)
Return an instance of ThreadPoolChooser based on the componentId that was passed as argument

	//FIXME: This method is not used, but should be fixed once
	//ORB's nio select starts working and we start using ThreadPoolChooser
	//This will be mostly used by the ORB
	return null;
    
public intgetThreadPoolChooserNumericId(java.lang.String componentId)
Gets the numeric index associated with the componentId specified for a ThreadPoolChooser. This method would help the component call the more efficient implementation i.e. getThreadPoolChooser(int componentIndex)

	//FIXME: This method is not used, but should be fixed once
	//ORB's nio select starts working and we start using ThreadPoolChooser
	//This will be mostly used by the ORB
	return 0;
    
public static com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolManagergetThreadPoolManager()


        
	return s1asThreadPoolMgr;
    
public intgetThreadPoolNumericId(java.lang.String id)
This method is used to return the numeric id of the threadpool, given a String threadpoolId. This is used by the POA interceptors to add the numeric threadpool Id, as a tagged component in the IOR. This is used to provide the functionality of dedicated threadpool for EJB beans

 
	Integer i = (Integer)idToIndexTable.get(id);
	return ((i == null) ? 0 : i.intValue());
    
public java.lang.StringgetThreadPoolStringId(int numericIdForThreadpool)
Return a String Id for a numericId of a threadpool managed by the threadpool manager

	String id = (String)indexToIdTable.get(new Integer(numericIdForThreadpool));
	return ((id == null) ? defaultID : id);
    
public voidsetThreadPoolChooser(java.lang.String componentId, com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolChooser aThreadPoolChooser)
Sets a ThreadPoolChooser for a particular componentId in the ThreadPoolManager. This would enable any component to add a ThreadPoolChooser for their specific use

	//FIXME: This method is not used, but should be fixed once
	//ORB's nio select starts working and we start using ThreadPoolChooser
	//This will be mostly used by the ORB