CMSC 433 - Project 5
Redoing Project 3 - Java Threads
 Due April 24, 6:00PM

Almost everyone had a very difficult time with Project 3, the software pipe and filter architecture that was implemented using many threads.  To help in understanding how that project is supposed to work, you will re-implement each part of that project in a sequence, building up the entire project from its constituent parts.  In the end, the project will have the identical functionality of Project 3, so see the specification of that project for the details of the overall system architecture.  For this project, you will implement the parts of Project 3 in 5 steps:

  1. FilterBufferImpl - build the class that implements (in the Java sense) the FilterBuffer interface.  Test code and info on how to run it is in this file.
  2. FilterImpl, with one simple computation thread called PassThrough - build the class that implements the Filter interface, and write one computation thread that reads characters from its input stream and writes them unchanged to its output stream. Test code and info on how to run it is in this file.
  3. Connect two FilterImpl objects, each of which has a PassThrough computation thread - build an application that connects two PassThrough filters in a pipeline.  Test code and info on how to run it is in this file.
  4. Text processing - build the text processing application from Project 3, with three types of filter: replace, unique and tail.  More info on testing this will be coming soon.  For now, use Text.java from Project 3, with your own input data.
  5. Sieve of Erastothenes - build the prime number generator application from Project 3, with two types of filter: generate and sieve.  Use Erast.java from Project 3, for now with inputs 25 and 100 (2 separate runs).

Here's the additional info on testing parts 4 & 5.  Testing for each of the text and sieve filters is described in this text file, with the Java driver code in this file.  For the text filters, you have to supply input text.  The drivers for running the filters in combination are still Text.java and Erast.java .  The only change from above is that you should also run Erast with an input of 500, to test if your code works properly when it generates a large number of threads.

Grading

Test code for each of the five parts of the project is given above, and that will be exactly the code that will be used to grade your project.  You should test the parts of your project in the sequence described above, making sure that your code works properly for each part before moving on to the next part.  Each of  the 5 parts is worth 20 points (no commentary for this project), and you can only get credit for a part of the project if all previous parts work (e.g., if parts 1 and 2 work, but part 3 doesn't, you can't get credit for parts 4 and 5).

Implementation details

Here again are the interfaces for the Filter and FilterBuffer interfaces, with corresponding FilterImpl and FilterBufferImpl classes, that you must write:

public interface Filter { 
void setConnection(java.io.Reader in, java.io.Writer out);
java.io.Reader getInputConnection();
java.io.Writer getOutputConnection();
FilterBuffer getInputBuffer();
FilterBuffer getOutputBuffer();
void startFilter(); // start computing 
}
public class FilterImpl implements Filter {
FilterImpl(java.io.Reader in, java.io.Writer out, int maxReadBufSize, int maxWriteBufSize, Runnable compute);
}
public interface FilterBuffer { 
char[] read (); // returns current contents of buffer and clears it. Returns a zero-length array if its internal buffer is empty and the FilterBuffer has been closed
void write(char[] str) throws bufTooSmallException; // write str to buffer if str.length is less than maxBufferSize, otherwise throws exception
int getMaxBufferSize(); 
void close(); // informs the FilterBuffer that no more data will be written to it
void flush(); // doesn't return until the buffer is empty
}
public class FilterBufferImpl implements FilterBuffer {
FilterBufferImpl(int maxSize);
}

Debugging

You do not have to implement logging of thread start and exit events as in Project 3.  However, that code may be useful for debugging your classes, so use it as needed.  But do not include any logging code in your submissions (comment it out in the files you submit).

Web Accessibility