// Copyright (c) 1999, 2000 Oracle Corporation package oracle.jbo.common.ampool; import java.util.Hashtable; import java.util.Enumeration; import oracle.jbo.common.Configuration; import oracle.jbo.*; /** ** This class manages the Application Pool. It is a singleton instance. ** ** View implementation of PoolMgr **
** @author Juan Oropeza **/ public class PoolMgr extends Object { static PoolMgr instance = new PoolMgr(); Hashtable poolList = new Hashtable(10); /** ** Constructor **/ private PoolMgr() { } /** ** Retrieves the singleton instance of the Pool Manager **/ static public PoolMgr getInstance() { return instance; } /** ** returns true if the pool has already been created. **/ public synchronized boolean isPoolCreated(String sName) { if(poolList.get(sName) != null) return true; return false; } /** ** Returns the ApplicationPool interface for the named pool. **/ public synchronized ApplicationPool getPool(String sName) { return (ApplicationPool)poolList.get(sName); } /** ** Removes the named pool and calls remove() function on all ApplicationModule ** instances that are being managed by the pool. **/ public synchronized void removePool(String sName) { if(!isPoolCreated(sName)) return; ApplicationPool pool = getPool(sName); poolList.remove(sName); pool.releaseInstances(); } /** ** Create a new Application Module pool, throws an exception if the pool is already registered. ** The connectInfo parameter provides the necessary settings required for creating instances of ** Application Modules that are part of the pool. You can also specify the name of the class that ** implements the ApplicationPool interface. This is an important setting for users that want to provide ** a custom implementation of the ApplicationPool interface. The default ApplicationPool implementation is ** in the oracle.jbo.client.ampool.ApplicationPoolImpl class. **/ public synchronized ApplicationPool createPool(String sName , String sClass, String sApplicationModule, String sConnectString, Hashtable env) throws Exception { if (isPoolCreated(sName)) { throw new ApplicationPoolException(AMPoolMessageBundle.class, AMPoolMessageBundle.EXC_AMPOOL_MGR_ALREADY_CREATED, new Object[] { sName }); } Class poolClass = Class.forName(sClass); ApplicationPool pool = (ApplicationPool)poolClass.newInstance(); pool.initialize(sName, sApplicationModule, sConnectString, env); poolList.put(sName, pool); return pool; } /** ** Create a new Application Module pool, throws an exception if the pool is already registered. ** The connectInfo parameter provides the necessary settings required for creating instances of ** Application Modules that are part of the pool. You can also specify the name of the class that ** implements the ApplicationPool interface. This is an important setting for users that want to provide ** a custom implementation of the ApplicationPool interface. The default ApplicationPool implementation is ** in the oracle.jbo.client.ampool.ApplicationPoolImpl class. **/ public synchronized ApplicationPool createPool(String sName , String sApplicationModule, String sConnectString, Hashtable env) throws Exception { return createPool(sName , "oracle.jbo.common.ampool.ApplicationPoolImpl", sApplicationModule, sConnectString, env); } /** ** Returns the Enumeration interface that allows you to enumerate through ** all the Application Pools that are registered with the Pool Manager. **/ public synchronized Enumeration getPools() { return poolList.elements(); } public synchronized Enumeration getPoolNames() { return poolList.keys(); } /** ** Create a new Application Module pool, throws an exception if the pool is already registered. ** ** This method creates an Application Module pool, based on the named AppModule Configuaraion ** ** ** The connectInfo parameter provides the necessary settings required for creating instances of ** Application Modules that are part of the pool. You can also specify the name of the class that ** implements the ApplicationPool interface. This is an important setting for users that want to provide ** a custom implementation of the ApplicationPool interface. The default ApplicationPool implementation is ** in the oracle.jbo.client.ampool.ApplicationPoolImpl class. ** ** @param sName name of the pool ** @param sPackageName package name of the AppModule., package10, for package10.Package10Module ** @param sConfigName named Configuration to use **/ public synchronized ApplicationPool createPool(String sName , String sPackageName, String sConfigName) throws Exception { String configFileName = Configuration.buildConfigurationFileName(sPackageName); Configuration configuration = new Configuration(); configuration.loadFromClassPath(configFileName); Hashtable env = configuration.getConfiguration(sConfigName); String sApplicationModule = null; sApplicationModule = (String)env.get(Configuration.APPLICATION_NAME_PROPERTY); String sConnectString = (String)env.get(Configuration.DB_CONNECTION_PROPERTY); if ((sApplicationModule == null) || (sConnectString == null)) throw new Exception("Configuration does not define one or more properties "); // dump the environment Enumeration e = env.keys(); String sValue; String sKey; while(e.hasMoreElements()) { sKey = e.nextElement().toString(); sValue = env.get(sKey).toString(); System.out.println(sKey + " = [" + sValue + "]"); } ApplicationPool pool = createPool(sName, sApplicationModule, sConnectString, env); pool.setUserData(env); return pool; } }