Class CPEFactory
- java.lang.Object
-
- org.apache.uima.collection.impl.cpm.container.CPEFactory
-
public class CPEFactory extends java.lang.Object
Component responsible for generating objects representing cpe descriptor configuration. Provides various ways to instantiate object model representing cpe configuration. In the simplest form it ingests an xml file (cpe descriptor), parses it and creates an object for every element in the xml file.Using objects representing configuration, this component creates CollectionReader CasInitializer, Analysis Engines, and Cas Consumers.
In addition to creating object, this component provides read/write access to the object model allowing for dynamic or programmatic modifications. It facilitates plugging in existing CollectionReaders and CasProcessors.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.HashMap
casProcessorConfigMap
The cas processor config map.private CpeDescription
cpeDescriptor
The cpe descriptor.static java.lang.String
CPM_HOME
The Constant CPM_HOME.private java.util.HashMap
cpMap
The cp map.private java.lang.String
DEFAULT_CONFIG_FILE
The default config file.private boolean
defaultConfig
The default config.private boolean
firstTime
The first time.private boolean
initialized
The initialized.private int
processorCount
The processor count.private UimaContextAdmin
uimaContext
The uima context.
-
Constructor Summary
Constructors Constructor Description CPEFactory(CpeDescription aDescriptor, ResourceManager aResourceManager)
Create a new CPEFactory for a CpeDescription that's already been parsed.CPEFactory(ResourceManager aResourceManager)
Create a new CPEFactory on which we will later call parse(String) to parse a CPE descriptor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private CpeCasProcessor
addCasProcessor(java.lang.String aCasProcessorName)
Adds new Cas Processor with given name.void
addCasProcessor(CasProcessor aCasProcessor)
Appends given Cas Processor to the list of CasProcessors.void
addCollectionReader(BaseCollectionReader collectionReader)
Adds the collection reader.private void
checkForErrors()
Checks if cpe description has been created.private void
copyCasProcessor(CpeCasProcessor aProcDesc, java.lang.String aName)
Copy cas processor.private NameValuePair
findMatchingNameValuePair(ConfigurationParameterSettings aCps, java.lang.String aParamName)
Find a parameter with a given name in the in-memory component descriptor.CasProcessor[]
getCasProcessors()
Returns an array of Cas Processors instantiated from the cpe descriptor.BaseCollectionReader
getCollectionReader()
Returns Collection Reader instantiated from configuration in the cpe descriptor.CpeConfiguration
getCPEConfig()
Returns an object containing global CPE configuration including: Number of documents to process Checkpoint configuration id of the document begin processing .CpeDescription
getCpeDescriptor()
Returns Cpe Descriptor.java.lang.String
getDescriptor(java.util.List aList)
Gets the descriptor.java.net.URL
getDescriptorURL(CpeCasProcessor aCasProcessorCfg)
Returns a descriptor path associated with Cas Processor.int
getProcessingUnitThreadCount()
Returns number of processing threads (Processing Units).ResourceManager
getResourceManager()
Gets the ResourceManager that all components of this CPE should share.ResourceSpecifier
getSpecifier(java.net.URL aDescriptorUrl)
Instantiates a ResourceSpecifier from a given URL.boolean
isDefault()
Checks if is default.boolean
isDefinitionInstanceOf(java.lang.Class aResourceClass, ResourceSpecifier resourceSpecifier, java.lang.String aDescriptor)
Check if a class has appropriate type.private boolean
isUniqueName(java.lang.String aName)
Checks uniqueness of a given name.private boolean
overrideParameterIfExists(ResourceSpecifier aResourceSpecifier, NameValuePair aCPE_nvp, java.lang.String aComponentName)
Override component's parameters.private void
overrideParameterSettings(ResourceSpecifier aResourceSpecifier, CasProcessorConfigurationParameterSettings aCpe_cps, java.lang.String aComponentName)
Replace component's parameters.void
parse()
Creates an object representation from default cpe descriptor.void
parse(java.io.InputStream aDescriptorStream)
Creates an object representation for configuration in a given stream.void
parse(java.lang.String aDescriptor)
Creates an object representation for configuration in a given cpe descriptor file.CasProcessor
produceCasDataConsumer(java.lang.Class aResourceClass, ResourceSpecifier aSpecifier, java.util.Map aAdditionalParams)
Instantiates CasData Consumer from a given class.private java.lang.Object
produceInitializer(ResourceSpecifier aSpecifier, java.util.Map aAdditionalParams)
Instantiates Cas Initializer from a given class.private CasProcessor
produceIntegratedCasProcessor(CpeCasProcessor aCasProcessorType)
Instantiates integrated Cas Processor.private CasProcessor
produceLocalCasProcessor(CpeCasProcessor aCasProcessorCfg)
Instantiates a local (managed) Cas Processor.private CasProcessor
produceRemoteCasProcessor(CpeCasProcessor aCasProcessorType)
Instantiates remote Cas Processor.private void
replaceArray(java.lang.String aType, boolean aMandatoryParam, ConfigurationParameterSettings aCps, NameValuePair aCPE_nvp, java.lang.String aComponentName)
Replace array values found in the component's descriptor with values found in the CPE descriptor.private void
replacePrimitive(java.lang.String aType, boolean aMandatoryParam, ConfigurationParameterSettings aCps, NameValuePair aCPE_nvp, java.lang.String aComponentName)
Replace a primitive value of a given parameter with a value defined in the CPE descriptor.private void
setCpeDescriptor(CpeDescription description)
Assigns Cpe configuration to use.private void
verifyDeploymentParams(java.lang.String aCasProcessorName, CasProcessorDeploymentParams aDepParams)
Checks for existance of two parameters required to launch remote Cas Processor vnsHost and vnsPort.
-
-
-
Field Detail
-
CPM_HOME
public static final java.lang.String CPM_HOME
The Constant CPM_HOME.- See Also:
- Constant Field Values
-
processorCount
private int processorCount
The processor count.
-
DEFAULT_CONFIG_FILE
private java.lang.String DEFAULT_CONFIG_FILE
The default config file.
-
defaultConfig
private boolean defaultConfig
The default config.
-
casProcessorConfigMap
public java.util.HashMap casProcessorConfigMap
The cas processor config map.
-
cpeDescriptor
private CpeDescription cpeDescriptor
The cpe descriptor.
-
initialized
private boolean initialized
The initialized.
-
uimaContext
private UimaContextAdmin uimaContext
The uima context.
-
firstTime
private boolean firstTime
The first time.
-
cpMap
private java.util.HashMap cpMap
The cp map.
-
-
Constructor Detail
-
CPEFactory
public CPEFactory(ResourceManager aResourceManager)
Create a new CPEFactory on which we will later call parse(String) to parse a CPE descriptor.- Parameters:
aResourceManager
- the a resource manager
-
CPEFactory
public CPEFactory(CpeDescription aDescriptor, ResourceManager aResourceManager) throws ResourceInitializationException
Create a new CPEFactory for a CpeDescription that's already been parsed.- Parameters:
aDescriptor
- the a descriptoraResourceManager
- the resource manager that all components of this CPE will share If null, a new ResourceManager will be created.- Throws:
ResourceInitializationException
- the resource initialization exception
-
-
Method Detail
-
parse
public void parse(java.lang.String aDescriptor) throws java.lang.InstantiationException
Creates an object representation for configuration in a given cpe descriptor file.- Parameters:
aDescriptor
- - path to the descriptor- Throws:
java.lang.InstantiationException
- -
-
parse
public void parse(java.io.InputStream aDescriptorStream) throws java.lang.InstantiationException
Creates an object representation for configuration in a given stream.- Parameters:
aDescriptorStream
- - stream containing cpe description- Throws:
java.lang.InstantiationException
- -
-
parse
public void parse()
Creates an object representation from default cpe descriptor.- Throws:
UIMARuntimeException
- wraps Exception
-
checkForErrors
private void checkForErrors() throws ResourceConfigurationException
Checks if cpe description has been created.- Throws:
ResourceConfigurationException
- the resource configuration exception
-
getCollectionReader
public BaseCollectionReader getCollectionReader() throws ResourceConfigurationException
Returns Collection Reader instantiated from configuration in the cpe descriptor. It also creates and intializes the Cas Initializer if one is defined and associates it with the CollectionReader.- Returns:
- CollectionReader instance
- Throws:
ResourceConfigurationException
- the resource configuration exception
-
getCasProcessors
public CasProcessor[] getCasProcessors() throws ResourceConfigurationException
Returns an array of Cas Processors instantiated from the cpe descriptor.- Returns:
- - array of CasProcessor instances
- Throws:
ResourceConfigurationException
- -
-
isDefinitionInstanceOf
public boolean isDefinitionInstanceOf(java.lang.Class aResourceClass, ResourceSpecifier resourceSpecifier, java.lang.String aDescriptor) throws ResourceConfigurationException
Check if a class has appropriate type.- Parameters:
aResourceClass
- - class to checkresourceSpecifier
- - specifier containing expected typeaDescriptor
- - descriptor name- Returns:
- true - if class matches type
- Throws:
ResourceConfigurationException
- -
-
produceCasDataConsumer
public CasProcessor produceCasDataConsumer(java.lang.Class aResourceClass, ResourceSpecifier aSpecifier, java.util.Map aAdditionalParams) throws ResourceInitializationException
Instantiates CasData Consumer from a given class.- Parameters:
aResourceClass
- - CasDataConsumer classaSpecifier
- - specifieraAdditionalParams
- - parameters used to initialize CasDataConsumer- Returns:
- - instance of CasProcessor
- Throws:
ResourceInitializationException
- -
-
produceInitializer
private java.lang.Object produceInitializer(ResourceSpecifier aSpecifier, java.util.Map aAdditionalParams) throws ResourceInitializationException
Instantiates Cas Initializer from a given class. It return- Parameters:
aSpecifier
- - configuration for Cas InitializeraAdditionalParams
- - parameters to initialize Cas Initializer- Returns:
- instance of CasDataInitializer or CasInitializer
- Throws:
ResourceInitializationException
- -
-
getDescriptorURL
public java.net.URL getDescriptorURL(CpeCasProcessor aCasProcessorCfg) throws ResourceConfigurationException
Returns a descriptor path associated with Cas Processor.- Parameters:
aCasProcessorCfg
- - Cas Processor configuration- Returns:
- - Descriptor path
- Throws:
ResourceConfigurationException
- -
-
getSpecifier
public ResourceSpecifier getSpecifier(java.net.URL aDescriptorUrl) throws java.lang.Exception
Instantiates a ResourceSpecifier from a given URL.- Parameters:
aDescriptorUrl
- - URL of descriptor- Returns:
- - ResourceSpecifier
- Throws:
java.lang.Exception
- -
-
produceLocalCasProcessor
private CasProcessor produceLocalCasProcessor(CpeCasProcessor aCasProcessorCfg) throws ResourceConfigurationException
Instantiates a local (managed) Cas Processor.- Parameters:
aCasProcessorCfg
- - Cas Processor configuration- Returns:
- - Local CasProcessor
- Throws:
ResourceConfigurationException
- -
-
findMatchingNameValuePair
private NameValuePair findMatchingNameValuePair(ConfigurationParameterSettings aCps, java.lang.String aParamName) throws java.lang.Exception
Find a parameter with a given name in the in-memory component descriptor.- Parameters:
aCps
- - parameter settings from the component's descriptoraParamName
- - name of the parameter to look for- Returns:
- - parameter as
NameValuePair
instance. If not found, returns null. - Throws:
java.lang.Exception
- - any error
-
replacePrimitive
private void replacePrimitive(java.lang.String aType, boolean aMandatoryParam, ConfigurationParameterSettings aCps, NameValuePair aCPE_nvp, java.lang.String aComponentName) throws java.lang.Exception
Replace a primitive value of a given parameter with a value defined in the CPE descriptor.- Parameters:
aType
- - type of the primitive value ( String, Integer, Boolean, or Float)aMandatoryParam
- the a mandatory paramaCps
- - parameter settings from the component's descriptoraCPE_nvp
- - parameter containing array of values to replace values in the component's descriptoraComponentName
- the a component name- Throws:
java.lang.Exception
- -
-
replaceArray
private void replaceArray(java.lang.String aType, boolean aMandatoryParam, ConfigurationParameterSettings aCps, NameValuePair aCPE_nvp, java.lang.String aComponentName) throws java.lang.Exception
Replace array values found in the component's descriptor with values found in the CPE descriptor.- Parameters:
aType
- - primitive type of the array (Sting, Integer, Float, or Boolean)aMandatoryParam
- the a mandatory paramaCps
- - parameter settings from the component's descriptoraCPE_nvp
- - parameter containing array of values to replace values in the component's descriptoraComponentName
- the a component name- Throws:
java.lang.Exception
- - any error
-
overrideParameterIfExists
private boolean overrideParameterIfExists(ResourceSpecifier aResourceSpecifier, NameValuePair aCPE_nvp, java.lang.String aComponentName) throws java.lang.Exception
Override component's parameters. This overridde effects the in-memory settings. The actual component's descriptor will not be changed.- Parameters:
aResourceSpecifier
- - in-memory descriptor of the componentaCPE_nvp
- - parameter represented as name-value pair. If the name of the parameter is found in the component's descriptor its value will be changed.aComponentName
- the a component name- Returns:
- true, if successful
- Throws:
java.lang.Exception
- - error during processing
-
overrideParameterSettings
private void overrideParameterSettings(ResourceSpecifier aResourceSpecifier, CasProcessorConfigurationParameterSettings aCpe_cps, java.lang.String aComponentName) throws java.lang.Exception
Replace component's parameters. Its parameter values will be changed to match those defined in the CPE descriptor.- Parameters:
aResourceSpecifier
- - component's descriptor containing parameters to overrideaCpe_cps
- the a cpe cpsaComponentName
- the a component name- Throws:
java.lang.Exception
- - failure during processing
-
produceIntegratedCasProcessor
private CasProcessor produceIntegratedCasProcessor(CpeCasProcessor aCasProcessorType) throws ResourceConfigurationException
Instantiates integrated Cas Processor.- Parameters:
aCasProcessorType
- the a cas processor type- Returns:
- - Integrated CasProcessor
- Throws:
ResourceConfigurationException
- -
-
produceRemoteCasProcessor
private CasProcessor produceRemoteCasProcessor(CpeCasProcessor aCasProcessorType) throws ResourceConfigurationException
Instantiates remote Cas Processor.- Parameters:
aCasProcessorType
- the a cas processor type- Returns:
- - Remote CasProcessor
- Throws:
ResourceConfigurationException
- -
-
getCPEConfig
public CpeConfiguration getCPEConfig() throws java.lang.InstantiationException
Returns an object containing global CPE configuration including:- Number of documents to process
- Checkpoint configuration
- id of the document begin processing
- Returns:
- Global CPE Configuration
- Throws:
java.lang.InstantiationException
- the instantiation exception
-
getProcessingUnitThreadCount
public int getProcessingUnitThreadCount() throws ResourceConfigurationException
Returns number of processing threads (Processing Units).- Returns:
- Number of processing threads
- Throws:
ResourceConfigurationException
- -
-
isDefault
public boolean isDefault()
Checks if is default.- Returns:
- true if the configuration is the default
-
getCpeDescriptor
public CpeDescription getCpeDescriptor()
Returns Cpe Descriptor.- Returns:
- the Cpe Descriptor
-
setCpeDescriptor
private void setCpeDescriptor(CpeDescription description)
Assigns Cpe configuration to use.- Parameters:
description
- the new cpe descriptor
-
isUniqueName
private boolean isUniqueName(java.lang.String aName) throws CpeDescriptorException
Checks uniqueness of a given name. This name is compared against all Cas Processors already defined. Cas Processor names must be unique.- Parameters:
aName
- - name to check- Returns:
- - true if name is unique, false otherwise
- Throws:
CpeDescriptorException
- the cpe descriptor exception
-
verifyDeploymentParams
private void verifyDeploymentParams(java.lang.String aCasProcessorName, CasProcessorDeploymentParams aDepParams) throws ResourceConfigurationException
Checks for existance of two parameters required to launch remote Cas Processor vnsHost and vnsPort. If not found the remote CasProcessor can not be located since the VNS is not specified. In this case an exception is thrown.- Parameters:
aCasProcessorName
- the a cas processor nameaDepParams
- the a dep params- Throws:
ResourceConfigurationException
- -
-
addCasProcessor
public void addCasProcessor(CasProcessor aCasProcessor) throws ResourceConfigurationException
Appends given Cas Processor to the list of CasProcessors.- Parameters:
aCasProcessor
- - CasProcessor to add- Throws:
ResourceConfigurationException
- the resource configuration exception
-
addCasProcessor
private CpeCasProcessor addCasProcessor(java.lang.String aCasProcessorName) throws ResourceConfigurationException
Adds new Cas Processor with given name.- Parameters:
aCasProcessorName
- - name of the CasProcessor to add- Returns:
- -
- Throws:
ResourceConfigurationException
- the resource configuration exception
-
getDescriptor
public java.lang.String getDescriptor(java.util.List aList) throws ResourceConfigurationException
Gets the descriptor.- Parameters:
aList
- the a list- Returns:
- the cpe descriptor constructed from the list
- Throws:
ResourceConfigurationException
- -
-
copyCasProcessor
private void copyCasProcessor(CpeCasProcessor aProcDesc, java.lang.String aName)
Copy cas processor.- Parameters:
aProcDesc
- the a proc descaName
- the a name
-
addCollectionReader
public void addCollectionReader(BaseCollectionReader collectionReader)
Adds the collection reader.- Parameters:
collectionReader
- - collection reader to use by the CPM
-
getResourceManager
public ResourceManager getResourceManager()
Gets the ResourceManager that all components of this CPE should share.- Returns:
- the resource manager
-
-