org.d_haven.event.command
Class DefaultCommandManager

java.lang.Object
  extended by org.d_haven.event.command.DefaultCommandManager
All Implemented Interfaces:
CommandManager

public class DefaultCommandManager
extends java.lang.Object
implements CommandManager

The DefaultCommandManager handles asynchronous commands from the rest of the system. The only exposed piece is the Pipe that other components use to give Commands to this system. You must register this with a ThreadManager for it to work.

Source Example

 

// // Set up the ThreadManager that the DefaultCommandManager will use //

ThreadManager threadManager = new DefaultThreadManager();

// // Set up the DefaultCommandManager //

DefaultCommandManager commandManager = new DefaultCommandManager(threadManager);

Author:
Berin Loritsch

Nested Class Summary
static class DefaultCommandManager.DelayedCommandInfo
          This class encapsulates the information needed to keep track of our progress executing delayed and repeated commands.
 
Field Summary
private  SwitchedEnqueuePredicate m_enqueuePredicate
           
private  CommandEventPipeline m_eventPipeline
           
private  ThreadManager m_threads
           
 
Constructor Summary
DefaultCommandManager(ThreadManager manager)
          Create the DefaultCommandManager using the supplied ThreadManager.
 
Method Summary
 void enqueueCommand(Command command)
          Get the Command Sink so that you can enqueue new commands.
 CommandFailureHandler getCommandFailureHandler()
          Get the failure handler so that DefaultCommandManager can use it when a problem happens.
 int getEnqueuedCommandSize()
          Get the number of currently enqueued commands.
 ThreadManager getThreadManager()
          Get the ThreadManager we are using for this CommandManager.
 void setCommandFailureHandler(CommandFailureHandler handler)
          Set the failure handler that the application can use to override what happens when a command failure happens.
 void start()
          Start or restart the CommandManager so that it can accept more commands.
 void stop(boolean clear)
          Stop the CommandManager so that it can stop accepting commands.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_enqueuePredicate

private final SwitchedEnqueuePredicate m_enqueuePredicate

m_eventPipeline

private final CommandEventPipeline m_eventPipeline

m_threads

private ThreadManager m_threads
Constructor Detail

DefaultCommandManager

public DefaultCommandManager(ThreadManager manager)
Create the DefaultCommandManager using the supplied ThreadManager.

Parameters:
manager - the ThreadManager to use for the command manager
Method Detail

setCommandFailureHandler

public void setCommandFailureHandler(CommandFailureHandler handler)
Set the failure handler that the application can use to override what happens when a command failure happens.

Specified by:
setCommandFailureHandler in interface CommandManager
Parameters:
handler - the new Handler
Throws:
java.lang.NullPointerException - if "handler" is null.

enqueueCommand

public void enqueueCommand(Command command)
                    throws SinkException
Get the Command Sink so that you can enqueue new commands.

Specified by:
enqueueCommand in interface CommandManager
Parameters:
command - the command to enqueue and run
Throws:
SinkException - if the enqueue operation cannot succeed

start

public void start()
Description copied from interface: CommandManager
Start or restart the CommandManager so that it can accept more commands.

Specified by:
start in interface CommandManager

stop

public void stop(boolean clear)
Description copied from interface: CommandManager
Stop the CommandManager so that it can stop accepting commands.

Specified by:
stop in interface CommandManager
Parameters:
clear - out currently enqueued commmands.

getCommandFailureHandler

public CommandFailureHandler getCommandFailureHandler()
Get the failure handler so that DefaultCommandManager can use it when a problem happens.

Returns:
the failure handler.

getThreadManager

public ThreadManager getThreadManager()
Get the ThreadManager we are using for this CommandManager.

Returns:
the ThreadManager

getEnqueuedCommandSize

public int getEnqueuedCommandSize()
Get the number of currently enqueued commands. This number is a snapshot so it may not be accurate by the time you do anything with it. It is mainly used for testing.

Returns:
the snapshot number of waiting commands

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object