Class Broker

Object
  extended byBroker
All Implemented Interfaces:
IBM, Runnable

public class Broker
extends Object
implements Runnable, IBM

CS 537, Fall 2004, Project 3. A centralized metals broker. It receives metals from the refiner periodically and serves consumer requests as soon as possible. If it has multiple requests, it satisfies them in a variety of ways, depending on the algorithm specified in the constructor.


Field Summary
 
Fields inherited from interface IBM
GOLD, metalName, METALS, PLATINUM, URANIUM
 
Constructor Summary
Broker(int algorithm)
          Creates a new Broker.
 
Method Summary
 void deliver(int[] amount)
          Accepts more resources from the supplier.
 boolean get(int id, int[] amt)
          Accepts a request from a consumer and blocks the consumer until the request can be satisfied.
 void run()
          Main loop.
 void shutDown()
          Tells this Broker to shut down.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Broker

public Broker(int algorithm)
Creates a new Broker.

Parameters:
algorithm - the algorithm used to choose among requests.
Method Detail

deliver

public void deliver(int[] amount)
Accepts more resources from the supplier.

Parameters:
amount - the number of each metal being delivered.

get

public boolean get(int id,
                   int[] amt)
Accepts a request from a consumer and blocks the consumer until the request can be satisfied.

Parameters:
id - the requesting consumer's id (for debugging output).
amt - the request.
Returns:
false if the request is rejected because the system is being shut down.

shutDown

public void shutDown()
Tells this Broker to shut down.


run

public void run()
Main loop.

Specified by:
run in interface Runnable