20-CS-694 Advanced Programming Techniques Spring 2012
Homework Assignment 3 (alternate)

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI


Due: April 26, 2012 (submit instructions: here)

    Demand-driven architectures may be implemented by abstractions similar to class Stream which we developed in class. But the idea of Stream, as we discussed it, has quite a few limitations and must be extended to meet the needs of specific applications. This assignment calls for extending the Stream class in two ways:
  • Create a "collector" extention of the Stream class, call it CollectorStream, which provides the following service: a CollectorStream object gets tokens from several producers and notifies a single consumer when this is accomplished. A (threaded) Notifier class will be designed and a Notifier object will be sent via a constructor argument to an object of a subclass of the CollectorStream class. The collector stream will compute a result from all producers' results, and place that result in the notifier object. A consumer thread will wait on the notifier thread until the result is received and then take the result from the notifier and print it.

    Assume, to keep things simple, that the producers put doubles into their streams and the collector just adds those up, sets a value in the notifier, and sends it on its way.

    Try this:    

    Here are some classes that make use of the collector stream:
        TestCollector.java     Producer.java     Notifier.java     Stream.java     IntObject.java     Subscriber.java

  • Create a "gate" extension of the Stream class, call it GateStream, to provide the following service: requests for a single producer's tokens from multiple consumers will not be satisfied until a request is made by one particular consumer. The "particular" consumer is established through the argument of the producer's constructor.

    Try this:    

    Here are some classes that make use of the collector stream:
        TestGate.java     TestProducer.java     TestConsumer.java     MultiStream.java     ConnectEntry.java     ConnectionRefusedException.java