Package org.apache.uima.resource.impl
Class ResourceManager_impl
java.lang.Object
org.apache.uima.resource.impl.ResourceManager_impl
- All Implemented Interfaces:
ResourceManager
- Direct Known Subclasses:
ResourceManagerPearWrapper_impl
Reference implementation of
ResourceManager
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object
a monitor lock for synchronizing get/set of casManager refCache of imported descriptors, so that parsed objects can be reused if the same URL is imported more than once.protected static final String
resource bundle for log messagesprotected CasManager
CasManager - manages creation and pooling of CASes.Internal map from resource names (declared in resource declaration XML) to Class objects.protected final Map<String,
ResourceManager_impl.ResourceRegistration> Internal map from resource names (declared in resource declaration XML) to ResourceRegistration objects.Map from String keys to Class objects.Map from ParameterizedResourceKey to Resource objects.private final RelativePathResolver
Object used for resolving relative paths.Map from qualified key names (declared in resource dependency XML) to Resource objects.private UIMAClassLoader
UIMA extension ClassLoader. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newResourceManager_impl
.ResourceManager_impl
(ClassLoader aClassLoader) Creates a newResourceManager_impl
with a custom ClassLoader to use for locating resources.ResourceManager_impl
(Map<String, Object> resourceMap, Map<String, ResourceManager_impl.ResourceRegistration> internalResourceRegistrationMap, Map<String, Class<?>> parameterizedResourceImplClassMap, Map<String, Class<?>> internalParameterizedResourceImplClassMap, Map<List<Object>, Object> parameterizedResourceInstanceMap) -
Method Summary
Modifier and TypeMethodDescriptionGets the CasManager, which manages the creation and pooling of CASes.Gets the data path used to resolve relative paths.Returns the UIMA extension class loader.Gets a cache of imported descriptors, so that the parsed objects can be reused if the same URL is imported more than once.protected RelativePathResolver
getResource
(String aName) Gets the Resource that has been registered under the specified name.getResource
(String aName, String[] aParams) Gets an instance of a parameterized Resource.getResourceAsStream
(String aKey) Retrieves an InputStream for reading from the named resource.getResourceAsStream
(String aKey, String[] aParams) Retrieves an InputStream for reading from the named resource.private InputStream
getResourceAsStreamCommon
(Object resource) private URL
getResourceAsStreamCommonUrl
(Object resource) getResourceClass
(String aName) Gets the Class of the Resource that will be returned by a call toResourceManager.getResource(String)
orResourceManager.getResource(String,String[])
.getResourceURL
(String aKey) Retrieves the URL to the named resource.getResourceURL
(String aKey, String[] aParams) Retrieves the URL to the named resource.void
initializeExternalResources
(ResourceManagerConfiguration aConfiguration, String aQualifiedContextName, Map<String, Object> aAdditionalParams) Initializes all external resources declared in a ResourceCreationSpecifier.private void
registerResource
(String aName, ExternalResourceDescription aResourceDescription, String aDefiningContext, Map<String, Object> aResourceInitParams) Instantiates a resource and inserts it in the internal resource map.void
resolveAndValidateResourceDependencies
(ExternalResourceDependency[] aDependencies, String aQualifiedContextName) Resolves a component's external resource dependencies using this resource manager.resolveRelativePath
(String aRelativePath) Attempts to resolve a relative path to an absolute path using the same mechanism that the ResourceManager uses to find resources -- a lookup in the datapath followed by a lookup in the classpath.void
setCasManager
(CasManager aCasManager) Sets the CasManager, which manages the creation and pooling of CASes.void
setDataPath
(String aPath) Sets the data path used to resolve relative paths.void
setExtensionClassPath
(ClassLoader parent, String classpath, boolean resolveResource) Sets the classpath for the UIMA extension ClassLoader and specifies if the extension ClassLoader should also be used to resolve resources.void
setExtensionClassPath
(String classpath, boolean resolveResource) /**void
setExtensionClassPath
(UIMAClassLoader uimaCL, boolean resolveResource) Support reusing UIMA Class Loader instances to speed up things including the Component Description Editor when obtaining info from CustomResourceSpecifiers https://issues.apache.org/jira/browse/UIMA-1722
-
Field Details
-
LOG_RESOURCE_BUNDLE
resource bundle for log messages- See Also:
-
EMPTY_RESOURCE_CLASS
-
casManagerMonitor
a monitor lock for synchronizing get/set of casManager ref -
mRelativePathResolver
Object used for resolving relative paths. This is built by parsing the data path. -
mResourceMap
Map from qualified key names (declared in resource dependency XML) to Resource objects. Can't be concurrentMap because it (currently) depends on storing nulls -
mInternalResourceRegistrationMap
protected final Map<String,ResourceManager_impl.ResourceRegistration> mInternalResourceRegistrationMapInternal map from resource names (declared in resource declaration XML) to ResourceRegistration objects. Used during initialization only. -
mParameterizedResourceImplClassMap
Map from String keys to Class objects. For ParameterizedResources only, stores the implementation class corresponding to each resource name. -
mInternalParameterizedResourceImplClassMap
Internal map from resource names (declared in resource declaration XML) to Class objects. Used internally during resource initialization. -
mParameterizedResourceInstanceMap
Map from ParameterizedResourceKey to Resource objects. For ParameterizedResources only, stores the DataResources that have already been encountered, and the Resources that have been instantiated therefrom. -
uimaCL
UIMA extension ClassLoader. ClassLoader is created if an extension classpath is specified at the ResourceManager volatile might be better than synch sets/gets -
mCasManager
CasManager - manages creation and pooling of CASes. -
importCache
Cache of imported descriptors, so that parsed objects can be reused if the same URL is imported more than once. All callers of this synchronize on the importCache object before doing a get ... put sequence Use Case where synchronization is needed: running multiple instances on multiple threads, sharing a common resource manager, the initialization that merges typePriorities happens lazily, when using Cas Multipliers, and occurs when the first getCas call happens on a thread. Although these calls are synchronized among themselves, any other use of this map that might occur simultaneously is not.
-
-
Constructor Details
-
ResourceManager_impl
public ResourceManager_impl()Creates a newResourceManager_impl
. -
ResourceManager_impl
Creates a newResourceManager_impl
with a custom ClassLoader to use for locating resources.- Parameters:
aClassLoader
- -
-
ResourceManager_impl
public ResourceManager_impl(Map<String, Object> resourceMap, Map<String, ResourceManager_impl.ResourceRegistration> internalResourceRegistrationMap, Map<String, Class<?>> parameterizedResourceImplClassMap, Map<String, Class<?>> internalParameterizedResourceImplClassMap, Map<List<Object>, Object> parameterizedResourceInstanceMap)
-
-
Method Details
-
setExtensionClassPath
Support reusing UIMA Class Loader instances to speed up things including the Component Description Editor when obtaining info from CustomResourceSpecifiers https://issues.apache.org/jira/browse/UIMA-1722- Parameters:
uimaCL
- -resolveResource
- -
-
setExtensionClassPath
public void setExtensionClassPath(String classpath, boolean resolveResource) throws MalformedURLException /**- Specified by:
setExtensionClassPath
in interfaceResourceManager
- Parameters:
classpath
- extension ClassLoader classpathresolveResource
- if true ClassLoad resolves resources- Throws:
MalformedURLException
- if a malformed URL has occurred in the classpath string.- See Also:
-
setExtensionClassPath
public void setExtensionClassPath(ClassLoader parent, String classpath, boolean resolveResource) throws MalformedURLException Description copied from interface:ResourceManager
Sets the classpath for the UIMA extension ClassLoader and specifies if the extension ClassLoader should also be used to resolve resources. Also allows a parent ClassLoader to be specified.- Specified by:
setExtensionClassPath
in interfaceResourceManager
- Parameters:
parent
- parent ClassLoader for the extension ClassLoaderclasspath
- extension ClassLoader classpathresolveResource
- if true ClassLoad resolves resources- Throws:
MalformedURLException
- if a malformed URL has occurred in the classpath string.- See Also:
-
getExtensionClassLoader
Description copied from interface:ResourceManager
Returns the UIMA extension class loader.- Specified by:
getExtensionClassLoader
in interfaceResourceManager
- Returns:
- ClassLoader - returns the UIMA extension class loader of null if it is not available.
- See Also:
-
getDataPath
Description copied from interface:ResourceManager
Gets the data path used to resolve relative paths. More than one directory may be specified by separating them with the Systempath.separator
character (; on windows, : on UNIX).- Specified by:
getDataPath
in interfaceResourceManager
- Returns:
- the data path
- See Also:
-
setDataPath
Description copied from interface:ResourceManager
Sets the data path used to resolve relative paths. More than one directory may be specified by separating them with the Systempath.separator
character (; on windows, : on UNIX). The elements of this path may be URLs or File paths.- Specified by:
setDataPath
in interfaceResourceManager
- Parameters:
aPath
- the data path- Throws:
MalformedURLException
- if an element of the path is neither a valid URL or a valid file path- See Also:
-
resolveRelativePath
Description copied from interface:ResourceManager
Attempts to resolve a relative path to an absolute path using the same mechanism that the ResourceManager uses to find resources -- a lookup in the datapath followed by a lookup in the classpath.- Specified by:
resolveRelativePath
in interfaceResourceManager
- Parameters:
aRelativePath
- a relative URL or file path- Returns:
- the absolute URL of an actual file in the datapath or classpath, null if no file
matching
aRelativePath
is found. - Throws:
MalformedURLException
- if the path cannot be converted to a URL
-
getResource
Description copied from interface:ResourceManager
Gets the Resource that has been registered under the specified name.- Specified by:
getResource
in interfaceResourceManager
- Parameters:
aName
- the name of the resource to retrieve- Returns:
- the Resource registered under
aName
,null
if none exists. - Throws:
ResourceAccessException
- if the requested resource could not be initialized. A common cause is that it requires parameters and theResourceManager.getResource(String,String[])
method should have been called instead of this method.- See Also:
-
getResource
Description copied from interface:ResourceManager
Gets an instance of a parameterized Resource. An example of a parameterized Resource is a dictionary whose data depends on a specified language identifier.- Specified by:
getResource
in interfaceResourceManager
- Parameters:
aName
- the name of the resource to retrieveaParams
- the parameters determining which particular instance is returned- Returns:
- the requested Resource,
null
if there is no resource registered under the nameaName
. - Throws:
ResourceAccessException
- if there is a resource registered underaName
but it could not be instantiated for the specified parameters.- See Also:
-
getResourceClass
Description copied from interface:ResourceManager
Gets the Class of the Resource that will be returned by a call toResourceManager.getResource(String)
orResourceManager.getResource(String,String[])
.- Specified by:
getResourceClass
in interfaceResourceManager
- Parameters:
aName
- the name of a resource- Returns:
- the Class for the resource named
aName
,null
if there is no resource registered under that name. - See Also:
-
getResourceAsStream
public InputStream getResourceAsStream(String aKey, String[] aParams) throws ResourceAccessException Description copied from interface:ResourceManager
Retrieves an InputStream for reading from the named resource. This can be used, for example, to read configuration or authority files. This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed.- Specified by:
getResourceAsStream
in interfaceResourceManager
- Parameters:
aKey
- the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the annotator's descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in thedata path
or in the class path usingClassLoader.getResource(String)
.aParams
- parameters used to further identify the resource- Returns:
- an
InputStream
for reading from the named resource,null
if the named resource could not be found. It is the caller's responsibility to close this stream once it is no longer needed. - Throws:
ResourceAccessException
- if a failure occurs in accessing the resource
-
getResourceAsStream
Description copied from interface:ResourceManager
Retrieves an InputStream for reading from the named resource. This can be used, for example, to read configuration or authority files.- Specified by:
getResourceAsStream
in interfaceResourceManager
- Parameters:
aKey
- the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the annotator's descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in thedata path
or in the class path usingClassLoader.getResource(String)
.- Returns:
- an
InputStream
for reading from the named resource,null
if the named resource could not be found. It is the caller's responsibility to close this stream once it is no longer needed. - Throws:
ResourceAccessException
- if a failure occurs in accessing the resource
-
getResourceAsStreamCommon
- Throws:
ResourceAccessException
-
getResourceAsStreamCommonUrl
-
getResourceURL
Description copied from interface:ResourceManager
Retrieves the URL to the named resource. This can be used, for example, to locate configuration or authority files. This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed.- Specified by:
getResourceURL
in interfaceResourceManager
- Parameters:
aKey
- the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the annotator's descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in thedata path
or in the class path usingClassLoader.getResource(String)
.aParams
- parameters used to further identify the resource- Returns:
- the
URL
at which the named resource is located,null
if the named resource could not be found. - Throws:
ResourceAccessException
- if a failure occurs in accessing the resource
-
getResourceURL
Description copied from interface:ResourceManager
Retrieves the URL to the named resource. This can be used, for example, to locate configuration or authority files.- Specified by:
getResourceURL
in interfaceResourceManager
- Parameters:
aKey
- the key by which the resource is identified. If this key was declared in the <externalResourceDependencies> section of the descriptor, then the resource manager is used to locate the resource. If not, the key is assumed to be the resource name and is looked up in thedata path
or in the class path usingClassLoader.getResource(String)
.- Returns:
- the
URL
at which the named resource is located,null
if the named resource could not be found. - Throws:
ResourceAccessException
- if a failure occurs in accessing the resource
-
initializeExternalResources
public void initializeExternalResources(ResourceManagerConfiguration aConfiguration, String aQualifiedContextName, Map<String, Object> aAdditionalParams) throws ResourceInitializationExceptionDescription copied from interface:ResourceManager
Initializes all external resources declared in a ResourceCreationSpecifier. Multi-threading: may be called on multiple threads. Initialization should be done once, on the first call- Specified by:
initializeExternalResources
in interfaceResourceManager
- Parameters:
aConfiguration
- the ResourceManagerConfiguration containing resource declarations and bindingsaQualifiedContextName
- qualified name of UimaContext for the component (e.g. analysis engine) that is declaring these external resourcesaAdditionalParams
- additional parameters to be passed to resource initialize methods- Throws:
ResourceInitializationException
- if an initialization failure occurs
-
resolveAndValidateResourceDependencies
public void resolveAndValidateResourceDependencies(ExternalResourceDependency[] aDependencies, String aQualifiedContextName) throws ResourceInitializationException Description copied from interface:ResourceManager
Resolves a component's external resource dependencies using this resource manager. Throws an exception if any required dependencies are not satisfied. Multi-threading: may be called on multiple threads, repeatedly for the same set of resources. Implementations should avoid wasting time do this work.- Specified by:
resolveAndValidateResourceDependencies
in interfaceResourceManager
- Parameters:
aDependencies
- declarations of a component's dependencies on external resourcesaQualifiedContextName
- qualified name of UimaContext for the component (e.g. analysis engine) that is declaring these dependencies- Throws:
ResourceInitializationException
- if a required dependency is not satisfied
-
registerResource
private void registerResource(String aName, ExternalResourceDescription aResourceDescription, String aDefiningContext, Map<String, Object> aResourceInitParams) throws ResourceInitializationExceptionInstantiates a resource and inserts it in the internal resource map.- Throws:
ResourceInitializationException
-
getCasManager
Description copied from interface:ResourceManager
Gets the CasManager, which manages the creation and pooling of CASes.- Specified by:
getCasManager
in interfaceResourceManager
- Returns:
- the CasManager
-
setCasManager
Description copied from interface:ResourceManager
Sets the CasManager, which manages the creation and pooling of CASes. This method does not normally need to be called by an application. It allows a custom CAS Manager implementation to be substituted for the default one, which may be useful when embedding UIMA in other middleware where a different CAS Manager implementation may be desired.This method can only be called once, and must be called before creating any AnalysisEngines that use this ResourceManager. An Exception will be thrown if this method is called twice or is called after
ResourceManager.getCasManager()
has already been called (which happens during AE initialization).- Specified by:
setCasManager
in interfaceResourceManager
- Parameters:
aCasManager
- CAS Manager instance to plug in
-
getRelativePathResolver
-
getImportCache
Description copied from interface:ResourceManager
Gets a cache of imported descriptors, so that the parsed objects can be reused if the same URL is imported more than once.- Specified by:
getImportCache
in interfaceResourceManager
- Returns:
- A map from absolute URL to the XMLizable object that was parsed from that URL
-