|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Chain
A Chain
represents a configured list of
Command
s that will be executed in order to perform processing
on a specified Context
. Each included Command
will be
executed in turn, until either one of them returns true
,
one of the executed Command
s throws an exception,
or the end of the chain has been reached. The Chain
itself will
return the return value of the last Command
that was executed
(if no exception was thrown), or rethrow the thrown exception.
Note that Chain
extends Command
, so that the two can
be used interchangeably when a Command
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 class ChainBase
)
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 which
Command
is currently being executed should be maintained in a
local variable inside the execute()
method, rather than
in an instance variable. The Command
s in a Chain
may be
configured (via calls to addCommand()
) at any time before
the execute()
method of the Chain
is first called.
After that, the configuration of the Chain
is frozen.
Field Summary |
---|
Fields inherited from interface org.apache.commons.chain.Command |
---|
CONTINUE_PROCESSING, PROCESSING_COMPLETE |
Method Summary | |
---|---|
void |
addCommand(Command command)
Add a Command to the list of Command s that will
be called in turn when this Chain 's execute()
method is called. |
boolean |
execute(Context context)
Execute the processing represented by this Chain according
to the following algorithm. |
Method Detail |
---|
void addCommand(Command command)
Add a Command
to the list of Command
s that will
be called in turn when this Chain
's execute()
method is called. Once execute()
has been called
at least once, it is no longer possible to add additional
Command
s; instead, an exception will be thrown.
command
- The Command
to be added
IllegalArgumentException
- if command
is null
IllegalStateException
- if this Chain
has already
been executed at least once, so no further configuration is allowedboolean execute(Context context) throws Exception
Execute the processing represented by this Chain
according
to the following algorithm.
Command
s in the Chain
,
return false
.execute()
method of each Command
configured on this chain, in the order they were added via calls
to the addCommand()
method, until the end of the
configured Command
s is encountered, or until one of
the executed Command
s returns true
or throws an exception.Command
s whose
execute()
methods, starting with the last one that
was executed. If this Command
instance is also a
Filter
, call its postprocess()
method,
discarding any exception that is thrown.Command
whose execute()
method
was called threw an exception, rethrow that exception.execute()
method of the last Command
that was executed. This will be
true
if the last Command
indicated that
processing of this Context
has been completed, or
false
if none of the called Command
s
returned true
.
execute
in interface Command
context
- The Context
to be processed by this
Chain
true
if the processing of this Context
has been completed, or false
if the processing
of this Context
should be delegated to a subsequent
Command
in an enclosing Chain
Exception
- if thrown by one of the Command
s
in this Chain
but not handled by a postprocess()
method of a Filter
IllegalArgumentException
- if context
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |