Interface Chain
-
- All Superinterfaces:
Command
- All Known Implementing Classes:
ChainBase
public interface Chain extends Command
A
Chain
represents a configured list ofCommand
s that will be executed in order to perform processing on a specifiedContext
. Each includedCommand
will be executed in turn, until either one of them returnstrue
, one of the executedCommand
s throws an exception, or the end of the chain has been reached. TheChain
itself will return the return value of the lastCommand
that was executed (if no exception was thrown), or rethrow the thrown exception.Note that
Chain
extendsCommand
, so that the two can be used interchangeably when aCommand
is expected. This makes it easy to assemble workflows in a hierarchical manner by combining subchains into an overall processing chain.To protect applications from evolution of this interface, specialized implementations of
Chain
should generally be created by extending the provided base classChainBase
) rather than directly implementing this interface.Chain
implementations should be designed in a thread-safe manner, suitable for execution on multiple threads simultaneously. In general, this implies that the state information identifying whichCommand
is currently being executed should be maintained in a local variable inside theexecute()
method, rather than in an instance variable. TheCommand
s in aChain
may be configured (via calls toaddCommand()
) at any time before theexecute()
method of theChain
is first called. After that, the configuration of theChain
is frozen.- Version:
- $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
-
-
Field Summary
-
Fields inherited from interface org.apache.commons.chain.Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addCommand(Command command)
boolean
execute(Context context)
Execute the processing represented by thisChain
according to the following algorithm.
-
-
-
Method Detail
-
addCommand
void addCommand(Command command)
-
execute
boolean execute(Context context) throws java.lang.Exception
Execute the processing represented by this
Chain
according to the following algorithm.- If there are no configured
Command
s in theChain
, returnfalse
. - Call the
execute()
method of eachCommand
configured on this chain, in the order they were added via calls to theaddCommand()
method, until the end of the configuredCommand
s is encountered, or until one of the executedCommand
s returnstrue
or throws an exception. - Walk backwards through the
Command
s whoseexecute()
methods, starting with the last one that was executed. If thisCommand
instance is also aFilter
, call itspostprocess()
method, discarding any exception that is thrown. - If the last
Command
whoseexecute()
method was called threw an exception, rethrow that exception. - Otherwise, return the value returned by the
execute()
method of the lastCommand
that was executed. This will betrue
if the lastCommand
indicated that processing of thisContext
has been completed, orfalse
if none of the calledCommand
s returnedtrue
.
- Specified by:
execute
in interfaceCommand
- Parameters:
context
- TheContext
to be processed by thisChain
- Returns:
true
if the processing of thisContext
has been completed, orfalse
if the processing of thisContext
should be delegated to a subsequentCommand
in an enclosingChain
- Throws:
java.lang.Exception
- if thrown by one of theCommand
s in thisChain
but not handled by apostprocess()
method of aFilter
java.lang.IllegalArgumentException
- ifcontext
isnull
- If there are no configured
-
-