org.apache.muse.core.routing
Class SimpleResourceRouter

java.lang.Object
  extended by org.apache.muse.core.routing.SimpleResourceRouter
All Implemented Interfaces:
Initialization, ResourceRouter, Shutdown
Direct Known Subclasses:
OSGiResourceRouter, WsResourceRouter

public class SimpleResourceRouter
extends Object
implements ResourceRouter

SimpleResourceRouter is Muse's default implementation of a router that uses the implied resource pattern to delegate requests to resources. It uses the WS-A header data to map the request to a particular resource in its ResourceManager.

Author:
Dan Jemiolo (danj)

Constructor Summary
SimpleResourceRouter()
           
 
Method Summary
protected  ResourceManager createResourceManager()
          This method can be overridden to provide an alternate implementation of the ResourceManager component to the router.
 Environment getEnvironment()
           
 Logger getLog()
           
 RouterPersistence getPersistence()
           
 Collection getResourceDefinitions()
           
 ResourceManager getResourceManager()
           
protected  Resource getTargetResource()
          Queries the Environment to get the WS-A EPR being targeted by the current request and then does a lookup in the ResourceManager with that EPR.
 boolean hasBeenInitialized()
           
 boolean hasBeenShutdown()
           
 void initialize()
          

This implementation performs initialization using the steps below.
 Element invoke(Element soapBody)
          This is a generic method invocation mechanism that can be used to delegate request handling to a specific Resource.
 void setEnvironment(Environment environment)
           
 void setLog(Logger log)
           
 void setPersistence(RouterPersistence persistence)
           
 void setResourceDefinitions(Collection resourceDefinitions)
           
 void setResourceManager(ResourceManager resourceManager)
           
 void shutdown()
          

This implementation iterates over the collection of resources in the ResourceManager and destroys each one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleResourceRouter

public SimpleResourceRouter()
Method Detail

createResourceManager

protected ResourceManager createResourceManager()
This method can be overridden to provide an alternate implementation of the ResourceManager component to the router.

Returns:
An instance of SimpleResourceManager.

getEnvironment

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

getLog

public Logger getLog()
Specified by:
getLog in interface ResourceRouter
Returns:
The JDK logger that writes to the Muse log file.

getPersistence

public RouterPersistence getPersistence()
Specified by:
getPersistence in interface ResourceRouter
Returns:
The persistence mechanism for the router, or null if none was defined.

getResourceDefinitions

public Collection getResourceDefinitions()
Specified by:
getResourceDefinitions in interface ResourceRouter
Returns:
The collection of ResourceDefinition objects representing all of the resource types that the router controls.

getResourceManager

public ResourceManager getResourceManager()

getTargetResource

protected Resource getTargetResource()
                              throws SoapFault
Queries the Environment to get the WS-A EPR being targeted by the current request and then does a lookup in the ResourceManager with that EPR. This method is essential to all routing activity. The resource returned is guaranteed to be the resource specified by the client, but it is not guaranteed to support the specified operation.

Returns:
The resource whose EPR maps to the WS-A data in the current request.
Throws:
SoapFault -
  • If the EPR (including any unique reference properties) is not associated with any resource instance.
See Also:
MessageHeaders.getToAddress(), ResourceManager.getResource(EndpointReference)

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


This implementation performs initialization using the steps below.
  1. Make sure a Logger has been provided.
  2. Make sure an Environment has been provided.
  3. Create the ResourceManager component.
  4. Create any resources that are supposed to be instantiated at startup.

Specified by:
initialize in interface Initialization
Throws:
SoapFault

invoke

public Element invoke(Element soapBody)
Description copied from interface: ResourceRouter
This is a generic method invocation mechanism that can be used to delegate request handling to a specific Resource. This method should be used by the isolation layer in order to process external requests.

Specified by:
invoke in interface ResourceRouter
Parameters:
soapBody - The parameters for the method, still in their SOAP Body form.
Returns:
The return value of the method, in SOAP Body form. If there was an error while processing the request, the value will be a SOAP v1.2 fault, in XML form.
See Also:
Resource.invoke(Element)

setEnvironment

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

setLog

public void setLog(Logger log)
Specified by:
setLog in interface ResourceRouter

setPersistence

public void setPersistence(RouterPersistence persistence)
Specified by:
setPersistence in interface ResourceRouter

setResourceDefinitions

public void setResourceDefinitions(Collection resourceDefinitions)
Specified by:
setResourceDefinitions in interface ResourceRouter

setResourceManager

public void setResourceManager(ResourceManager resourceManager)

shutdown

public void shutdown()


This implementation iterates over the collection of resources in the ResourceManager and destroys each one. If one destructor fails, it is logged and we move on to the next resource.

Specified by:
shutdown in interface Shutdown
See Also:
getResourceManager()


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