K
- the type of keys in the mapIN
- the input type of processorsOUT
- the output type of processorspublic final 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.
The Function
used to extract a key from an input is the only
argument of the constructor. It cannot be null.
Note that null keys are not allowed.
Constructor and Description |
---|
ProcessorMap(Function<IN,K> keyFunction)
Constructor
|
Modifier and Type | Method and Description |
---|---|
ProcessorMap<K,IN,OUT> |
addEntry(K key,
Processor<IN,OUT> processor)
Add an entry to the processor map
|
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 ProcessorMap(Function<IN,K> keyFunction)
keyFunction
- function to extract a key from an inputNullPointerException
- key function is nullpublic ProcessorMap<K,IN,OUT> addEntry(K key, Processor<IN,OUT> processor)
key
- the key to match againstprocessor
- the processor for that keyNullPointerException
- either the key or the processor are nullpublic ProcessorMap<K,IN,OUT> setDefaultProcessor(Processor<IN,OUT> defaultProcessor)
defaultProcessor
- the default processorNullPointerException
- processor is nullpublic 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.