Communication between activities within a request is done via pipes (created by the engine) that link activities together. Blocks of data are passed through these pipes from producer to consumer. These pipes are made available to an activity via the context and are retrieved when the activity is initialised. A pipe implements the uk.org.ogsadai.engine.BlockReader and uk.org.ogsadai.engine.BlockWriter interfaces, used by the consumer and producer respectively. Any given activity must use a pipe as either as a BlockReader or a BlockWriter.
The blocks of data that activities pass between them are represented by Java objects. In consequence, any object in Java can be put into a BlockWriter for consumption by another activity. Currently there is no type checking done between activities. This means that it is possible to link two activities together that do not have a common data type that they understand, e.g. activity A provides org.w3c.dom.Element objects to activity B and B expects to be reading in ByteArray objects. This will result in a ClassCastException being thrown by the activity receiving the unknown type (activity B in this example). Each activity may do type checking, but this is not required. If a ClassCastException is generated the engine will catch it and allow the request to fail gracefully, returning a Response document containing the exception noted against the activity it occurred in.
There is currently no notion of block size beyond that which an activity imposes itself. To elaborate, if a query activity defines a block to be one row of output from some result set obtained from a relational database then a block is one row. If that activity has a configuration option to set the block size to ten rows then a block is ten rows. However, both the single row and the ten rows block sizes will be handled in exactly the same way by the engine. They are both passed between activities as a single Java object by the engine. There is no mechanism provided for the consumer to find out the block size that the producer was using.
BlockWriters are used by activities to write blocks (Objects) to an output. A BlockWriter normally is one side of a pipe; the other side of which is a BlockReader.
BlockWriter exposes the two methods:
public void put(Object) public void close()
To write an object to an output, simply pass it to the put(Object) method. Once there is nothing more to write the pipe should be closed using the close() method, thereby notifying any consumers of the output that there are no more blocks.
BlockReaders are used by activities to read blocks from an input. The status of this class (either open for reading or closed for reading) will track the status of the BlockWriter with which it is paired, if any. The class exposes only one method:
public Object next() throws NoSuchElementException
The next() method returns the next block from its input. What constitutes a block is arbitrary and is determined by whatever produced the Object that has been published via the BlockReader. If the end of the input is reached and there are no more blocks to consume then a NoSuchElementException is thrown.
A call to next() may block the calling thread until the source has produced a block to be consumed. Blocking is the norm rather than the exception because the logic governing the extent of internal caching is not yet implemented.
| Back: The Activity Execution Context | Up: How Activities Work | Next: The Life-cycle of an Activity During Execution of a Perform Document |
| © International Business Machines Corporation, 2004. | © The University of Edinburgh, 2004. |