KWIC Implemented with Pipe Filter Architectural Style

Pipe and Filter Systems in General

In a pipe and filter style each component has a set of input streams and a set of output streams. A component reads streams of data on its input streams, processes the data and writes the resulting data on its output streams. Hence components are termed filters. The connectors of this style merge the streams together, i.e., they transmit outputs of one filter to inputs of another filter. Hence the connectors are termed pipes.

General Pipe Filter Architecture

Among the important invariants of the style is the condition that filters must be independent entities: in particular, they should not share state with other filters. Another important invariant is that filters do not know the identity of their upstream and downstream filters. Thus, filters may not identify the components on the ends of their pipes.

Common specializations of this style include pipelines (see figure below), which restrict the topologies to linear sequences of filters; bounded pipes, which restrict the amount of data that can reside on a pipe; and typed pipes, which require that the data passed between two filters have a well-defined type.

Pipeline

The best-known examples of pipe and filter architectures are programs written in the Unix shell. Unix supports this style by providing a notation for connecting components (represented as Unix processes) and by providing run-time mechanisms for implementing pipes.

Architecture

Pipe and Filter KWIC system is composed of the following components:

Architecture

Pipes in KWIC system

Pipes in the KWIC system are represented as instances of the Pipe class. An instance of the Pipe class is a composition of two streams: an input and an output stream. Pipe class connects these two streams in the following way. The data that is written to the input stream is transmitted to the output stream. In this way these data become available for reading from the output stream.

The Pipe class encapsulates the input and output streams as its private instance variables and provide just a simple public interface for writing and reading data to a pipe object. Thus, clients simply write some data to a pipe object by calling its write method. This data becomes then available for other clients, which can call the read method of the pipe object to retrieve the data.

Pipe Class

There are few important properties of pipe objects:

Filters in KWIC System

Filters in the KWIC system are represented by an abstract class named Filter. An instance of Filter class is composed of:

Filter Class

The current implementation of the Filter class provides already the basic filter functionality. Thus, clients start the execution of the filter object by invoking its start method. In turn, this method starts the control thread, which consecutively invokes the filter's transform method.

In the current implementation the transform method is an abstract method, which means that subclasses of Filter class should provide a particular implementation for that specific filter object. For example, CircularShifter filter implements transform method in the following way. The lines retrieved from the input pipe are processed and circular shifts of those lines are made. Thereafter the produced shifts are written to the output pipe. Speaking more generally, subclasses of Filter class implement their transform methods in the following way: the data is retrieved from the input pipe, transformed (processed) and written out to the output pipe.

Filter objects may be combined into a typical producer/consumer scenario by simply sharing a pipe object. For example, we assign the output pipe of the first filter to the input pipe of the second filter. In that way whenever the first filter produces some data and writes it to its output pipe, this data is available for the second filter to consume it. Thus, we may combine a number of filters into a sequence (pipeline) to achieve the desired functionality of the system.

Pipeline in KWIC system

The current KWIC system utilizes a pipeline consisting of the following four filters:

All KWIC filters are of course subclasses of abstract Filter class. These relationships are depicted on the following class diagram:

KWIC

The four KWIC filters are connected by means of the following pipes:

The following figure shows the current pipeline including the pipe names:

KWIC Pipeline

Valid XHTML 1.0! Valid CSS!