public final class GracefulShutdownMonitor extends java.lang.Object
The monitor will orchestrate a graceful shutdown, when its shutdownNetwork() method is called. For this mechanism to work, all selectors/operators in the network have to have their own instance of GracefulShutdownListener added and these listeners have to share the same GracefulShutdownMonitor instance. Each listener observes the activity in the input channels of its corresponding operator/selector. Upon graceful shutdown initialization, the listeners also start watching the state of their operators/selectors. The GracefulShutdownMonitor then repeatedly watches, whether listeners report activity in the operators. When the activity ceases, the monitor will poll all listeners about the state of their operator/selector and its input channels. If all listeners report no activity and no incoming messages, the monitor can safely terminate all operators.
Modifiers | Name | 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 |
Type | Name and description |
---|---|
private boolean |
checkWhetherAnyEventsHaveArrived() Checks the notification flag whether there has been some activity since last timer run. |
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 |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
All listeners that watch the operators/selectors in the network
Indicates, whether some activity has been reported since last time
The final latch that indicates the network has been shutdown
Indicates whether shutdown has been initialized
Uses the default timer delay
Allows to use a customized 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.Checks the notification flag whether there has been some activity since last timer run.
Checks, whether the network is no longer active. To reduce effect on system performance, cheap criteria are being checked first.
Invoked by GracefulShutdownListeners, which listen on operators/selectors for lifecycle events, to get registered with the monitor. The monitor will query these registered listeners about their respective operator/selector state when performing graceful shutdown.
listener
- The listener to registerClears the notification flag so as we know whether some activity happens between subsequent checks. Schedules the timer to run again after the delay set on the monitor.
Initializes the shutdown process. New listeners cannot be registered after this point. New messages should not enter the dataflow network from the outside, since this may prevent the network from terminating.
Invoked whenever a processor changes state
Copyright © 2008–2014 Václav Pech. All Rights Reserved.