6.4 Event Handling

Each Flow, has the ability to execute callbacks via an event listener. This is very useful when external application need to be notified that a Flow has completed.

A good example is when running Flows on an Amazon EC2 Hadoop cluster. After the Flow is completed, a SQS event can be sent notifying another application it can now fetch the job results from S3. In tandem, it can start the process of shutting down the cluster if no more work is queued up for it.

Flows support event listeners through the cascading.flow.FlowListener interface. The FlowListener interface supports four events,onStarting, onStopping,onCompleted, and onThrowable.

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 whether if was success or failed. If there was a thrown exception, 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.

FlowListeners are useful when external systems must be notified when a Flow has completed or failed.

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