// Copyright (c) 1999, 2000 Oracle Corporation package oracle.jbo.common.ampool; import java.util.*; import oracle.jbo.*; /** * This class demonstrates usage of the Application Module pool. *

** ** View implementation of PoolTester **

* @author Juan Oropeza */ public class PoolTester extends Object { /** * Constructor */ public PoolTester() { } public void doTest() throws Exception { Hashtable info = new Hashtable(); info.put(JboContext.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY); info.put(JboContext.DEPLOY_PLATFORM, "LOCAL"); PoolMgr.getInstance().createPool("TestAMPool", "package2.Package2Module" , "jdbc:oracle:thin:scott/tiger@localhost:1521:orcl", info); ApplicationPool pool = PoolMgr.getInstance().getPool("TestAMPool"); ApplicationModule instance = pool.checkout(); ApplicationModule instance2 = pool.checkout(); pool.checkin(instance2); ApplicationModule instance3 = pool.checkout(); PoolMgr.getInstance().removePool("TestAMPool"); // create a pool with a custom application pool class PoolMgr.getInstance().createPool("CustomTestAMPool", "oracle.jbo.common.ampool.CustomPool" , "package2.Package2Module" , "jdbc:oracle:thin:scott/tiger@localhost:1521:orcl", info); pool = PoolMgr.getInstance().getPool("CustomTestAMPool"); try { instance = pool.checkout(); instance = pool.checkout(); instance = pool.checkout(); instance = pool.checkout(); instance = pool.checkout(); } catch(Exception ex) { ex.printStackTrace(); } } /** * main * @param args */ public static void main(String[] args) { PoolTester poolTester = new PoolTester(); try { poolTester.doTest(); } catch(Exception ex) { ex.printStackTrace(); } } } /** ** This is a simple application pool class that only allows checkout of 3 instances **/ class CustomPool extends ApplicationPoolImpl { public CustomPool() { } /** * checkout * @return oracle.jbo.ApplicationModule */ public synchronized ApplicationModule checkout() throws Exception { // if the instance count > 3 throw an exception int nCount = getInstanceCount(); if(nCount > 3) { throw new RuntimeException("You have exceeded the number of instances for this pool"); } return super.checkout(); } }