org.apache.muse.core
Class SimpleResourceManager

java.lang.Object
  extended by org.apache.muse.core.SimpleResourceManager
All Implemented Interfaces:
Initialization, ResourceManager, Shutdown
Direct Known Subclasses:
OSGiResourceManager

public class SimpleResourceManager
extends Object
implements ResourceManager

SimpleResourceManager is Muse's default implementation of resource lifecycle management and the implied resource pattern. It maintains a simple table that maps EPRs to Resource objects. Each EPR that is added to the manager must be unique, but multiple EPRs may be mapped to the same Resource object.

Author:
Dan Jemiolo (danj)

Constructor Summary
SimpleResourceManager()
           
 
Method Summary
 void addListener(ResourceManagerListener listener)
           
 void addResource(EndpointReference epr, Resource resource)
          Add a resource to the manager, associated with the given EPR.
 void addResourceDefinitions(Collection definitions)
           
 Resource createResource(String contextPath)
          Finds the resource type definition associated with the given context path (defined in muse.xml), instantiates an instance of the resource class, and sets the basic values (EPR, initialization parameters, etc.) and Muse components (Environment, log file, etc.) that it needs to operate.
 Environment getEnvironment()
           
protected  List getListeners()
           
 int getNumberOfResources()
           
 Resource getResource(EndpointReference epr)
           
 String getResourceContextPath(Class capabilityClass)
          This method allows you to find a resource type's endpoint URI given the Java interface or concrete class of one of its capabilities.
 Collection getResourceContextPaths()
           
 Collection getResourceContextPaths(Class capabilityClass)
          This method is just like getResourceContextPath(Class) except that it returns multiple endpoints that use the capability.
protected  ResourceDefinition getResourceDefinition(String contextPath)
           
 Iterator getResourceEPRs()
           
 Iterator getResourceEPRs(String contextPath)
          This method allows you to search for the EPRs for all instances of a given resource type (where each resource type has a unique context path).
 boolean hasBeenInitialized()
           
 boolean hasBeenShutdown()
           
 void initialize()
           
 boolean isUsingPersistence(String contextPath)
           
 void removeListener(ResourceManagerListener listener)
          Stops the given listener from receiving notifications about the addition and removal of resource instances.
 void removeResource(EndpointReference epr)
          Removes the EPR-resource pair from the manager.
 void removeResourceDefinitions(Collection definitions)
          Removes each ResourceDefinition in the given Collection.
 void setEnvironment(Environment environment)
           
 void shutdown()
          This implementation loops through all existing resource instances and tells them to shutdown().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleResourceManager

public SimpleResourceManager()
Method Detail

addListener

public void addListener(ResourceManagerListener listener)
Specified by:
addListener in interface ResourceManager
Parameters:
listener - A listener that will be fired whenever a resource is added or removed from the resource.

addResource

public void addResource(EndpointReference epr,
                        Resource resource)
                 throws SoapFault
Description copied from interface: ResourceManager
Add a resource to the manager, associated with the given EPR.

Specified by:
addResource in interface ResourceManager
Parameters:
epr - The unique EPR identifying the resource instance.
Throws:
SoapFault -
  • If there is already a resource with the same EPR.
See Also:
ResourceManager.getResource(EndpointReference)

addResourceDefinitions

public void addResourceDefinitions(Collection definitions)
Specified by:
addResourceDefinitions in interface ResourceManager
Parameters:
definitions - The ResourceDefinition objects that will be used to generate new resource instances.

createResource

public Resource createResource(String contextPath)
                        throws SoapFault
Description copied from interface: ResourceManager
Finds the resource type definition associated with the given context path (defined in muse.xml), instantiates an instance of the resource class, and sets the basic values (EPR, initialization parameters, etc.) and Muse components (Environment, log file, etc.) that it needs to operate.

The Resource object returned by this method has not been initialized yet. Once the Resource.initialize() method has been called, the resource should be added to the ResourceManager with the addResource() method.

Specified by:
createResource in interface ResourceManager
Parameters:
contextPath - The context path for the resource type that is to be instantiated. This value is specified with the context-path element in muse.xml.
Returns:
An instance of the resource class. It will have a proper EPR, all of its capabilities, and references to all of the basic Muse components (Environment, log file, etc.). Calling code may further modify the resource before calling initialize() and making it available to clients.
Throws:
SoapFault

getEnvironment

public Environment getEnvironment()
Specified by:
getEnvironment in interface ResourceManager
Returns:
The manager's access point for things such as the WS-Addressing context, file system resources, and more.

getListeners

protected List getListeners()
Returns:
A copy of the list of ResourceManagerListeners.

getNumberOfResources

public int getNumberOfResources()
Specified by:
getNumberOfResources in interface ResourceManager
Returns:
The number of resource instances stored by the manager.

getResource

public Resource getResource(EndpointReference epr)
Specified by:
getResource in interface ResourceManager
Parameters:
epr - The unique EPR that is associated with the desired resource.
Returns:
The resource associated with the given EPR, or null if no such resource exists.

getResourceContextPath

public String getResourceContextPath(Class capabilityClass)
Description copied from interface: ResourceManager
This method allows you to find a resource type's endpoint URI given the Java interface or concrete class of one of its capabilities.

Specified by:
getResourceContextPath in interface ResourceManager
Parameters:
capabilityClass - An interface or concrete class for one of the capabilities in the application's resource types. This value may be defined in resource-type/capability/java-capability-class in muse.xml.
Returns:
A unique URL for the resource type that is partially-defined by the given capability's interface or class, or null if no such type exists.

getResourceContextPaths

public Collection getResourceContextPaths()
Specified by:
getResourceContextPaths in interface ResourceManager
Returns:
A collection containing the context paths for all resource types specified in muse.xml. The collection may be empty.

getResourceContextPaths

public Collection getResourceContextPaths(Class capabilityClass)
Description copied from interface: ResourceManager
This method is just like getResourceContextPath(Class) except that it returns multiple endpoints that use the capability.

Specified by:
getResourceContextPaths in interface ResourceManager

getResourceDefinition

protected ResourceDefinition getResourceDefinition(String contextPath)
Parameters:
contextPath - The URL targeted by an incoming request - this should map to a context-path value in muse.xml.
Returns:
The ResourceDefinition associated with the given endpoint, or null if there is no such type.

getResourceEPRs

public Iterator getResourceEPRs()
Specified by:
getResourceEPRs in interface ResourceManager
Returns:
This implementation returns an iterator over a copy of the collection of resource EPRs.

getResourceEPRs

public Iterator getResourceEPRs(String contextPath)
This method allows you to search for the EPRs for all instances of a given resource type (where each resource type has a unique context path).

This implementation may be fairly slow depending on how many resource types are in the application. It does a linear search through the entire collection of active EPRs and returns those that have the given context path. This is different from the getResource() method, which does a simple O(1) hash table lookup.

Specified by:
getResourceEPRs in interface ResourceManager
Returns:
An iterator over the collection of resource EPRs whose wsa:Address includes the given context path.

hasBeenInitialized

public boolean hasBeenInitialized()
Specified by:
hasBeenInitialized in interface Initialization
Returns:
True, if the initialize() method has been called and run to completion successfully.

hasBeenShutdown

public boolean hasBeenShutdown()
Specified by:
hasBeenShutdown in interface Shutdown
Returns:
True, if the shutdown() method has been called and run to completion successfully. If true, no other methods should be called on this Resource object.

initialize

public void initialize()
                throws SoapFault
Specified by:
initialize in interface Initialization
Throws:
SoapFault

isUsingPersistence

public boolean isUsingPersistence(String contextPath)
Specified by:
isUsingPersistence in interface ResourceManager
Returns:
True if the resource type was specified with the use-router-persistence flag set to 'true' in muse.xml.

removeListener

public void removeListener(ResourceManagerListener listener)
Description copied from interface: ResourceManager
Stops the given listener from receiving notifications about the addition and removal of resource instances.

Specified by:
removeListener in interface ResourceManager

removeResource

public void removeResource(EndpointReference epr)
                    throws SoapFault
Description copied from interface: ResourceManager
Removes the EPR-resource pair from the manager. This does not destroy the resource - it merely removes it from the external view.

Specified by:
removeResource in interface ResourceManager
Parameters:
epr - The unique EPR that maps to the resource being removed.
Throws:
SoapFault -
  • If the EPR does not map to a resource.

removeResourceDefinitions

public void removeResourceDefinitions(Collection definitions)
Description copied from interface: ResourceManager
Removes each ResourceDefinition in the given Collection. After this method has returned, the application will no longer service requests for the given resource types. It will be as though they were never deployed.

Specified by:
removeResourceDefinitions in interface ResourceManager

setEnvironment

public void setEnvironment(Environment environment)
Specified by:
setEnvironment in interface ResourceManager

shutdown

public void shutdown()
              throws SoapFault
This implementation loops through all existing resource instances and tells them to shutdown().

Specified by:
shutdown in interface Shutdown
Throws:
SoapFault


Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.