commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Santiago, Iris" <Iris.Santi...@qwest.com>
Subject Init parameters for poolable object
Date Fri, 04 Apr 2008 20:38:43 GMT
Hello,
 
I am implementing a GenericKeyedObjectPool, which contains a
KeyedPoolableObjectFactory.
I need to pass the init parameters when the object is created but, there
seems to be no way of doing this.
I created an object to be used as the key, which contains the init
parameters.  But, it seems to think
each object is a new key (even tho I do return it to the pool when I am
done) and every call to borrowObject
creates a new instance, instead of using the one I just returned.  Any
ideas/suggestions?
 
Here is an excerpt from the code:
 
 
public final class SessionPool
{
  public static GenericKeyedObjectPool wfaDoPool;
  public String init()
  {
    try
    {
      // Init sessions
      SessionFactory wfaDo = null;
      // WFA/DO Pool
      wfaDo = new SessionFactory();
      wfaDoPool = new GenericKeyedObjectPool(wfaDo);
      wfaDoPool.setMaxActive(3);
      wfaDoPool.setMaxIdle(5);
      wfaDoPool.setTestOnBorrow(true);
      return("Success");
    }
    catch (Exception ex)
    {
      return("SessionPool connect error");
    }
  }
}
 
public class SessionFactory extends BaseIntegrationSession
  implements KeyedPoolableObjectFactory
{
  public SessionFactory()
  {}
  public Object makeObject(Object key)
    throws LIRuntimeException, ScreenErr, MaxTimeOutException
  {
    WfaRegion regionObj = (WfaRegion)key;
    vtamId =regionObj.getImshost();
    String wfaHost = regionObj.getApplication();
    log.info("Create new WFA session for " + vtamId);
    TN3270Session session = new TN3270Session();
 
    log.debug("getNumActive(): " +
SessionPool.wfaDoPool.getNumActive(key));
    log.debug("getNumIdle(): " + SessionPool.wfaDoPool.getNumIdle(key));
    log.debug("key: " + key.toString());
    //connect session to host with credentials provided
    return session;
    }
  public void activateObject(Object key, Object obj) throws Exception
  {}
  public void passivateObject(Object key, Object obj) throws Exception
  {}
  public boolean validateObject(Object key, Object obj)
  {}
  public void destroyObject(Object key, Object obj) 
    throws MaxTimeOutException, LIRuntimeException, ScreenErr
  {
    TN3270Session session = (TN3270Session)obj;
    if(session.startCommConnected)
      session.stopCommunication();
    session.dispose();
    System.gc();
  }
}
 
public final class ScratchPad
{
  public CompleteJobResponseDocument doScratchPad(
    CompleteJobC2FindRequestDocument requestDoc)
  {
    CompleteJobResponseDocument respDoc = null;
    TN3270Session session = null;
    String region = null;
    WfaRegion wfaCreds = new WfaRegion();
    try
    {
      String host =
RegionTools.getWFADOHost(requestDoc.getCompleteJobC2FindRequest().getReg
ion());
      region =
RegionTools.getWFARegion(requestDoc.getCompleteJobC2FindRequest().getReg
ion());
      wfaCreds.setImshost(host);
      wfaCreds.setRegion(region);
      wfaCreds.setApplication("WFADO");
      session =
(TN3270Session)SessionPool.wfaDoPool.borrowObject(wfaCreds);
      // do work
      SessionPool.wfaDoPool.returnObject(wfaCreds, session);
    catch(Exception e)
    {}
    return respDoc;
  }
}
 
 
Thx


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.

Mime
  • Unnamed multipart/alternative (inline, 7-Bit, 0 bytes)
View raw message