uk.org.ogsadai.activity
Class IterativeActivity

java.lang.Object
  extended by uk.org.ogsadai.activity.ActivityBase
      extended by uk.org.ogsadai.activity.IterativeActivity
All Implemented Interfaces:
Activity
Direct Known Subclasses:
ControlledRepeatActivity, EchoActivity, ListConcatenateActivity, ListControlledRepeatActivity, ListRandomSplitActivity, ListRemoveActivity, MetadataRenameActivity, PipelinedTupleJoinActivity, RandomSplitActivity, ReadFromDataSinkActivity, SplitActivity, StringConcatenateActivity, TeeActivity, TupleJoinActivity, TupleProductActivity, TupleProjectionActivity, WriteToDataSourceActivity

public abstract class IterativeActivity
extends ActivityBase

An abstract activity base class that provides a template for a simple iterative processing algorithm. This is an example of the template design pattern. The skeleton for the iterative processing algorithm is defined in the process() method. Several steps of the algorithm are deferred to concrete sub-classes.

The processing algorithm has the following form:

 preprocess();
 WHILE more processing to do
     processIteration();
 END-WHILE
 postprocess();
 cleanUp();
 
The methods shown in italics must be implemented by a concrete sub-class. These comprise the processing stage of the algorithm. The cleanUp() method may optionally be overridden. If any exceptions are raised during the processing stage, execution jumps straight to the cleanUp() method, before the exception is thrown onwards.

Author:
The OGSA-DAI Project Team

Field Summary
 
Fields inherited from class uk.org.ogsadai.activity.ActivityBase
mContracts
 
Constructor Summary
IterativeActivity()
           
 
Method Summary
protected  void cleanUp()
          Cleans up the activity.
protected  void iterativeStageComplete()
          Invoked by a subclass to indicate that the iterative stage of processing is complete.
protected abstract  void postprocess()
          Performs any post-processing required after the iterative part of the activity processing has completed.
protected abstract  void preprocess()
          Performs any pre-processing required before the iterative part of the activity processing commences.
 void process()
          Processes the activity to completion.
protected abstract  void processIteration()
          Performs an iteration of the activity processing.
 
Methods inherited from class uk.org.ogsadai.activity.ActivityBase
addInput, addOutput, close, closeDueToError, getActivityContracts, getActivityDescriptor, getInput, getInput, getInputs, getOutput, getOutput, getOutputs, hasInput, hasOutput, removeInput, setActivityDescriptor, toString, validateInput, validateInputs, validateOutput, validateOutputs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IterativeActivity

public IterativeActivity()
Method Detail

process

public final void process()
                   throws ActivityUserException,
                          ActivityProcessingException,
                          ActivityTerminatedException
Description copied from interface: Activity
Processes the activity to completion. This method blocks until the processing is complete.

Throws:
ActivityUserException - If the settings specified by the user prevent processing from completing.
ActivityProcessingException - If an internal error prevents processing from completing.
ActivityTerminatedException - If activity processing is terminated at an intermediate stage. This occurs when the thread processing the activity is interrupted.

iterativeStageComplete

protected void iterativeStageComplete()
Invoked by a subclass to indicate that the iterative stage of processing is complete.


preprocess

protected abstract void preprocess()
                            throws ActivityUserException,
                                   ActivityProcessingException,
                                   ActivityTerminatedException
Performs any pre-processing required before the iterative part of the activity processing commences.

Throws:
ActivityUserException - if the settings specified by the user prevent processing from completing
ActivityProcessingException - if an internal error prevents processing from completing
ActivityTerminatedException - if activity processing is terminated at an intermediate stage

processIteration

protected abstract void processIteration()
                                  throws ActivityProcessingException,
                                         ActivityTerminatedException,
                                         ActivityUserException
Performs an iteration of the activity processing. During this the input blocks should be consumed and the output blocks produced.

Throws:
ActivityUserException - if the settings specified by the user prevent processing from completing
ActivityProcessingException - if an internal error prevents processing from completing
ActivityTerminatedException - if activity processing is terminated at an intermediate stage

postprocess

protected abstract void postprocess()
                             throws ActivityUserException,
                                    ActivityProcessingException,
                                    ActivityTerminatedException
Performs any post-processing required after the iterative part of the activity processing has completed. Note that this will not be be invoked if an error occurs during an earlier stage of processing.

Throws:
ActivityUserException - if the settings specified by the user prevent processing from completing
ActivityProcessingException - if an internal error prevents processing from completing
ActivityTerminatedException - if activity processing is terminated at an intermediate stage

cleanUp

protected void cleanUp()
                throws java.lang.Exception
Cleans up the activity. By default this method is empty. This may be overridden by subclasses to perform any additional clean-up required. An overriding implementation should also invoke the super class implementation using super.cleanUp().

This method will be invoked either after the postprocess() method returns successfully, or after an exception has occurred during the processing stage. Any further exceptions raised during clean-up will be logged rather than thrown upwards.

Throws:
java.lang.Exception - if an error occurs