Complete both of the following problems:
Problem 1: For this problem, you will implement a message queue in your language of choice. There are two kinds of messages that can be sent to the Queue "QueryMsg" and "ReplyMsg". A user should be able to add messages to the Queue or remove messages from the Queue (assume the queue is FIFO).
What you need to implement:
A class called MessageQueue that stores the messages it gets in
a Vector (or similar class). The Vector class (already available in Java.util and the
STL etc.) implements an array with dynamic size. The MessageQueue will need to
implement methods to manipulate the queue (e.g. addMsg, popMsg, isEmpty
etc.). Do not use the standard Queue class. Instead, you must implement queue
manipulation methods yourself.
A base class called Message and subclasses : QueryMsg and
ReplyMsg.
Include the ability (implementation and test code) to respond to a particular QueryMsg with a particular ReplyMsg. In this case, there are multiple queue writers - one that adds QueryMsg's, and another that responds to a QueryMsg with a ReplyMsg. The QueryMsg replies should be made in FIFO fashion (i.e. reply to the oldest query first). This is the start of a "distributed" message queue that uses a simple interprocess communication mechanism so that one process can send a message to another process over that means.
The queue is, in general, a FIFO, but allow a client that 'sends' a QueryMsg to be able to get the ReplyMsg corresponding to their QueryMsg. The ReplyMsg may not be the oldest message in the queue, but the client should still be able to get it out of the queue if it's anywhere in the queue. In this way, your queue must support more than the standard FIFO methods.
Test your program by using the message queue to send and receive a couple of messages. Include tests to reply to a query, showing that the reply can be retrieved out of order.
Problem 2: You will implement a Pipes and Filter pattern for this problem. A Filter typically either feeds input to the Pipe or reads from the Pipe and manipulates the data. In this case, there are two filters: the first one simply sends data into a pipe and the second filter reads off the pipe and converts the data to UPPER CASE.
What you need to implement:
Pipe class which accepts input from a filter. A Filter interface
that is implemented by all filters. Two particular filters, the WriteFilter,
and CapsFilter as described above.