org.araneaframework.framework.router
Class BaseServiceRouterService

java.lang.Object
  extended by org.araneaframework.core.BaseComponent
      extended by org.araneaframework.core.BaseService
          extended by org.araneaframework.framework.router.BaseServiceRouterService
All Implemented Interfaces:
Serializable, Component, Service
Direct Known Subclasses:
BaseExpiringServiceRouterService, PathInfoServiceRouterService, StandardSessionServiceRouterService

public abstract class BaseServiceRouterService
extends BaseService

A router service consists of multiple child services, they form a service map. One of the services is a default one.

Author:
"Toomas Römer"
See Also:
Serialized Form

Nested Class Summary
protected  class BaseServiceRouterService.ServiceRouterContextImpl
           
 
Nested classes/interfaces inherited from class org.araneaframework.core.BaseService
BaseService.ServiceImpl
 
Nested classes/interfaces inherited from class org.araneaframework.core.BaseComponent
BaseComponent.ComponentImpl
 
Nested classes/interfaces inherited from interface org.araneaframework.Service
Service.Interface
 
Field Summary
protected  Object defaultServiceId
           
 
Fields inherited from class org.araneaframework.core.BaseService
currentInputData, currentOutputData
 
Constructor Summary
BaseServiceRouterService()
           
 
Method Summary
protected  void action(Path path, InputData input, OutputData output)
          Uses the map to route the request to the service under getServiceId(input).
protected  void closeService(Object serviceId)
           
protected  Environment getChildEnvironment(Object serviceId)
           
protected  Object getDefaultServiceId()
          Returns the default service id.
protected  Object getServiceId(InputData input)
          Returns the service id of the request.
protected  Object getServiceIdFromInput(InputData input)
          Returns the service id read from input.
protected abstract  Object getServiceKey()
          Every service has its own key under which the service service id can be found in the request.
protected  void init()
          Initialize all the services in the service map with getChildEnvironment(Object serviceId).
protected  void propagate(Message message)
          Forwards the message to the component and to all of its children components.
 void setDefaultServiceId(Object defaultServiceId)
          Sets the default service id.
 void setServiceMap(Map serviceMap)
          Sets the service map.
 
Methods inherited from class org.araneaframework.core.BaseService
_getService, getInputData, getOutputData, handleServiceException
 
Methods inherited from class org.araneaframework.core.BaseComponent
_addComponent, _addComponent, _checkCall, _disableComponent, _enableComponent, _endCall, _endWaitingCall, _getChildren, _getComponent, _getDisabledChildren, _propagate, _relocateComponent, _removeComponent, _setEnvironment, _setScope, _startCall, _startWaitingCall, _strictCheckCall, _strictStartCall, _waitNoCall, destroy, disable, enable, getEnvironment, getScope, handleException, isAlive, isDead, isInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.araneaframework.Component
_getComponent, getEnvironment, getScope, isAlive
 

Field Detail

defaultServiceId

protected Object defaultServiceId
Constructor Detail

BaseServiceRouterService

public BaseServiceRouterService()
Method Detail

setServiceMap

public void setServiceMap(Map serviceMap)
Sets the service map. Key is the id of the service, value is the service.


setDefaultServiceId

public void setDefaultServiceId(Object defaultServiceId)
Sets the default service id. The id is used as a key in the service map.


init

protected void init()
             throws Exception
Initialize all the services in the service map with getChildEnvironment(Object serviceId). The serviceId is the key of the service in the service map.

Overrides:
init in class BaseComponent
Throws:
Exception - Any runtime exception that may occur.

propagate

protected void propagate(Message message)
                  throws Exception
Description copied from class: BaseComponent
Forwards the message to the component and to all of its children components.

Overrides:
propagate in class BaseComponent
Parameters:
message - A message to forward.
Throws:
Exception - Any runtime exception that may occur.

action

protected void action(Path path,
                      InputData input,
                      OutputData output)
               throws Exception
Uses the map to route the request to the service under getServiceId(input). The id of the service is determined by getServiceId(input). If the service id cannot be determined then the default id is used set via setDefaultServiceId(Object).

Overrides:
action in class BaseService
Parameters:
path - The path of the component to whom the action is targeted.
input - The request data.
output - The response data.
Throws:
Exception - Any runtime exception that may occur.

getChildEnvironment

protected Environment getChildEnvironment(Object serviceId)
                                   throws Exception
Throws:
Exception

getServiceId

protected Object getServiceId(InputData input)
                       throws Exception
Returns the service id of the request. By default returns the parameter value of the request under the key getServiceKey(). Returns defaultServiceId when input has no service information specified.

Throws:
Exception

getServiceIdFromInput

protected Object getServiceIdFromInput(InputData input)
                                throws Exception
Returns the service id read from input.

Throws:
Exception

getDefaultServiceId

protected Object getDefaultServiceId()
Returns the default service id.


getServiceKey

protected abstract Object getServiceKey()
                                 throws Exception
Every service has its own key under which the service service id can be found in the request. This method returns that key.

Throws:
Exception

closeService

protected void closeService(Object serviceId)