org.d_haven.event.command

Class DefaultCommandManager

public class DefaultCommandManager extends 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 classDefaultCommandManager.DelayedCommandInfo
This class encapsulates the information needed to keep track of our progress executing delayed and repeated commands.
Field Summary
SwitchedEnqueuePredicatem_enqueuePredicate
CommandEventPipelinem_eventPipeline
ThreadManagerm_threads
Constructor Summary
DefaultCommandManager(ThreadManager manager)
Create the DefaultCommandManager using the supplied ThreadManager.
Method Summary
voidenqueueCommand(Command command)
Get the Command Sink so that you can enqueue new commands.
CommandFailureHandlergetCommandFailureHandler()
Get the failure handler so that DefaultCommandManager can use it when a problem happens.
intgetEnqueuedCommandSize()
Get the number of currently enqueued commands.
ThreadManagergetThreadManager()
Get the ThreadManager we are using for this CommandManager.
voidsetCommandFailureHandler(CommandFailureHandler handler)
Set the failure handler that the application can use to override what happens when a command failure happens.
voidstart()
voidstop(boolean clear)
StringtoString()

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

enqueueCommand

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

Parameters: command the command to enqueue and run

Throws: SinkException if the enqueue operation cannot succeed

getCommandFailureHandler

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

Returns: the failure handler.

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

getThreadManager

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

Returns: the ThreadManager

setCommandFailureHandler

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

Parameters: handler the new Handler

Throws: NullPointerException if "handler" is null.

start

public void start()

stop

public void stop(boolean clear)

toString

public String toString()