Piped OsidList Pattern

A concurrent producer/consumer list — push elements, pull elsewhere.

Overview

A piped OsidList is a concurrent producer/consumer list. The producer pushes elements in with addOsidObject and signals completion with finish(); a single consumer pulls them out through the standard getNextOsidObject(). The two sides may run on different threads, handing off through an internal blocking queue.

If the producer hits a problem it calls error() instead of finish(); the exception surfaces on the consumer side as an OperationFailedException at the next read. available() reports the number of elements offered by the producer and not yet consumed — always safe to pass to getNextOsidObjects() without blocking. Assumes a single consumer thread.

Javadoc Reference

net.okapia.osid.streams.spi

Class Declaration Pattern

public final class PipedOsidObjectList
extends AbstractOsidObjectList
implements OsidObjectList

Constructor Pattern

PipedOsidObjectList()

No parameters. Construct the list, hand it to the consumer, and feed it from the producer thread.

Producer Pattern

public void addOsidObject(OsidObject element)
public void addOsidObjects(OsidObject[] elements)
public void addOsidObjectCollection(Collection<OsidObject> elements)
public void finish()

Signals that the producer has offered its last element. After finish() the consumer drains any remaining elements and then reaches end-of-list.

public void error(OsidException e)
ParameterTypeDescription
e OsidException the failure to raise on the consumer side as an OperationFailedException at its next read