Class CasPool
CAS
instances. This is useful for multithreaded
applications, where there is a need for multiple CASes to be processed simultaneously. Because
CAS creation is expensive, it is a good idea to create a pool of reusable CAS instances at
initialization time, rather than creating a new CAS each time one is needed.
Clients check-out CAS instances from the pool using the getCas()
method and check-in CAS
instances using the releaseCas(CAS)
method.
Design considerations: The pool favors reuse of CASes is some arbitrary preferred priority order. For example if there is a pool of 10 CASes, but only 2 are being check-out at any given time, the same 2 CASes will be used (as opposed to a FIFO approach where all the CASes would be cycled through). If more threads request CASes from the pool than are available, the pool (optionally) puts requesting threads into a wait state. When CASes become available, the longest-waiting thread gets the CAS; this approach prevents starvation behavior (where some threads get all the CASes and others get none).
-
Constructor Summary
ConstructorDescriptionCasPool
(int aNumInstances, Collection<? extends ProcessingResourceMetaData> aCollectionOfProcessingResourceMetaData, Properties aPerformanceTuningSettings, ResourceManager aResourceManager) Creates a new CasPoolCasPool
(int aNumInstances, AnalysisEngine aAnalysisEngine) Creates a new CasPoolCasPool
(int aNumInstances, CasDefinition aCasDefinition, Properties aPerformanceTuningSettings) Creates a new CasPool.CasPool
(int aNumInstances, CasManager aCasManager, Properties aPerformanceTuningSettings) Creates a new CasPoolCasPool
(int aNumInstances, ProcessingResourceMetaData aMetaData) Creates a new CasPoolCasPool
(int aNumInstances, ProcessingResourceMetaData aMetaData, ResourceManager aResourceManager) Creates a new CasPool -
Method Summary
Modifier and TypeMethodDescriptiongetCas()
Checks out a CAS from the pool.getCas
(long aTimeout) Checks out a CAS from the pool.int
Gets the number of CASes currently available in this pool.int
getSize()
Gets the size of this pool (the total number of CAS instances that it can hold).void
releaseCas
(CAS aCas) Checks in a CAS to the pool.
-
Constructor Details
-
CasPool
public CasPool(int aNumInstances, Collection<? extends ProcessingResourceMetaData> aCollectionOfProcessingResourceMetaData, Properties aPerformanceTuningSettings, ResourceManager aResourceManager) throws ResourceInitializationException Creates a new CasPool- Parameters:
aNumInstances
- the number of CAS instances in the poolaCollectionOfProcessingResourceMetaData
- a collection ofProcessingResourceMetaData
objects.aPerformanceTuningSettings
- Properties object containing framework performance tuning settings using key names defined onUIMAFramework
interfaceaResourceManager
- the resource manager to use to resolve import declarations within the metadata- Throws:
ResourceInitializationException
- if the CAS instances could not be created
-
CasPool
public CasPool(int aNumInstances, AnalysisEngine aAnalysisEngine) throws ResourceInitializationException Creates a new CasPool- Parameters:
aNumInstances
- the number of CAS instances in the poolaAnalysisEngine
- the analysis engine that will create the CAS instances and which will later be used to process them- Throws:
ResourceInitializationException
- if the CAS instances could not be created
-
CasPool
public CasPool(int aNumInstances, ProcessingResourceMetaData aMetaData) throws ResourceInitializationException Creates a new CasPool- Parameters:
aNumInstances
- the number of CAS instances in the poolaMetaData
- metadata that includes the type system for the CAS- Throws:
ResourceInitializationException
- if the CAS instances could not be created
-
CasPool
public CasPool(int aNumInstances, ProcessingResourceMetaData aMetaData, ResourceManager aResourceManager) throws ResourceInitializationException Creates a new CasPool- Parameters:
aNumInstances
- the number of CAS instances in the poolaMetaData
- metadata that includes the type system for the CASaResourceManager
- Resource Manager- Throws:
ResourceInitializationException
- if the CAS instances could not be created
-
CasPool
public CasPool(int aNumInstances, CasDefinition aCasDefinition, Properties aPerformanceTuningSettings) throws ResourceInitializationException Creates a new CasPool. TODO: do we need this method AND the one that takes a CasManager?- Parameters:
aNumInstances
- the number of CAS instances in the poolaCasDefinition
- the Cas definition, which includes the type system, type priorities, and indexes for the CASes in the pool.aPerformanceTuningSettings
- Properties object containing framework performance tuning settings using key names defined onUIMAFramework
interface- Throws:
ResourceInitializationException
- -
-
CasPool
public CasPool(int aNumInstances, CasManager aCasManager, Properties aPerformanceTuningSettings) throws ResourceInitializationException Creates a new CasPool- Parameters:
aNumInstances
- the number of CAS instances in the poolaCasManager
- CAS Manager that will be used to create the CAS. The CAS Manager holds the CAS Definition. Also all CASes created from the same CAS Manager will share identical TypeSystem objects.aPerformanceTuningSettings
- Properties object containing framework performance tuning settings using key names defined onUIMAFramework
interface- Throws:
ResourceInitializationException
- -
-
-
Method Details
-
getCas
Checks out a CAS from the pool.- Returns:
- a CAS instance. Returns
null
if none are available (in which case the client mayObject.wait()
on this object in order to be notified when an instance becomes available).
-
getCas
Checks out a CAS from the pool. If none is currently available, wait for the specified amount of time for one to be checked in.- Parameters:
aTimeout
- the time to wait in milliseconds. A value of <=0 will wait forever.- Returns:
- a CAS instance. Returns
null
if none are available within the specified timeout period.
-
releaseCas
Checks in a CAS to the pool. This automatically calls theCAS.reset()
method, to ensure that when the CAS is later retrieved from the pool it will be ready to use. Also notifies other Threads that may be waiting for an instance to become available. Synchronized on the CAS to avoid the unnatural case where multiple threads attempt to return the same CAS to the pool at the same time.- Parameters:
aCas
- the Cas to release
-
getSize
public int getSize()Gets the size of this pool (the total number of CAS instances that it can hold).- Returns:
- the size of this pool
-
getNumAvailable
public int getNumAvailable()Gets the number of CASes currently available in this pool.- Returns:
- the numberof available CASes
-
getAllInstances
-
getFreeInstances
-