Class SplitGateProcessorWorker<X,Y>
- Type Parameters:
X- the type of the input message bodyY- the type of the output message body
- All Implemented Interfaces:
Measureable<SplitGateProcessorWorker.Metrics>,ProcessorWorker<Message<X>,,Message<Y>> MeasuredProcessorWorker<Message<X>,Message<Y>, SplitGateProcessorWorker.Metrics>
- Direct Known Subclasses:
SimpleSplitGateProcessorWorker
ProcessorWorker that implements a gating "split-join" pattern over messages:
- Each input message is passed through a
splitterFunctionthat produces zero or more output messages. - If the splitter produces no messages, the input message (after mapping) is forwarded immediately downstream.
- If the splitter produces one or more messages, the input message is held back.
- The split messages are sent downstream immediately and tracked for acknowledgement.
- Once all split messages are acknowledged (acked or nacked), the original message (after mapping) is released downstream.
This pattern is useful when downstream logic depends on all child messages being processed before the parent can proceed, for example not acknowledging message until all its children have themselves been acknowledged.
This class is loosely inspired by the Enterprise Integration Patterns "Splitter" and "Aggregator". In the EIP framework, this pattern would be implemented using a stateful message store that tracked all children messages a little more explicitly, perhaps using control messages instead of data messages. This class simply tracks all child messages in memory, since workers always runin in a single process.
The mapperFunction is applied to the original message to produce the final representation
of the parent message that will be emitted after all child messages are complete. This class also
exposes a gated metric to indicate how many parent messages are currently waiting on
child acknowledgements.
The splitter messages' message IDs are derived from the parent message ID, so that they can be easily be correlated with their parent. The original message's attributes are copied to the split messages.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSplitGateProcessorWorker(Function<X, Y> mapperFunction, Function<X, Collection<Y>> splitterFunction) -
Method Summary
Modifier and TypeMethodDescriptionvoid
-
Constructor Details
-
SplitGateProcessorWorker
-
-
Method Details
-
process
- Specified by:
processin interfaceProcessorWorker<X,Y> - Throws:
InterruptedException
-
checkMetrics
- Specified by:
checkMetricsin interfaceMeasureable<X>
-
flushMetrics
- Specified by:
flushMetricsin interfaceMeasureable<X>
-