Class CPECasPool


  • public class CPECasPool
    extends java.lang.Object
    Implements object pooling mechanism to limit number of CAS instances. Cas'es are checked out, used and checked back in when done.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.LinkedList checkedOutInstances
      The checked out instances.
      private java.util.Vector mAllInstances
      The m all instances.
      private java.util.Vector mFreeInstances
      The m free instances.
      private int mNumInstances
      The m num instances.
    • Constructor Summary

      Constructors 
      Constructor Description
      CPECasPool​(int aNumInstances, CasManager aCasManager)
      Initialize the pool.
      CPECasPool​(int aNumInstances, CasManager aCasManager, java.util.Properties aPerformanceTuningSettings)
      Initialize the pool.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void fillPool​(CasManager aCasManager, java.util.Properties aPerformanceTuningSettings)
      Fills the pool with initialized instances of CAS.
      CAS getCas()
      Checks out a CAS from the pool.
      CAS getCas​(long aTimeout)
      Returns a Cas instance from the pool.
      CAS getCheckedOutCas​(int aIndex)
      Returns a CAS found in a given position in the list.
      int getCheckedOutCasCount()
      Returns number of CAS'es that have been checked out from 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mAllInstances

        private java.util.Vector mAllInstances
        The m all instances.
      • mFreeInstances

        private java.util.Vector mFreeInstances
        The m free instances.
      • checkedOutInstances

        private java.util.LinkedList checkedOutInstances
        The checked out instances.
      • mNumInstances

        private final int mNumInstances
        The m num instances.
    • Method Detail

      • fillPool

        protected void fillPool​(CasManager aCasManager,
                                java.util.Properties aPerformanceTuningSettings)
                         throws ResourceInitializationException
        Fills the pool with initialized instances of CAS.
        Parameters:
        aCasManager - - definition (type system, indexes, etc.) of CASes to create
        aPerformanceTuningSettings - the a performance tuning settings
        Throws:
        ResourceInitializationException - -
      • getCas

        public CAS getCas​(long aTimeout)
        Returns a Cas instance from the pool. This routine waits for a free instance of Cas a given amount of time. If free instance is not available this routine returns null.
        Parameters:
        aTimeout - - max amount of time in millis to wait for CAS instance
        Returns:
        - CAS instance, or null on timeout
      • getCas

        public CAS getCas()
        Checks out a CAS from the pool.
        Returns:
        a CAS instance. Returns null if none are available (in which case the client may Object.wait() on this object in order to be notified when an instance becomes available).
      • releaseCas

        public void releaseCas​(CAS aCas)
        Checks in a CAS to the pool. This automatically calls the CAS.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.
        Parameters:
        aCas - the CAS to release
      • getCheckedOutCasCount

        public int getCheckedOutCasCount()
        Returns number of CAS'es that have been checked out from pool.
        Returns:
        - number of CAS'es being processed
      • getCheckedOutCas

        public CAS getCheckedOutCas​(int aIndex)
        Returns a CAS found in a given position in the list.
        Parameters:
        aIndex - - position of the CAS in the list
        Returns:
        CAS - reference to a CAS
      • 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