org.codehaus.gpars

groovyx.gpars.dataflow.operator.component
[Java] Class GracefulShutdownMonitor

java.lang.Object
  groovyx.gpars.dataflow.operator.component.GracefulShutdownMonitor
All Implemented Interfaces:
OperatorStateMonitor

public final class GracefulShutdownMonitor

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.

Authors:
Vaclav Pech


Field Summary
private static long DEFAULT_DELAY

private long delay

private java.util.Collection listeners

private java.util.concurrent.atomic.AtomicBoolean notificationArrivedFlag

Uses the default timer delay

private DataflowVariable result

private boolean shutdownFlag

All listeners that watch the operators/selectors in the network

 
Constructor Summary
GracefulShutdownMonitor()

GracefulShutdownMonitor(long delay)

Invoked whenever a processor changes state

 
Method Summary
private boolean checkWhetherAnyEventsHaveArrived()

Checks the notification flag whether there has been some activity since last timer run.

void onTimer()

void registerProcessorListener(GracefulShutdownListener listener)

Initializes the shutdown process.

private void schedule()

Promise shutdownNetwork()

Checks, whether the network is no longer active.

void stateChanged()

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), 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()
 

Field Detail

DEFAULT_DELAY

private static final long DEFAULT_DELAY


delay

private final long delay


listeners

private final java.util.Collection listeners


notificationArrivedFlag

private final java.util.concurrent.atomic.AtomicBoolean notificationArrivedFlag
Uses the default timer delay


result

private final DataflowVariable result


shutdownFlag

private boolean shutdownFlag
All listeners that watch the operators/selectors in the network


 
Constructor Detail

GracefulShutdownMonitor

public GracefulShutdownMonitor()


GracefulShutdownMonitor

public GracefulShutdownMonitor(long delay)
Invoked whenever a processor changes state


 
Method Detail

checkWhetherAnyEventsHaveArrived

private boolean checkWhetherAnyEventsHaveArrived()
Checks the notification flag whether there has been some activity since last timer run.
Returns:
True, if events have been registered since last time, false otherwise.


onTimer

void onTimer()


registerProcessorListener

@java.lang.Overrideif (!shutdownFlag) {
public void registerProcessorListener(GracefulShutdownListener listener)
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.
Returns:
A Promise, which may be used to wait for or get notified about the shutdown success.


schedule

private void schedule()


shutdownNetwork

public Promise shutdownNetwork()
Checks, whether the network is no longer active. To reduce effect on system performance, cheap criteria are being checked first.


stateChanged

@java.lang.Overridelisteners.add(listener);
public void stateChanged()


 

Copyright © 2008–2013 Václav Pech. All Rights Reserved.