Project 4

In this project we will try to reuse as many components and ideas of the PIPES toolkit as possible. The goal is to construct a pipeline similar to the one constructed in Project 3:

where:

nums.txt = a text file containing some numbers
f1 = FileInputFilter
f2 = Square filter
f3 = IsEven filter
f4 = Accum filter
f5 = FileOutputFilter
sums.txt = a text file containing the output of f5

The main difference is that each filter runs in its own Java virtual machine (JVM), and the out pipe of filter fi is connected to the in pipe of filter fi+1 using a socket. In addition, each filter (except for the FileInputFilter) is equipped with its own server socket, which listens at a unique port for connection requests from other filters.

This program has no user interface. The user first creates the input file (nums.txt) containing numbers and white spaces using an ordinary text editor. Next, the user opens five Windows or UNIX console windows. Working from left to right, the users starts each filter:

console-5> java FileOutputFilter 4444 sums.txt

console-4> java Accum 5555 4444

console-3> java IsEven 6666 5555

console-2> java Square 7777 6666

console-1> java FileInputFilter nums.txt 7777

The basic command line syntax is:

console> java FilterClass myPort outPort

This starts a filter that is both a client and a server. As a server, it listens for clients using a server socket associated with port number myPort. When it receives a request, it spawns a thread to receive tokens from the client. As a client, it sends a connection request to the filter/server listening at port number outPort. This connection results in a socket that can be used to send tokens to the server.

Hints:

It might be a good idea to think of filters as the request handlers in the simple server framework. In this case it might be possible to create a generic server class similar to the one used by the framework. The command line might look like this:

console> java Server FilterClass myPort outPort

The Server constructor uses the name of the filter class to determine the request handler type.