Class CasManager_impl

  • All Implemented Interfaces:
    CasOwner, CasManager

    public class CasManager_impl
    extends java.lang.Object
    implements CasManager
    Simple CAS Manager Implementation used in the AnalysisEngine framework. Maintains a pool of 1 CAS for each requestor. The ResourceManager points to one instantiation of this class. An instance of this class might be accessed in parallel on different threads.
    • Field Detail

      • mMetaDataList

        private final java.util.List<ProcessingResourceMetaData> mMetaDataList
        accumulates the metadata needed for shared CASes for this resource manager Starts out "empty" when this is created; is added to (but never removed). Duplicates may be in the list. Threading: This list is always accessed under the class instance lock.
      • mRequestorToCasPoolMap

        private final java.util.Map<java.lang.String,​CasPool> mRequestorToCasPoolMap
      • mCasToCasPoolMap

        private final java.util.Map<CAS,​CasPool> mCasToCasPoolMap
      • mCasToUimaContextMap

        private final java.util.Map<CAS,​UimaContext> mCasToUimaContextMap
      • mCurrentTypeSystem

        private volatile TypeSystem mCurrentTypeSystem
      • mMBeanServer

        private volatile java.lang.Object mMBeanServer
      • mMBeanNamePrefix

        private volatile java.lang.String mMBeanNamePrefix
    • Constructor Detail

      • CasManager_impl

        public CasManager_impl​(ResourceManager aResourceManager)
    • Method Detail

      • addMetaData

        public void addMetaData​(ProcessingResourceMetaData aMetaData)
        Description copied from interface: CasManager
        Called by components when they initialize.
        Specified by:
        addMetaData in interface CasManager
        Parameters:
        aMetaData - an object containing metadata for the component, including Type System, Type Priorities, and Index Definitions needed to create the CAS.
      • containsSameTypeAndIndexInfo

        private boolean containsSameTypeAndIndexInfo​(ProcessingResourceMetaData md)
        This comparison is needed to avoid throwing errors in the use case: a) the pipeline has been fully initialized, and one or more CASes have been drawn from this pool b) Another instance of an annotator using the same resource manager is initialized. In this case there is no change to the metadata, and we do not want to disturb anything.
        Parameters:
        md - the metadata to see if its in the list already
        Returns:
        true if the type system description, the type priority description, and the index collection are in the list already.
      • equalsWithNulls

        private boolean equalsWithNulls​(java.lang.Object a,
                                        java.lang.Object b)
      • getCas

        public CAS getCas​(java.lang.String aRequestorContextName)
        Description copied from interface: CasManager
        Gets an empty CAS. An AnalysisEngine may only call this method after it has first called CasManager.defineCasPool(String, int, Properties) and established a CAS Pool of size > 0. The CAS Manager maintains a separate pool for each AnalysisEngine. This method may block if the CAS pool does not contain any free instances.
        Specified by:
        getCas in interface CasManager
        Parameters:
        aRequestorContextName - the context name of the AE requesting the CAS (AnalysisEngine.getUimaContextAdmin().getQualifiedContextName()).
        Returns:
        an empty CAS
      • releaseCas

        public void releaseCas​(AbstractCas aCAS)
        Description copied from interface: CasOwner
        Releases a CAS back to its owner. After calling this method, the caller should no longer access aCAS.
        Specified by:
        releaseCas in interface CasOwner
        Parameters:
        aCAS - the CAS to release
      • defineCasPool

        public void defineCasPool​(UimaContextAdmin aRequestorContext,
                                  int aMinimumSize,
                                  java.util.Properties aPerformanceTuningSettings)
                           throws ResourceInitializationException
        Description copied from interface: CasManager
        Defines the CAS pool required by a particular AnalysisEngine. (The AnalysisEngine must contain a CAS Multiplier if it requires a CAS pool.)
        Specified by:
        defineCasPool in interface CasManager
        Parameters:
        aRequestorContext - the UimaContext of the AE that will request the CASes (AnalysisEngine.getUimaContextAdmin()).
        aMinimumSize - the minimum CAS pool size required
        aPerformanceTuningSettings - settings, including initial CAS heap size, for the AE
        Throws:
        ResourceInitializationException - if a CAS could not be created.
      • createNewCas

        public CAS createNewCas​(java.util.Properties aPerformanceTuningSettings)
                         throws ResourceInitializationException
        Description copied from interface: CasManager
        Create a new CAS using the CasDefinition stored in this CAS Manager. Note that this new CAS will not belong to any pool managed by this CAS Manager. If this method is called multiple times while the CasDefinition is constant, each new CAS will share an identical TypeSystem object.
        Specified by:
        createNewCas in interface CasManager
        Parameters:
        aPerformanceTuningSettings - settings, including initial CAS heap size, for the AE
        Returns:
        a new CAS
        Throws:
        ResourceInitializationException - if the CAS could not be created
      • getCasInterface

        public AbstractCas getCasInterface​(CAS cas,
                                           java.lang.Class<? extends AbstractCas> requiredInterface)
        Gets a specified interface to a CAS.
        Specified by:
        getCasInterface in interface CasManager
        Parameters:
        cas - The CAS
        requiredInterface - interface to get. Currently must be one of CAS or JCas.
        Returns:
        the CAS Interface
      • getCasInterfaceStatic

        public static <T extends AbstractCas> T getCasInterfaceStatic​(CAS cas,
                                                                      java.lang.Class<T> requiredInterface)
        Gets a specified interface to a CAS.
        Type Parameters:
        T - the particular interface
        Parameters:
        cas - The CAS
        requiredInterface - interface to get. Currently must be one of CAS or JCas.
        Returns:
        -
      • setJmxInfo

        public void setJmxInfo​(java.lang.Object aMBeanServer,
                               java.lang.String aRootMBeanName)
        Description copied from interface: CasManager
        Configures this CAS Manager so it can register an MBean for each of its CAS pools.
        Specified by:
        setJmxInfo in interface CasManager
        Parameters:
        aMBeanServer - the JMX MBean Server to register MBeans with. If null, the platform MBeanServer (Java 1.5+ only) will be used.
        aRootMBeanName - unique MBean name for the root component that owns this CAS Manager. The names of the CAS Pool MBeans will be formed by appending ,casPoolContextName=[contextName] to the root component name, where [contextName] is the requestorContextName for the CasPool.
      • getCasToCasPoolMap

        protected java.util.Map<CAS,​CasPool> getCasToCasPoolMap()
      • populateCasToCasPoolMap

        protected void populateCasToCasPoolMap​(CasPool aCasPool)
      • populateCasToCasPoolAndUimaContextMaps

        protected void populateCasToCasPoolAndUimaContextMaps​(CasPool aCasPool,
                                                              UimaContext aUimaContext)
      • registerCasPoolMBean

        protected void registerCasPoolMBean​(java.lang.String aRequestorContextName,
                                            CasPool pool)
        Registers an MBean for the given CasPool. Never called unless pool is new
        Parameters:
        aRequestorContextName - context name that identifies this CasPool
        pool - the CasPool
      • getCasPoolSize

        protected int getCasPoolSize​(java.lang.String aRequestorContextName,
                                     int aMinimumSize)
        Determines the size to use for a particular CAS Pool. This can be overridden by subclasses to specify custom pool sizes.
        Parameters:
        aRequestorContextName - the context name of the AE that will request the CASes (AnalysisEngine.getUimaContextAdmin().getQualifiedContextName()).
        aMinimumSize - the minimum CAS pool size required
        Returns:
        the size of the CAS pool to create for the specified AE
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable