IBM Branch Transformation Toolkit Javadoc

com.ibm.btt.services
Class GenericPool

java.lang.Object
  extended bycom.ibm.btt.base.Service
      extended bycom.ibm.btt.services.GenericPool
All Implemented Interfaces:
BTTService, Externalizable, java.io.Externalizable, java.lang.Runnable, java.io.Serializable

public class GenericPool
extends Service
implements BTTService, java.lang.Runnable

The GenericPool is a pool that manages service that implement the Poolable interface. The pool has an initial size externalized in the service definition. The pool size grows if more instances of Poolable objects are required and the current size is lower than the maximum size. The maximum size is also externalized. The pool size shrinks if the maximum number of concurrent request for communications services during a period of time is lower than the current number of elements in the pool.

See Also:
Serialized Form

Field Summary
(package private)  int cleanupTime
          Time between resizing processes
static java.lang.String COMPID
          The component id for the trace
static java.lang.String DEFAULT_RESPONSE
          Default response
(package private)  int indexOfLastSession
          Index of the last element that was assigned
(package private)  int initialSize
          Initial pool size
(package private)  int maxConcurrents
          Maximum number of concurrent request from the last resizing process
(package private)  int maxPoolSize
          Maximum pool size
(package private)  int orphanTimeout
          Orphan Timeout in second.
 java.util.Vector pool
          The pool of the service object
(package private)  java.util.Hashtable poolHash
          Internal semaphore used to notify that a service has been released
(package private)  java.lang.Object poolSem
          Object used for synchronization purposes
(package private)  int requestsCount
          Counter of current concurrent requests
(package private)  Semaphore sem
          Internal semaphore used to notify that a service has been released
 java.lang.String serviceName
          The service name
(package private)  int size
          Current pool size
(package private)  int spare
          Additional percentage of the pool size to be added during the resizing process
(package private)  long timeBetweenRetries
          Time to wait for a retry when no free service is available
 
Fields inherited from class com.ibm.btt.base.Service
externalizer, name
 
Constructor Summary
GenericPool()
          Default GenericPool constructor
GenericPool(java.lang.String aName)
          This constructor creates a GenericPool object.
 
Method Summary
 Poolable createPoolable()
          Returns a new instance of the Poolable element that is managed in the pool.
protected  void freeAll()
          Marks every pool element as not in use.
 int getOrphanTimeout()
          Returns the orphanTimeout.
 Poolable getPoolable()
          Returns the first element in the pool that is not in use.
 Poolable getPoolable(boolean newChance)
          Returns the first free element available in the pool.
 Poolable getPoolable(java.lang.String pKey)
          Returns the first element in the pool that is not in use.
 java.lang.String getServiceName()
          Returns the service name.
 int getSize()
          Returns the current pool's size.
 java.lang.Object handleCommand(java.lang.String opName, java.util.Hashtable parts)
          Command method to handle the request from the requester.
 void initialize()
          Initializes some values, fills the pool, and creates a Thread for the resizing process if necessary.
 java.lang.Object initializeFrom(Tag aTag)
          Initializes the Service reading its attributes values from aTag.
 void initInstance()
          Initializes the thread responsible for resizing the pool.
 void insertPoolable(Poolable poolable)
          Inserts a new Poolable object in the pool.
 boolean isThreadIsAlive()
          Returns the status of the thread responsible for resizing the pool.
 java.lang.Object processRequest(java.lang.String opName, java.util.Hashtable parts)
          Command interface for the service
 void releaseOrphan()
          Release the orphan instance.
 void releaseOrphan(int orphanTime)
          Release the orphan instance.
 void releasePoolable(Poolable poolable)
          Releases a Poolable object.
protected  void removeAll()
          Removes all the Poolable objects from the pool.
 void removePoolable(Poolable poolable)
          Removes a Poolable object from the pool.
 void run()
           
 void setOrphanTimeout(int orphanTimeout)
          Sets the orphanTimeout.
 void setServiceName(java.lang.String name)
          Sets the serviceName attribute to the string provided as an argument.
 void setSize(int i)
          Sets the size attribute to the int provided as an argument.
 void terminate()
          Frees and closes all the objects from the pool.
 java.lang.String toString()
          Converts this GenericPoolService to string.
 
Methods inherited from class com.ibm.btt.base.Service
externalizer, getExternalizer, getName, getTagName, readExternal, readExternal, readObject, removeExternal, setExternalizer, setName, toStrings, toTags, writeExternal, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serviceName

public java.lang.String serviceName
The service name


pool

public java.util.Vector pool
The pool of the service object


COMPID

public static final java.lang.String COMPID
The component id for the trace

See Also:
Constant Field Values

indexOfLastSession

int indexOfLastSession
Index of the last element that was assigned


size

int size
Current pool size


initialSize

int initialSize
Initial pool size


poolSem

java.lang.Object poolSem
Object used for synchronization purposes


maxPoolSize

int maxPoolSize
Maximum pool size


timeBetweenRetries

long timeBetweenRetries
Time to wait for a retry when no free service is available


cleanupTime

int cleanupTime
Time between resizing processes


requestsCount

int requestsCount
Counter of current concurrent requests


maxConcurrents

int maxConcurrents
Maximum number of concurrent request from the last resizing process


spare

int spare
Additional percentage of the pool size to be added during the resizing process


sem

Semaphore sem
Internal semaphore used to notify that a service has been released


poolHash

java.util.Hashtable poolHash
Internal semaphore used to notify that a service has been released


orphanTimeout

int orphanTimeout
Orphan Timeout in second. If a pool instance has no action in a specific period, the service will be released. 0 means the orphan timeout features will not enable. Also, the cleanupTime must be specified.


DEFAULT_RESPONSE

public static final java.lang.String DEFAULT_RESPONSE
Default response

See Also:
Constant Field Values
Constructor Detail

GenericPool

public GenericPool()
Default GenericPool constructor


GenericPool

public GenericPool(java.lang.String aName)
            throws java.io.IOException
This constructor creates a GenericPool object.

Parameters:
aName - The generic pool service name
Throws:
java.io.IOException
Method Detail

createPoolable

public Poolable createPoolable()
                        throws DSEInvalidArgumentException
Returns a new instance of the Poolable element that is managed in the pool.

Returns:
com.ibm.dse.cs.mq.Poolable - The new instance
Throws:
DSEInvalidArgumentException
DSEInvalidArgumentException

freeAll

protected void freeAll()
Marks every pool element as not in use.


getPoolable

public Poolable getPoolable(java.lang.String pKey)
Returns the first element in the pool that is not in use. The returned element is marked as in use to prevent it from being used by another client. If there are no free elements, this method creates a new instance if the pool size is lower than the maximum pool size.

Returns:
com.ibm.dse.cs.mq.Poolable - The element that is not in use

getPoolable

public Poolable getPoolable()
Returns the first element in the pool that is not in use. The returned element is marked as in use to prevent it from being used by another client. If there are no free elements, this method creates a new instance if the pool size is lower than the maximum pool size.

Returns:
com.ibm.dse.cs.mq.Poolable - The element that is not in use

getPoolable

public Poolable getPoolable(boolean newChance)
Returns the first free element available in the pool. The returned element is marked as in use to prevent it from being used by another client. If there are no free elements, this method creates a new instance if the pool size is lower that the maximum pool size. The newChance parameter determines if the request is a retry (false) or if it is the first time (true) an element is requested.

Parameters:
newChance - boolean Set to false if the current request is a retry
Returns:
com.ibm.dse.cs.mq.Pooleable - The element that is not in use

getServiceName

public java.lang.String getServiceName()
Returns the service name.

Returns:
java.lang.String - The service name

getSize

public int getSize()
Returns the current pool's size.

Returns:
int - The size

initialize

public void initialize()
                throws DSEException
Initializes some values, fills the pool, and creates a Thread for the resizing process if necessary.

Throws:
DSEException
DSEException

initializeFrom

public java.lang.Object initializeFrom(Tag aTag)
                                throws java.io.IOException,
                                       DSEException
Initializes the Service reading its attributes values from aTag.

Specified by:
initializeFrom in interface Externalizable
Overrides:
initializeFrom in class Service
Parameters:
aTag - com.ibm.dse.base.Tag
Returns:
java.lang.Object - The GenericPool Object
Throws:
java.io.IOException
DSEException

initInstance

public void initInstance()
                  throws DSEException
Initializes the thread responsible for resizing the pool.

Throws:
DSEException
DSEException

insertPoolable

public void insertPoolable(Poolable poolable)
Inserts a new Poolable object in the pool.

Parameters:
poolable - The object to be added to the pool

handleCommand

public java.lang.Object handleCommand(java.lang.String opName,
                                      java.util.Hashtable parts)
                               throws java.lang.Exception
Command method to handle the request from the requester.

Parameters:
opName - Operation name will be perfromed.
parts - Input paramters for the operation.
Returns:
java.lang.Object - The execution result
Throws:
java.lang.Exception

processRequest

public java.lang.Object processRequest(java.lang.String opName,
                                       java.util.Hashtable parts)
                                throws java.lang.Exception
Command interface for the service

Specified by:
processRequest in interface BTTService
Parameters:
opName - An operation name to indicate which process will be performed
parts - A Hashtable to store the parameter for a process
Returns:
Object A object which need to be serializable
Throws:
java.lang.Exception

isThreadIsAlive

public boolean isThreadIsAlive()
Returns the status of the thread responsible for resizing the pool.

Returns:
boolean - The status of the thread

releaseOrphan

public void releaseOrphan()
Release the orphan instance. The instance will be release if the instance's last access is exceeded the orphan timeout value. The orphan timeout value is according to the value from the definition file.


releaseOrphan

public void releaseOrphan(int orphanTime)
Release the orphan instance. The instance will be release if the instance's last access is exceeded the orphan timeout value(based on the input parameter)

Parameters:
orphanTime - - The orphan timeout value in second

releasePoolable

public void releasePoolable(Poolable poolable)
Releases a Poolable object. The released object is returned to the pool and signaled as available (not in use).

Parameters:
poolable - - The object to be released

removeAll

protected void removeAll()
Removes all the Poolable objects from the pool.


removePoolable

public void removePoolable(Poolable poolable)
Removes a Poolable object from the pool.

Parameters:
poolable - The object to be removed

run

public void run()
Specified by:
run in interface java.lang.Runnable
See Also:
Run the pool thread

setServiceName

public void setServiceName(java.lang.String name)
Sets the serviceName attribute to the string provided as an argument.

Parameters:
name - The new service name

setSize

public void setSize(int i)
Sets the size attribute to the int provided as an argument.

Parameters:
i - The size of the pool

terminate

public void terminate()
Frees and closes all the objects from the pool.

Overrides:
terminate in class Service

toString

public java.lang.String toString()
Converts this GenericPoolService to string.

Overrides:
toString in class Service
Returns:
java.lang.String

getOrphanTimeout

public int getOrphanTimeout()
Returns the orphanTimeout.

Returns:
int

setOrphanTimeout

public void setOrphanTimeout(int orphanTimeout)
Sets the orphanTimeout.

Parameters:
orphanTimeout - The orphanTimeout to set

IBM Branch Transformation Toolkit Javadoc

(c) Copyright IBM Corporation 1998, 2005