Package com.kheops.util
Class KObjectPool<T>
java.lang.Object
com.kheops.util.KObjectPool<T>
- All Implemented Interfaces:
- KSchedulerClient
- Direct Known Subclasses:
- DatabaseConnectionPool,- JMapNetworkConnectionPool,- JMapServerRemoteConnectionPool,- JMapServerThreadPool,- KSocketConnectionPool,- SdeConnectionPool
This abstract class encapsulates a pool of objects.
 Subclasses will override the method to manage these objects.
 
 The Object pool consists of
  
-minimumSize      : the initial number of objects 
  
-maximumSize      : the maximum number of objects 
  
-cleanupPeriod    : the amount of time between cleanups. During a clean up all the
  
 invalid input: ' ' objects created after the initial creation (objects over the minimum)
  
 invalid input: ' ' that are inactive for a period longer than the shrink period will be closed. 
  
-shrinkTime       : the amount of time extra objects can remain inactive before it is
  
 invalid input: ' ' eligible for clean up 
  
-recyclePeriod    : the amount of time an initial object can remain inactive before it is recycled
  
 invalid input: ' ' (objects are closed and reopen)
 
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected longprotected longprotected longstatic final longstatic final long
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidApply a non-blocking operation on each pool workers.voidThis method sets the object availablecheckOut()This method makes a request for an unlocked object from the pool.This method makes a request for an unlocked object from the pool.voidclose()This method closes one by one all the objects currently opened for this the poolabstract Tcreate()Creates the object encapsulating the appropriate objectvoidCreates an unlocked instance of the appropriate object and adds it to the pool.abstract voidThis method closes the objectlongGets the default timeout to use on checkout action if no timeout is specified.protected intgetId()This method gets the PoolMonitorInfo associated with the KObject pool instance.intGets the maximum number of concurrent objects allowedintGets the number of objects currently usedintGets the number of currently used objectsintGets the peak number of objects used simultaneously this method is used for statistic reasons.protected longvoidinitialize(int minimumSize) Initializes a KObjectPool instance with the specified minimum sizevoidinitialize(int minimumSize, long recyclePeriod) Initializes a KObjectPool instance with the specified minimum size and recycle periodvoidinitialize(int minimumSize, long shrinkTime, long cleanupPeriod, long recyclePeriod) Initializes a KObjectPool instance with the specified minimum size, recycle period, clean up period and shrink periodprotected voidvoidreset()This will close and reinitialize the pool.protected voidresourceAdded(T o) No-op hook that allows implementation instructions after resource creation.voidschCallback(int jobId) This method is automatically called by the KScheduler to either perform the clean up or object recycle jobsvoidsetDefaultTimeout(long defaultTimeout) Sets the default timeout to use on checkout action if no timeout is specified.voidsetPoolMaximumSize(int size) Sets the maximum number of objects allowedvoidsetPoolMinimumSize(int size) Sets the pool minimum sizeabstract booleanThis method checks if the object is valid
- 
Field Details- 
TIMEOUT_UNDEFINEDpublic static final long TIMEOUT_UNDEFINED- See Also:
 
- 
TIMEOUT_UNLIMITEDpublic static final long TIMEOUT_UNLIMITED- See Also:
 
- 
shrinkTimeprotected long shrinkTime
- 
cleanupPeriodprotected long cleanupPeriod
- 
recyclePeriodprotected long recyclePeriod
 
- 
- 
Constructor Details- 
KObjectPoolpublic KObjectPool()Creates a new instance
 
- 
- 
Method Details- 
initializeInitializes a KObjectPool instance with the specified minimum size- Parameters:
- minimumSize- the minimum number of objects in this pool
- Throws:
- Exception- if an error occurred while initializing the object pool
 
- 
initializeInitializes a KObjectPool instance with the specified minimum size and recycle period- Parameters:
- minimumSize- the minimum number of objects in this pool
- recyclePeriod- the amount of time an initial object can remain inactive before it is recycled (closed than reopen).
- Throws:
- Exception- if an error occurred while initializing the object pool
 
- 
initializepublic void initialize(int minimumSize, long shrinkTime, long cleanupPeriod, long recyclePeriod) throws Exception Initializes a KObjectPool instance with the specified minimum size, recycle period, clean up period and shrink period- Parameters:
- minimumSize- the minimum number of objects in this pool
- shrinkTime- the amount of time extra objects can remain inactive before it eligible for cleanup
- cleanupPeriod- the amount of time between cleanups
- recyclePeriod- the amount of time an initial object can remain inactive before it is recycled (closed than reopen).
- Throws:
- Exception- if an error occurred while initializing the object pool
 
- 
createCreates the object encapsulating the appropriate object- Returns:
- the corresponding object
- Throws:
- Exception- if an error occurred while creating the object
 
- 
validateThis method checks if the object is valid- Parameters:
- o- object to validate
- Returns:
- true if the object is valid false otherwise
 
- 
expireThis method closes the object- Parameters:
- o- the object to be expired
 
- 
getPoolSizepublic int getPoolSize()Gets the number of objects currently used- Returns:
- the number of objects currently used
 
- 
getPoolMaximumSizepublic int getPoolMaximumSize()Gets the maximum number of concurrent objects allowed- Returns:
- maximumSize the maximum number of allowed objects
 
- 
getIdprotected int getId()
- 
internalErrorOccurred
- 
setPoolMaximumSizepublic void setPoolMaximumSize(int size) Sets the maximum number of objects allowed- Parameters:
- size- the corresponding integer number
 
- 
setPoolMinimumSizepublic void setPoolMinimumSize(int size) Sets the pool minimum size- Parameters:
- size- the corresponding integer value
 
- 
getPoolUsageCountpublic int getPoolUsageCount()Gets the number of currently used objects- Returns:
- the corresponding integer value
 
- 
getPoolUsagePeakpublic int getPoolUsagePeak()Gets the peak number of objects used simultaneously this method is used for statistic reasons.- Returns:
- the corresponding integer value
 
- 
getDefaultTimeoutpublic long getDefaultTimeout()Gets the default timeout to use on checkout action if no timeout is specified. This value either comes from the server configuration or can be configured directly for this instance.- Returns:
- timeout value in milliseconds
- Since:
- 7.0
 
- 
setDefaultTimeoutpublic void setDefaultTimeout(long defaultTimeout) Sets the default timeout to use on checkout action if no timeout is specified.- Parameters:
- defaultTimeout- value in milliseconds
- Since:
- 7.0
 
- 
getSystemDefaultTimeoutprotected long getSystemDefaultTimeout()
- 
createUnlockedInstanceCreates an unlocked instance of the appropriate object and adds it to the pool.- Throws:
- Exception- if an error occurred while creating the object
- TimeoutException- if the operation is not executed within the default timeout delay.
 
- 
checkOutThis method makes a request for an unlocked object from the pool. Afterward the returned object becomes locked and cannot be used by another source unless it is checkIn.- Returns:
- an unlocked free object
- Throws:
- Exception- if an error occurred while checking out an object
- TimeoutException- if the operation is not executed within the default timeout delay.
 
- 
checkOutThis method makes a request for an unlocked object from the pool. Afterward the returned object becomes locked and cannot be used by another source unless it is checkIn. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. Timeout value must be greater than 0 to be supported.- Parameters:
- timeout- the maximum time to wait
- unit- the time unit of the timeout argument
- Returns:
- an unlocked free object
- Throws:
- Exception- if an error occurred while checking out an object
- TimeoutException- if the operation is not executed within the specified timeout delay.
- Since:
- 7.0
 
- 
checkInThis method sets the object available- Parameters:
- o- the corresponding object
 
- 
closepublic void close()This method closes one by one all the objects currently opened for this the pool
- 
resetThis will close and reinitialize the pool.- Throws:
- Exception
 
- 
schCallbackpublic void schCallback(int jobId) This method is automatically called by the KScheduler to either perform the clean up or object recycle jobs- Specified by:
- schCallbackin interface- KSchedulerClient
- Parameters:
- jobId- the job Id to determine which job will be done
 
- 
getMonitoringInfoThis method gets the PoolMonitorInfo associated with the KObject pool instance. The PoolMonitorInfo maintains the pool statistics- Returns:
- the corresponding PoolMonitorInfo instance
- See Also:
 
- 
resourceAddedNo-op hook that allows implementation instructions after resource creation.- Parameters:
- o- the corresponding object
 
- 
applyApply a non-blocking operation on each pool workers.
 
-