com.admc.jamama.director
Class JamamaDirector

java.lang.Object
  extended byAbstractDynamicMBean
      extended bycom.admc.jamama.director.JamamaDirector
All Implemented Interfaces:
Configurable, Director, Router, java.lang.Runnable, Server

public class JamamaDirector
extends AbstractDynamicMBean
implements Director

Implementation of a Routing Director. Just a stub at this point.

Version:
$Revision: 1.7 $
Author:
Blaine Simpson
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.admc.jamama.Router
STATUS_CONTINUE, STATUS_DEFER, STATUS_DROP, STATUS_EXPLICITROUTE, STATUS_FREEZE, STATUS_SUCCESS
 
Constructor Summary
JamamaDirector()
           
 
Method Summary
 void configure(java.lang.Object inCfg)
          Initialize the object's state with information in the given Jaxb object.
protected  MBeanAttributeInfo[] createMBeanAttributeInfo()
           
 Mit createMit()
          Creates a mit but does not store it anyhwhere.
 java.lang.Object getConfig()
          Returns the Jaxb object used to configure this.
protected  java.lang.String getMBeanDescription()
           
 java.lang.String getName()
          Name which Jamama config file uses to identify this object instance.
 RepositoryDependency[] getNeededRepositories()
           
 RepositoryDependency[] getNeedRepositories()
          Returns names of the repositories needed.
 java.lang.String[] getNeedRouters()
          Returns names of all Routers that this Router may forward to.
 boolean getRun()
          Say whether main thread of this Server is running.
 boolean isRun()
           
 void restoreRunState()
          Start up server iff server is configured to start automatically.
 int route(Mit mit, boolean ping, Repository[] repositoryList)
          Processes a Mit, with a goal of approaching or achieving Mit consumption or rejection.
 boolean route(Mit mit, boolean ping, Router startingRouter)
          Routes a Mit through a portion of the (or the entire) pipeline.
 void routingRun(java.lang.String criteria, int mitState, boolean debug)
          Extracts Mits with the given state and other criteria from repository and attempts to route them.
 void run()
          Main thread
 void setPipeline(java.util.List inList)
          Sets the router Pipeline to those pipes named in the input list.
 void setRepositories(ClassReposMapMap inClassReposes, ClassRepositoryMap inDefaultClassReposes)
          Set repositories to use and to make available to Routers.
 void setRouters(StringRouterMap inRouterMap)
           
 void setRun(boolean inRun)
          Start or stop the main thread in this object.
 void validateRouters()
          Verifies that Routers and Repositories "needed" by Routers in our "router" set all exist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JamamaDirector

public JamamaDirector()
Method Detail

setRouters

public void setRouters(StringRouterMap inRouterMap)
                throws java.lang.Exception
Specified by:
setRouters in interface Director
Throws:
java.lang.Exception

setRepositories

public void setRepositories(ClassReposMapMap inClassReposes,
                            ClassRepositoryMap inDefaultClassReposes)
Description copied from interface: Director
Set repositories to use and to make available to Routers.

Specified by:
setRepositories in interface Director
See Also:
Director

routingRun

public void routingRun(java.lang.String criteria,
                       int mitState,
                       boolean debug)
                throws java.io.IOException
Extracts Mits with the given state and other criteria from repository and attempts to route them.

Parameters:
criteria - Selection criteria for Mits to route
mitState - Only attempt to route Mits with this state
debug - Only do ping routings. Don't persist anything.
Throws:
java.io.IOException

validateRouters

public void validateRouters()
                     throws java.lang.Exception
Verifies that Routers and Repositories "needed" by Routers in our "router" set all exist.

Throws:
java.lang.Exception

createMit

public Mit createMit()
Creates a mit but does not store it anyhwhere. The created Mit will not ever be persisted until somebody calls mit.persist(). The Director will never route it until the mit.state is set appropriately. This method is in this class so that the Director can designate what repository it will be saved to when anybody runs mit.persist().

Specified by:
createMit in interface Director

setPipeline

public void setPipeline(java.util.List inList)
                 throws UndefinedNameException
Sets the router Pipeline to those pipes named in the input list. Pipeline always starts with Router.pipehead and ends with the Routing Director itself (which implements Router). (That fact is actually an implementation detail which doesn't belong in the API, but I'm putting that info here for now).

Specified by:
setPipeline in interface Director
Parameters:
inList - A list of String pipe names.
Throws:
UndefinedNameException

route

public boolean route(Mit mit,
                     boolean ping,
                     Router startingRouter)
Routes a Mit through a portion of the (or the entire) pipeline. Note that this is not Router.route(). Router.route() just invokes a single Router. This method invokes a chain of Routers. Even though this method requires to be invoked with a starting router that is in the pipeline, any router may forward to a router that is not in the pipeline.

Parameters:
mit - Mit to route
ping - True to actually route the Mit, False to just get a return status from this method.
startingRouter - Name of the Router to start at. This Router must be in the current Director pipeline. A null startRouter means to start at the head of the pipeline.
Returns:
An indication of success or failure. (This is mostly of use when ping is true).

isRun

public boolean isRun()
See Also:
Server

getRun

public boolean getRun()
Description copied from interface: Server
Say whether main thread of this Server is running.

Specified by:
getRun in interface Server
Returns:
Indication of whether Server main thread is running.
See Also:
Server

createMBeanAttributeInfo

protected MBeanAttributeInfo[] createMBeanAttributeInfo()

getMBeanDescription

protected java.lang.String getMBeanDescription()

setRun

public void setRun(boolean inRun)
Description copied from interface: Server
Start or stop the main thread in this object.

Specified by:
setRun in interface Server
Parameters:
inRun - true to start up thread; false to stop it
See Also:
Server

restoreRunState

public void restoreRunState()
Description copied from interface: Server
Start up server iff server is configured to start automatically.

Specified by:
restoreRunState in interface Server
See Also:
Server

run

public void run()
Main thread

Specified by:
run in interface java.lang.Runnable

getNeedRouters

public java.lang.String[] getNeedRouters()
Description copied from interface: Router
Returns names of all Routers that this Router may forward to.

Specified by:
getNeedRouters in interface Router
Returns:
Set of names of routers which could possibly be forward to by this router with this configuration
See Also:
com.admc.Router

getNeededRepositories

public RepositoryDependency[] getNeededRepositories()
See Also:
com.admc.Router

route

public int route(Mit mit,
                 boolean ping,
                 Repository[] repositoryList)
Description copied from interface: Router
Processes a Mit, with a goal of approaching or achieving Mit consumption or rejection. N.b. this method uses return values to indicate any expected routing failures, it does not throw Exceptions for that purpose. If a router returns STATUS_DROP or STATUS_FREEZE, then this router should send a bounce message if appropriate. This is because the caller of route() may not know whether a bounce is appropriate. Successful consumption is achieved by returning STATUS_SUCCESS. Unsuccessful consumption is achieved by returning STATUS_DROP. Pure filtering (i.e. filtering without consuming) is achieved by conditionally returning STATUS_DROP, STATUS_CONTINUE, STATUS_EXPLICITROUTE, etc. If a router() method has one resolution for some recipient(s) and some other resolution for any other recipient(s), then it must proceed with one (group) and just clone and persist the Mit for the other recipient(s). The Director will pick up the new Mit instance and route it when it can.

Specified by:
route in interface Router
Returns:
An indication of how the Mit should be processed next.
See Also:
com.admc.Router

configure

public void configure(java.lang.Object inCfg)
Description copied from interface: Configurable
Initialize the object's state with information in the given Jaxb object.

Specified by:
configure in interface Configurable
Parameters:
inCfg - A Jaxb object corresponding to a XML document branch.
See Also:
Configurable

getName

public java.lang.String getName()
Description copied from interface: Configurable
Name which Jamama config file uses to identify this object instance.

Specified by:
getName in interface Configurable
See Also:
Configurable

getConfig

public java.lang.Object getConfig()
Description copied from interface: Configurable
Returns the Jaxb object used to configure this.

Specified by:
getConfig in interface Configurable
See Also:
Configurable

getNeedRepositories

public RepositoryDependency[] getNeedRepositories()
Description copied from interface: Router
Returns names of the repositories needed. The list gets updated every time that the configuration runs, so that users can change repositories at runtime.

Specified by:
getNeedRepositories in interface Router
Returns:
list of names of repositories which could possibly be required by this router with current configuration.
See Also:
Router