Executing Activities in the Engine

This page gives an overview of the engine which is used by OGSA-DAI services to execute Perform documents.

Engine Architecture for Activities and Handlers

Engine Architecture for Activities and Handlers

The above figure shows the general structure created by the engine when processing a Perform document (the components shown are limited to those which are related to or impact upon implementation of activities). The main points are:

To illustrate this, the Perform document below provides some hard-coded string data and passes that into a stringTokenizer. No delivery is specified so the results will be delivered back to the client in a synchronous fashion:

<perform
  xmlns="http://ogsadai.org.uk/namespaces/2005/03/types">
  <dataStore name="data">
    <item>my-data</item>
    <itemCursor name="cursor"/>
  </dataStore>
  <stringTokenizer name="tokenizer">
    <sourceString from="cursor"/>
    <tokens name="tokens"/>
  </stringTokenizer>
</perform>

The Perform document above would result in a structure identical to that shown in the foregoing figure. The following figure labels the activities and their handlers with the types that would be used when processing this Perform document.

Structure of an Example Request

Structure of an Example Request

The engine's responsibilities are split into four main areas:

  1. Processing the Perform document to generate the structure shown in the foregoing figures.
  2. Initiating execution of the activities (see below).
  3. Monitoring the status of the activities within the Perform document (see below).
  4. Returning a response to the client within a Response document.

Execution

The way in which an engine executes a request is simple. All handlers registered within a specific section of the context (uk.org.ogsadai.engine.EngineImpl.OUTPUTS) are told to initiate processing (a call is made to the processBlock() method of the handler). This is the same way that a pipe causes its source to initiate processing, if required. When using the default activity handlers, any activity that does not publish any outputs will be a member of this set, and so will be executed directly by the engine.

Activities that do publish outputs will only be executed when a running activity requests a block from one of their outputs. At this point, the pipe will call processBlock() on the associated activity handler to initiate processing.

Execution ends when all activities have set their status to either ERROR or COMPLETE. Once all of the activities in the output set have completed successfully, if other activities are still running the engine will terminate the request to force those activities still outstanding to finish.

Status Monitoring

This stage can occur either before or after a response is returned to the client. If the client request is asynchronous in nature (i.e. the results from the request are being delivered to a third party) then the response is sent to the client once the engine has successfully completed execution of the request. The response seen by the client in this case contains only the status of the activities in the request, and will only contain additional data if there was an error prior to execution of the request.

If the request is synchronous then the status of the activities is monitored in the same way, but the engine will only return a response to the client once the request has terminated, either successfully, or because of an error condition. If the request completed successfully then the data will be returned to the client within the response. If the request failed then any data produced prior to the failure will be discarded and only the error will be returned to the client. In the case of an error, the first error to be reported is flagged by the engine so that if it causes a cascade of errors the root cause is easy to locate.

Any status change reported by an activity is published via a RequestStatus property.