public final class GracefulShutdownMonitor extends java.lang.Object implements OperatorStateMonitor
Modifier and Type | Field and Description |
---|---|
private static long |
DEFAULT_DELAY |
private long |
delay |
private java.util.Collection<GracefulShutdownListener> |
listeners
All listeners that watch the operators/selectors in the network
|
private java.util.concurrent.atomic.AtomicBoolean |
notificationArrivedFlag
Indicates, whether some activity has been reported since last time
|
private DataflowVariable<java.lang.Boolean> |
result
The final latch that indicates the network has been shutdown
|
private boolean |
shutdownFlag
Indicates whether shutdown has been initialized
|
Constructor and Description |
---|
GracefulShutdownMonitor()
Uses the default timer delay
|
GracefulShutdownMonitor(long delay)
Allows to use a customized delay
|
Modifier and Type | Method and Description |
---|---|
private boolean |
checkWhetherAnyEventsHaveArrived()
Checks the notification flag whether there has been some activity since last timer run.
|
(package private) void |
onTimer()
Checks, whether the network is no longer active.
|
void |
registerProcessorListener(GracefulShutdownListener listener)
Invoked by GracefulShutdownListeners, which listen on operators/selectors for lifecycle events, to get registered with the monitor.
|
private void |
schedule()
Clears the notification flag so as we know whether some activity happens between subsequent checks.
|
Promise<java.lang.Boolean> |
shutdownNetwork()
Initializes the shutdown process.
|
void |
stateChanged()
Invoked whenever a processor changes state
|
private static final long DEFAULT_DELAY
private final long delay
private boolean shutdownFlag
private final java.util.concurrent.atomic.AtomicBoolean notificationArrivedFlag
private final DataflowVariable<java.lang.Boolean> result
private final java.util.Collection<GracefulShutdownListener> listeners
public GracefulShutdownMonitor()
public GracefulShutdownMonitor(long delay)
delay
- A timeout in milliseconds to wait between two subsequent polls on processors' state.
Lower values will reduce the wait time for network shutdown,
but maz have impact on the performance when the shutdown process gets initialized.public void stateChanged()
stateChanged
in interface OperatorStateMonitor
public void registerProcessorListener(GracefulShutdownListener listener)
registerProcessorListener
in interface OperatorStateMonitor
listener
- The listener to registerpublic Promise<java.lang.Boolean> shutdownNetwork()
void onTimer()
private boolean checkWhetherAnyEventsHaveArrived()
private void schedule()