public class GracefulShutdownListener extends DataflowEventAdapter
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicInteger |
activeForks |
private boolean |
collectingMessages |
private java.util.concurrent.atomic.AtomicLong |
messagesInChannels |
private OperatorStateMonitor |
monitor |
private DataflowProcessor |
processor |
private boolean |
shutdownFlag |
Constructor and Description |
---|
GracefulShutdownListener(OperatorStateMonitor monitor)
Hooks hooks the shared monitor
|
Modifier and Type | Method and Description |
---|---|
void |
afterRun(DataflowProcessor processor,
java.util.List<java.lang.Object> messages)
Enters an idle state, so a notification needs to be sent to the monitor.
|
java.util.List<java.lang.Object> |
beforeRun(DataflowProcessor processor,
java.util.List<java.lang.Object> messages)
Entering a different non-idle state, so a notification needs to be sent to the monitor.
|
java.lang.Object |
controlMessageArrived(DataflowProcessor processor,
DataflowReadChannel<java.lang.Object> channel,
int index,
java.lang.Object message)
Entering a non-idle state, so a notification needs to be sent to the monitor.
|
private void |
fireEvent()
If shutdown is in progress, we'll notify the monitor
|
(package private) void |
initiateShutdown()
Starts the shutdown phase by turning shutdownFlag on
|
boolean |
isIdle()
A quick check on, whether the operator/selector is in the Idle state
|
boolean |
isIdleAndNoIncomingMessages()
A more sophisticated test for being Idle
|
java.lang.Object |
messageArrived(DataflowProcessor processor,
DataflowReadChannel<java.lang.Object> channel,
int index,
java.lang.Object message)
Entering a non-idle state, so a notification needs to be sent to the monitor.
|
void |
registered(DataflowProcessor processor)
When hooked into an operator/selectors, the listener will tap to its input channels to get notified about all incoming messages.
|
(package private) void |
terminateProcessor()
Used by the monitor to terminate the underlying operator/selector
|
afterStart, afterStop, customEvent, messageSentOut, onException
private boolean collectingMessages
private final java.util.concurrent.atomic.AtomicInteger activeForks
private final OperatorStateMonitor monitor
private DataflowProcessor processor
private volatile boolean shutdownFlag
private final java.util.concurrent.atomic.AtomicLong messagesInChannels
public GracefulShutdownListener(OperatorStateMonitor monitor)
monitor
- The monitor that will orchestrate the shutdownpublic void registered(DataflowProcessor processor)
registered
in interface DataflowEventListener
registered
in class DataflowEventAdapter
processor
- The reporting dataflow operator/selectorpublic java.lang.Object messageArrived(DataflowProcessor processor, DataflowReadChannel<java.lang.Object> channel, int index, java.lang.Object message)
messageArrived
in interface DataflowEventListener
messageArrived
in class DataflowEventAdapter
processor
- The reporting dataflow operator/selectorchannel
- The input channel holding the messageindex
- The index of the input channel within the operatormessage
- The incoming messagepublic java.lang.Object controlMessageArrived(DataflowProcessor processor, DataflowReadChannel<java.lang.Object> channel, int index, java.lang.Object message)
controlMessageArrived
in interface DataflowEventListener
controlMessageArrived
in class DataflowEventAdapter
processor
- The reporting dataflow operator/selectorchannel
- The input channel holding the messageindex
- The index of the input channel within the operatormessage
- The incoming messagepublic java.util.List<java.lang.Object> beforeRun(DataflowProcessor processor, java.util.List<java.lang.Object> messages)
beforeRun
in interface DataflowEventListener
beforeRun
in class DataflowEventAdapter
processor
- The reporting dataflow operator/selectormessages
- The incoming messagespublic void afterRun(DataflowProcessor processor, java.util.List<java.lang.Object> messages)
afterRun
in interface DataflowEventListener
afterRun
in class DataflowEventAdapter
processor
- The reporting dataflow operator/selectormessages
- The incoming messages that have been processedprivate void fireEvent()
final void initiateShutdown()
public final boolean isIdle()
public final boolean isIdleAndNoIncomingMessages()
final void terminateProcessor()