org.apache.excalibur.event.command
Class CommandManager

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.event.command.CommandManager
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.LogEnabled, org.apache.excalibur.event.command.EventPipeline, org.apache.excalibur.event.EnqueuePredicate

public class CommandManager
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.excalibur.event.command.EventPipeline, org.apache.avalon.framework.activity.Disposable, org.apache.excalibur.event.EnqueuePredicate

The CommandManager handles asynchronous commands from the rest of the system. The only exposed piece is the Queue 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 CommandManager will use
 //

 ThreadManager threadManager = new TPCThreadManager();
 threadManager.enableLogging( getLogger().getChildLogger("threadmanager") );
 Parameters params = new Parameters();
 params.setParameter( "threads-per-processor", "2" );
 params.setParameter( "sleep-time", "1000" );
 params.setParameter( "block-timeout", "250" );
 threadManager.parameterize( params );
 threadManager.initialize();

 //
 // Set up the CommandManager
 //

 CommandManager commandManager = new CommandManager();
 commandManager.enableLogging( getLogger().getChildLogger("commandmanager") );
 threadManager.register( commandManager );
 

Author:
Avalon Development Team

Nested Class Summary
private  class CommandManager.CommandEventHandler
           
private static class CommandManager.DelayedCommandInfo
           
 
Field Summary
private  org.apache.excalibur.event.EventHandler m_eventHandler
           
private  org.apache.excalibur.event.command.CommandFailureHandler m_failureHandler
           
private  boolean m_isAccepting
           
private  EDU.oswego.cs.dl.util.concurrent.ReentrantLock m_mutex
           
private  org.apache.excalibur.event.Queue m_queue
           
private  java.util.HashMap m_signalHandlers
           
private  org.apache.excalibur.event.Source[] m_sources
           
 
Constructor Summary
CommandManager()
          Create the CommandManager
 
Method Summary
 boolean accept(java.lang.Object[] elements, org.apache.excalibur.event.Sink modifyingSink)
          Tests the given element for acceptance onto the m_sink.
 boolean accept(java.lang.Object element, org.apache.excalibur.event.Sink modifyingSink)
          Tests the given element for acceptance onto the m_sink.
 void deregisterSignalHandler(org.apache.excalibur.event.Signal signal, org.apache.excalibur.event.EventHandler handler)
          Deregister a Signal with an EventHandler.
 void dispose()
          When you are done with CommandManager, call this and it will clean up all its resources.
protected  org.apache.excalibur.event.command.CommandFailureHandler getCommandFailureHandler()
          Get the failure handler so that CommandManager can use it when a problem happens.
 org.apache.excalibur.event.Sink getCommandSink()
          Get the Command Sink so that you can enqueue new commands.
 org.apache.excalibur.event.EventHandler getEventHandler()
          Used by the ThreadManager to get the EventHandler for the CommandManager.
 org.apache.excalibur.event.Source[] getSources()
          Used by the Threadmanager to get the sources that are feeding the CommandManager.
 void registerSignalHandler(org.apache.excalibur.event.Signal signal, org.apache.excalibur.event.EventHandler handler)
          Register a Signal with an EventHandler.
 void setCommandFailureHandler(org.apache.excalibur.event.command.CommandFailureHandler handler)
          Set the failure handler that the application can use to override what happens when a command failure happens.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_queue

private final org.apache.excalibur.event.Queue m_queue

m_signalHandlers

private final java.util.HashMap m_signalHandlers

m_mutex

private final EDU.oswego.cs.dl.util.concurrent.ReentrantLock m_mutex

m_eventHandler

private final org.apache.excalibur.event.EventHandler m_eventHandler

m_sources

private final org.apache.excalibur.event.Source[] m_sources

m_failureHandler

private org.apache.excalibur.event.command.CommandFailureHandler m_failureHandler

m_isAccepting

private boolean m_isAccepting
Constructor Detail

CommandManager

public CommandManager()
Create the CommandManager

Method Detail

setCommandFailureHandler

public void setCommandFailureHandler(org.apache.excalibur.event.command.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:
java.lang.NullPointerException - if "handler" is null.

getCommandFailureHandler

protected org.apache.excalibur.event.command.CommandFailureHandler getCommandFailureHandler()
Get the failure handler so that CommandManager can use it when a problem happens.

Returns:
the failure handler.

getCommandSink

public final org.apache.excalibur.event.Sink getCommandSink()
Get the Command Sink so that you can enqueue new commands.

Returns:
the Sink that feeds the CommandManager

registerSignalHandler

public final void registerSignalHandler(org.apache.excalibur.event.Signal signal,
                                        org.apache.excalibur.event.EventHandler handler)
Register a Signal with an EventHandler. The Signal is a special object that implements the Signal interface. When CommandManager recieves events that match the Signal, it will send a copy of it to all the CommandManager.CommandEventHandlers attached to it.

Parameters:
signal - The signal we are listening for.
handler - The handler that wants to be notified

deregisterSignalHandler

public final void deregisterSignalHandler(org.apache.excalibur.event.Signal signal,
                                          org.apache.excalibur.event.EventHandler handler)
Deregister a Signal with an EventHandler. Stop notifying the particular EventHandler that is passed in about the associated Signal.

Parameters:
signal - The signal we are listening for.
handler - The handler that wants to be notified

dispose

public void dispose()
When you are done with CommandManager, call this and it will clean up all its resources.

Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

getSources

public final org.apache.excalibur.event.Source[] getSources()
Used by the Threadmanager to get the sources that are feeding the CommandManager.

Specified by:
getSources in interface org.apache.excalibur.event.command.EventPipeline
Returns:
the Array of one Source

getEventHandler

public final org.apache.excalibur.event.EventHandler getEventHandler()
Used by the ThreadManager to get the EventHandler for the CommandManager.

Specified by:
getEventHandler in interface org.apache.excalibur.event.command.EventPipeline
Returns:
the EventHandler

accept

public boolean accept(java.lang.Object element,
                      org.apache.excalibur.event.Sink modifyingSink)
Tests the given element for acceptance onto the m_sink.

Specified by:
accept in interface org.apache.excalibur.event.EnqueuePredicate
Parameters:
element - The element to enqueue
modifyingSink - The sink that is used for this predicate
Returns:
true if the sink accepts the element; false otherwise.
Since:
Feb 10, 2003

accept

public boolean accept(java.lang.Object[] elements,
                      org.apache.excalibur.event.Sink modifyingSink)
Tests the given element for acceptance onto the m_sink.

Specified by:
accept in interface org.apache.excalibur.event.EnqueuePredicate
Parameters:
elements - The array of elements to enqueue
modifyingSink - The sink that is used for this predicate
Returns:
true if the sink accepts all the elements; false otherwise.
Since:
Feb 10, 2003