The Life-cycle of an Activity During Execution of a Perform Document

The engine defines three distinct phases in the lifecycle of an activity's lifecycle. These phases map directly onto methods defined in the uk.org.ogsadai.engine.Activity base class which activity implementations must sub-class:

  1. Construction - Activity(org.w3c.dom.Element).
  2. Initialisation - setContext(uk.org.ogsadai.common.Context).
  3. Processing and Output - processBlock().

When a Perform document is received by an OGSA-DAI service it is forwarded directly on to the engine for processing. This is done as follows:

  1. The document is validated against the XML Schema describing valid Perform documents.
  2. Any invocation context, such as the client's distinguished name and message context, is added to the execution context.
  3. For each activity in the Perform document, an instance of the associated activity class (defined by an activity mapping in an activity configuration document) is created using the contents of the element.
  4. The execution context is prepared:
    1. Pipes are created for inputs and/or outputs published by activities and are placed in the context.
    2. A dependency check is done to ensure that all inputs required by activities are present.
    3. Additional configuration of the context is performed.
  5. The instantiated activities are provided with the context within which they will execute.
  6. The engine executes the client's request.
  7. Either the results from the execution are delivered to the client, or the status of the request if the results are being delivered elsewhere.

If any of these steps fail then an error is returned to the client detailing what occurred and any subsequent processing of the request is terminated immediately. Any/all data produced by the request that has not yet been delivered is discarded.

The execution strategy used is an extremely simple pull mechanism - if an activity does not define any outputs the engine will repeatedly call the processBlock method of that activity. This will cause each activity in the dependency chain to have processBlock called on it as its consumer's request blocks its execution. There is a mechanism provided for pre-caching and buffering blocks between activities but the basic implementation does not provide the necessary logic to select if this should occur.

Construction

public Activity(org.w3c.dom.Element)

An activity is constructed using org.w3c.dom.Element passed into their constructor. This element will be extracted from a Perform document and will conform to the XML Schema associated with the activity via an activity mapping.

For most activities this Element will contain two distinct parts. One part is configuration information that is activity-specific, e.g. the public key a PGPEncryption activity should use. The other part supplies the names of the inputs and outputs for the activity. The XML Schema for the activity defines inputs that the activity can take and outputs that it can provide, but the names for both inputs and outputs are defined per request and so are provided within an each activity's element in a Perform document. These names are extracted by the engine and are required to permit construction of the pipes that link activities together. Publishing of inputs/outputs for use by the engine is done by putting the names of inputs and outputs into two String arrays, mInputs and mOutputs respectively, e.g.:

mInputs = new String[] { input };

The constructors of activities are permitted to throw two types of exceptions, both of which are relayed by the engine back to the user.

Non-OGSA-DAI exceptions which are thrown as a result of the logic contained within an activity's constructor should be wrapped up in either of the above types of exception, rather than being thrown from the constructor themselves. Special care should be taken to ensure that all java.lang.RuntimeExceptions are caught and re-packaged in an ActivitySystemException or an ActivityUserException.

Initialisation

public void setContext(org.uk.ogsadai.common.Context)

Initialisation of an activity prior to executing a request is done via a call to the activity's setContext(Context) method. This state occurs once the entire request has been pre-processed successfully.

Each of the activities in the request is initialised with the context to be used during execution. Within the setContext method the context should be considered read-only by the activity. This is stipulated to maintain the consistency of the context across all the activities involved in the request (there is no guaranteed initialisation order for activities so it is not possible to predict the behaviour resulting from altering the context at this point). If an activity must be able to modify the context it should be done by overriding the configureContext(Context) method.

The usual behaviour of an activity during initialisation is for it to retrieve its inputs and outputs (BlockReaders and BlockWriters respectively) from the context and store them within the activity for easy access during the processing/output phase. During initialisation an activity must not attempt to read from or write to any of the inputs and outputs provided in the context during initialisation.

Processing and Output

The activity design is based on a model where activities operate on blocks of data provided via a stream. An activity is thus expected to operate in an iterative fashion, the simplest case being where it pulls a block of data from an input, does some processing on the block and then publishes the result via its outputs for use by another activity. As a result, processing and output are considered to be one stage in an activity's lifecycle because the two are inextricably linked in the model.

This maps directly onto the processBlock() method. This method is called on an activity by the engine when the activity is required to do some processing. While it is not necessary for an activity to output a block as a result of every call to processBlock() that is nevertheless the expected behaviour (activities that provide no outputs are a special case). The method will continue to be called until a block has been output. For activities with more than one output the method will be called until a block has been written to the output that triggered the call.

If an error occurs within the logic of the processBlock() method which needs to be brought to the users attention, this can be achieved by the use of the setError(ActivityException) method. This causes processing of the activity to cease, so that the processBlock() method is not called again, and provides the user with the details of the error which occurred. Note that it is not permitted to raise an exception other than one which is a sub-type of ActivityException, so all other exceptions must be wrapped in either an ActivitySystemException or an ActivityUserException, as appropriate, along with an adequate description of why the exception occurred.