IN
- the input type for that chainOUT
- the output type for that chain@Immutable public final class ProcessorChain<IN extends MessageProvider,OUT extends MessageProvider> extends Object
This class allows to build a chain out of different Processor
instances. Chaining two processors p1
and p2
only requires
that the output of p1
be compatible with the input of p2
.
The result behaves like a processor itself, so it can be used in other chains as well.
Sample usage:
final Processor<X, Y> chain = ProcessorChain.startWith(p1) .chainWith(p2).chainWith(...).getProcessor(); // input is of type X final Y ret = chain.process(report, X);
Note that all instances are immutable: each alteration of the chain returns a new chain. This, for example, will not work:
final ProcessorChain<X, Y> chain = ProcessorChain.startWith(p1); chain.failOnError(); // WRONG! chain.getProcessor(); // Will return p1, not p1 with a stop condition
Modifier and Type | Method and Description |
---|---|
<NEWOUT extends MessageProvider> |
chainWith(Processor<OUT,NEWOUT> p)
Add a processor to the chain
|
ProcessorChain<IN,OUT> |
failOnError()
Stop the processing chain on failure
|
ProcessorChain<IN,OUT> |
failOnError(ProcessingMessage message)
Stop the processing chain on failure
|
Processor<IN,OUT> |
getProcessor() |
static <X extends MessageProvider,Y extends MessageProvider> |
startWith(Processor<X,Y> p)
Start a processing chain with a single processor
|
public static <X extends MessageProvider,Y extends MessageProvider> ProcessorChain<X,Y> startWith(Processor<X,Y> p)
X
- the input typeY
- the output typep
- the processorNullPointerException
- processor is nullpublic ProcessorChain<IN,OUT> failOnError()
Inserting this into a chain will stop the processing chain if the
previous processor ended up with an error (ie, ProcessingReport.isSuccess()
returns false
).
public ProcessorChain<IN,OUT> failOnError(ProcessingMessage message)
Inserting this into a chain will stop the processing chain if the
previous processor ended up with an error (ie, ProcessingReport.isSuccess()
returns false
).
message
- the processing message to useProcessingMessage.asException()
,
ProcessingMessage.setExceptionProvider(ExceptionProvider)
public <NEWOUT extends MessageProvider> ProcessorChain<IN,NEWOUT> chainWith(Processor<OUT,NEWOUT> p)
NEWOUT
- the return type for that new processorp
- the processor to addNullPointerException
- processor to append is null