uk.org.ogsadai.activity
Class ActivityPipelineRequestComponent

java.lang.Object
  |
  +--uk.org.ogsadai.activity.ActivityPipelineRequestComponent
All Implemented Interfaces:
RequestComponent

public class ActivityPipelineRequestComponent
extends java.lang.Object
implements RequestComponent

A RequestComponent that consists of an activity or a pipeline of connected activities. In the case of a pipeline of activities, the activities will be processed simultaneously, with data streaming from one end of the pipeline to the other when the process method is invoked.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement.
private static DAILogger LOG
          Logger object for logging in this class.
private  java.util.List mActivities
          A list of the activities contained in the pipeline.
private  ActivityContext mContext
          The context of the activities in the pipeline.
private  ObserverActivity[] mObserverActivities
          Internal activities to observe status of activities driven by external outputs.
private  ResponseBuilder mResponseBuilder
          Builder used for assembling parts of the response document.
private  ResultActivity[] mResultActivities
          Internal activities to read data from unconnected internal outputs.
 
Constructor Summary
ActivityPipelineRequestComponent()
          Constructs an ActivityPipelineRequestComponent.
 
Method Summary
 void add(RequestComponent child)
          Adds a child to a composite component.
 void addActivity(Activity activity)
          Adds the specified activity to this activity pipeline.
private  void buildResponse()
          Assembles the parts of the response document corresponding to each activity's status and result data.
private  void checkForErrors()
          Checks whether there has been an error while processing the pipeline.
 java.util.List children()
          Returns a non-mutable list of the children of this RequestComponent.
 boolean containsActivity(java.lang.String activityName)
          Returns true if the specified activity is contained in this pipeline.
private  void createInternalActivities()
          Creates some special internal activities that are needed for processing the activities contained in the pipeline.
 boolean generatesResultData()
          Indicates whether or not this component will generate any result data.
private  Activity[] getAllActivities()
          Gets an array of all the activities, internal and external.
private  java.util.List getEndPointActivities()
          Gets the end-point activities, both internal and external, that will drive the execution of the request.
private  java.util.List getExternalOutputActivities()
          Returns an array of the activities with external outputs.
private  java.lang.String[] getUnconnectedOutputs()
          Returns an array of the unconnected outputs from the activites contained in the pipeline.
 void initialise(ActivityContext context, Session session, ResponseBuilder responseBuilder)
          Initialises the component.
private  void prepareActivities(ActivityContext activityContext, Session session)
          Prepares the activities for processing.
 void process(ActivityContext context, ResponseBuilder responseBuilder)
          Processes the component.
 void terminate()
          Terminates the processing of the request component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement.

See Also:
Constant Field Values

LOG

private static final DAILogger LOG
Logger object for logging in this class.


mActivities

private final java.util.List mActivities
A list of the activities contained in the pipeline.


mResultActivities

private ResultActivity[] mResultActivities
Internal activities to read data from unconnected internal outputs.


mObserverActivities

private ObserverActivity[] mObserverActivities
Internal activities to observe status of activities driven by external outputs.


mContext

private ActivityContext mContext
The context of the activities in the pipeline.


mResponseBuilder

private ResponseBuilder mResponseBuilder
Builder used for assembling parts of the response document.

Constructor Detail

ActivityPipelineRequestComponent

public ActivityPipelineRequestComponent()
Constructs an ActivityPipelineRequestComponent. The activities contained in the pipeline are added using repeated invocations of the addActivity method.

Method Detail

initialise

public void initialise(ActivityContext context,
                       Session session,
                       ResponseBuilder responseBuilder)
                throws RequestSpecificationException,
                       RequestExecutionException
Description copied from interface: RequestComponent
Initialises the component. After this method has been returned the generatesResultData method must operational.

Specified by:
initialise in interface RequestComponent
Parameters:
context - The context for the request
session - The session for the request
responseBuilder - The response builder for assembling the response document
Throws:
RequestSpecificationException - If there is an initialisation problem caused by incorrect information in the request.
RequestExecutionException - If a problem occurs during initialisation that is not caused by incorrect information in the request.

process

public void process(ActivityContext context,
                    ResponseBuilder responseBuilder)
             throws RequestSpecificationException,
                    RequestExecutionException
Description copied from interface: RequestComponent
Processes the component. If this is a composite component, then any child components will be processed recursively. Wherever possible an implementation should be coded in such a way that the processing can be terminated prematurely by an invocation of the terminate method by another thread. Hence, when this method returns processing will be either complete or terminated.

Specified by:
process in interface RequestComponent
Parameters:
context - The context for the request
responseBuilder - The response builder for assembling the response document during processing
Throws:
RequestExecutionException - If a problem occurs during processing that is not caused by incorrect information in the request.
RequestSpecificationException - If there is a processing problem caused by incorrect information in the request.

getEndPointActivities

private java.util.List getEndPointActivities()
Gets the end-point activities, both internal and external, that will drive the execution of the request.

Returns:
Activity objects.

prepareActivities

private void prepareActivities(ActivityContext activityContext,
                               Session session)
                        throws RequestSpecificationException,
                               RequestExecutionException
Prepares the activities for processing. This is achieved by setting their context and invoking their initialise methods.

Parameters:
activityContext - Current activity context.
session - The session for the request
Throws:
RequestSpecificationException - If any activity contains incorrect parameters provided by a client.
RequestExecutionException - If some internal problem arises during execution.

createInternalActivities

private void createInternalActivities()
                               throws RequestExecutionException
Creates some special internal activities that are needed for processing the activities contained in the pipeline. Two types of internal activity are needed. Firstly, ResultActivity objects which read the result data generated by the pipeline. Secondly, ObserverActivity objects which monitor the status of any activities which are driven by external outputs to determine when they are complete.

Throws:
RequestExecutionException - If some internal problem arises during execution.

getUnconnectedOutputs

private final java.lang.String[] getUnconnectedOutputs()
Returns an array of the unconnected outputs from the activites contained in the pipeline.

Returns:
names of unconnected outputs.

getExternalOutputActivities

private final java.util.List getExternalOutputActivities()
Returns an array of the activities with external outputs.

Returns:
Activity objects.

checkForErrors

private void checkForErrors()
Checks whether there has been an error while processing the pipeline. If so, then the status of each activity in the request is set to ERROR TODO - review and devise better approach.


buildResponse

private void buildResponse()
Assembles the parts of the response document corresponding to each activity's status and result data. The result data is read from the internal ResultActivity objects.


getAllActivities

private Activity[] getAllActivities()
Gets an array of all the activities, internal and external.

Returns:
all the activities.

add

public void add(RequestComponent child)
Description copied from interface: RequestComponent
Adds a child to a composite component. Note that an empty implementation of this method should be provided for any leaf components.

Specified by:
add in interface RequestComponent
Parameters:
child - The child RequestComponent

children

public java.util.List children()
Description copied from interface: RequestComponent
Returns a non-mutable list of the children of this RequestComponent. If this component is a leaf and not a composite then java.util.Collections.EMPTY_LIST should be returned.

Specified by:
children in interface RequestComponent
Returns:
a java.util.List containing any children.

addActivity

public void addActivity(Activity activity)
Adds the specified activity to this activity pipeline.

Parameters:
activity - The Activity to add to this pipeline

containsActivity

public boolean containsActivity(java.lang.String activityName)
Returns true if the specified activity is contained in this pipeline.

Parameters:
activityName - The name of the activity
Returns:
true if the activity is contained in the pipeline, false otherwise

generatesResultData

public boolean generatesResultData()
Description copied from interface: RequestComponent
Indicates whether or not this component will generate any result data. This can only be invoked after the initialise method has returned. This method is used by the engine to determine whether to process a request synchronously or asynchronously.

Specified by:
generatesResultData in interface RequestComponent
Returns:
true if so, false otherwise

terminate

public void terminate()
Description copied from interface: RequestComponent
Terminates the processing of the request component. When this method returns, any threads and other resources associated with the processing of this request must be finished with.

Specified by:
terminate in interface RequestComponent