7.5 Event Handling

Each Flow has the ability to execute callbacks via an event listener. This ability is useful when an external application needs to be notified that a Flow has started, halted, completed, or the Flow has thrown an exception.

For instance, at the completion of a flow that runs on an Amazon EC2 Hadoop cluster, an Amazon SQS message can be sent to notify another application to fetch the job results from S3 or begin the shutdown of the cluster.

Flows support event listeners through the cascading.flow.FlowListener interface, which supports four events:

onStarting

The onStarting event is fired when a Flow instance receives the start() message.

onStopping

The onStopping event is fired when a Flow instance receives the stop() message.

onCompleted

The onCompleted event is fired when a Flow instance has completed all work, regardless of success or failure. If an exception was thrown, onThrowable will be fired before this event.

onThrowable

The onThrowable event is fired if any internal job client throws a Throwable type. This throwable is passed as an argument to the event. onThrowable should return true if the given throwable was handled, and should not be rethrown from the Flow.complete() method.

Copyright © 2007-2012 Concurrent, Inc. All Rights Reserved.