org.codehaus.gpars

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

java.lang.Object
  groovyx.gpars.dataflow.operator.DataflowEventAdapter
      groovyx.gpars.dataflow.operator.component.GracefulShutdownListener

public class GracefulShutdownListener
extends DataflowEventAdapter

Listens to an operator/selector and reports its state and activity to a GracefulShutdownMonitor, shared with other listeners.

Authors:
Vaclav Pech


Field Summary
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 Summary
GracefulShutdownListener(OperatorStateMonitor monitor)

Hooks hooks the shared monitor

 
Method Summary
void afterRun(DataflowProcessor processor, java.util.List messages)

Enters an idle state, so a notification needs to be sent to the monitor.

java.util.List beforeRun(DataflowProcessor processor, java.util.List messages)

Entering a different non-idle state, so a notification needs to be sent to the monitor.

java.lang.Object controlMessageArrived(DataflowProcessor processor, DataflowReadChannel 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

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 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.

void terminateProcessor()

Used by the monitor to terminate the underlying operator/selector

 
Methods inherited from class DataflowEventAdapter
afterRun, afterStart, afterStop, beforeRun, controlMessageArrived, customEvent, messageArrived, messageSentOut, onException, registered
 

Field Detail

activeForks

private final java.util.concurrent.atomic.AtomicInteger activeForks


collectingMessages

private boolean collectingMessages


messagesInChannels

private final java.util.concurrent.atomic.AtomicLong messagesInChannels


monitor

private final OperatorStateMonitor monitor


processor

private DataflowProcessor processor


shutdownFlag

private boolean shutdownFlag


 
Constructor Detail

GracefulShutdownListener

public GracefulShutdownListener(OperatorStateMonitor monitor)
Hooks hooks the shared monitor
Parameters:
monitor - The monitor that will orchestrate the shutdown


 
Method Detail

afterRun

@Override
public void afterRun(DataflowProcessor processor, java.util.List messages)
Enters an idle state, so a notification needs to be sent to the monitor.
Parameters:
processor - The reporting dataflow operator/selector
messages - The incoming messages that have been processed


beforeRun

@Override
public java.util.List beforeRun(DataflowProcessor processor, java.util.List messages)
Entering a different non-idle state, so a notification needs to be sent to the monitor.
Parameters:
processor - The reporting dataflow operator/selector
messages - The incoming messages
Returns:
The same set of messages that was passed in


controlMessageArrived

@Override
public java.lang.Object controlMessageArrived(DataflowProcessor processor, DataflowReadChannel channel, int index, java.lang.Object message)
Entering a non-idle state, so a notification needs to be sent to the monitor. Also, the received message must be removed from the temporary message cache (or added to it so that so that the not-yet-arrived notification from the channel can remove it).
Parameters:
processor - The reporting dataflow operator/selector
channel - The input channel holding the message
index - The index of the input channel within the operator
message - The incoming message
Returns:
The same object that was passed in as the last argument


fireEvent

private void fireEvent()
If shutdown is in progress, we'll notify the monitor


initiateShutdown

final void initiateShutdown()
Starts the shutdown phase by turning shutdownFlag on


isIdle

public final boolean isIdle()
A quick check on, whether the operator/selector is in the Idle state
Returns:
True, if the current state is Idle


isIdleAndNoIncomingMessages

public final boolean isIdleAndNoIncomingMessages()
A more sophisticated test for being Idle
Returns:
True, if the operator/selector state is Idle, there are no messages in the input channels and there are no messages in the intermediate state between having been removed from the channel and being accepted by the operator


messageArrived

@Override
public java.lang.Object messageArrived(DataflowProcessor processor, DataflowReadChannel channel, int index, java.lang.Object message)
Entering a non-idle state, so a notification needs to be sent to the monitor. Also, the received message must be removed from the temporary message cache (or added to it so that so that the not-yet-arrived notification from the channel can remove it).
Parameters:
processor - The reporting dataflow operator/selector
channel - The input channel holding the message
index - The index of the input channel within the operator
message - The incoming message
Returns:
The same object that was passed in as the last argument


registered

@Override
public 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. These incoming messages will be stored temporarily so as the listener can keep track of it until the message is passed to the operator/selector. The messageArrived() event handler will then remove the message from the temporary storage. However, it is not guaranteed that the channel reports an incoming message before the corresponding messageArrived() handler gets invoked. These cases are fine with respect to shutdown, however, we still need to take care of such situation in order to remove the message from teh temporary cache.
Parameters:
processor - The reporting dataflow operator/selector


terminateProcessor

final void terminateProcessor()
Used by the monitor to terminate the underlying operator/selector


 

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