K
- the type of keys in the mapIN
- the input type of processorsOUT
- the output type of processors@NotThreadSafe public abstract class ProcessorMap<K,IN extends MessageProvider,OUT extends MessageProvider> extends Object
Map
-based processor selector, with an optional default processor
The processor produced by this class works as follows:
K
, is computed from the processor input, of
type IN
, using a Function
;Map
, whose values
are Processor
s;The default action depends on whether a default processor has been
supplied: if none exists, a ProcessingException
is thrown.
This class is meant to be extended, and the only method to implement is
f()
, which provides the function to compute keys.
Note that while this class is not thread safe, the resulting processor is immutable.
Also note that null keys are not allowed.
Constructor and Description |
---|
ProcessorMap() |
Modifier and Type | Method and Description |
---|---|
ProcessorMap<K,IN,OUT> |
addEntry(K key,
Processor<IN,OUT> processor)
Add an entry to the processor map
|
protected abstract Function<IN,K> |
f()
Provide the function to compute a key out of an input
|
Processor<IN,OUT> |
getProcessor()
Build the resulting processor from this map selector
|
ProcessorMap<K,IN,OUT> |
setDefaultProcessor(Processor<IN,OUT> defaultProcessor)
Set the default processor if no matching key is found
|
public final ProcessorMap<K,IN,OUT> addEntry(K key, Processor<IN,OUT> processor)
key
- the key to match againstprocessor
- the processor for that keyProcessorBuildError
- either the key or the processor are nullpublic final ProcessorMap<K,IN,OUT> setDefaultProcessor(Processor<IN,OUT> defaultProcessor)
defaultProcessor
- the default processorProcessorBuildError
- processor is nullpublic final Processor<IN,OUT> getProcessor()
The resulting processor is immutable: reusing a map builder after getting the processor by calling this method will not alter the processor you grabbed.
ProcessorBuildError
- the function (provided by f()
) is
nullCopyright © 2013. All Rights Reserved.