Class BrokerImplementation

Object
  extended byBrokerImplementation
All Implemented Interfaces:
Broker, IBM

public class BrokerImplementation
extends Object
implements Broker, IBM

CS 537, Spring 2004, Project 2. Implementation of a broker.


Field Summary
 
Fields inherited from interface IBM
GOLD, metalName, METALS, PLATINUM, URANIUM
 
Constructor Summary
BrokerImplementation(int specialty)
          Creates a new Broker.
 
Method Summary
 void deliver(int ounces)
          Accepts more metal from the refiner.
 void get(int[] order)
          A purchase request from a consumer.
 void getAmountOnHand(int[] result)
          Report on the total amount of resources held by this Broker.
 void swap(int what, int ounces)
          Responds to a swap request from another broker.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BrokerImplementation

public BrokerImplementation(int specialty)
Creates a new Broker.

Parameters:
specialty - my "special" metal -- the one for which this Broker is the supplier.
Method Detail

getAmountOnHand

public void getAmountOnHand(int[] result)
Report on the total amount of resources held by this Broker.

Specified by:
getAmountOnHand in interface Broker
Parameters:
result - a vector of amounts, one for each metal, allocated by the caller and filled in by this Broker.

get

public void get(int[] order)
A purchase request from a consumer. The caller is blocked until the request can be completely filled. Note that this method is not synchronized. We do not wish to hold the monitor lock while calling other synchronized methods (namely Broker.swap). However, it uses synchronized methods to access all shared fields, so it is thread-safe.

Specified by:
get in interface Broker
Parameters:
order - the amount needed of each metal.

swap

public void swap(int what,
                 int ounces)
Responds to a swap request from another broker. Delays the caller until this Broker can complete the swap.

Specified by:
swap in interface Broker
Parameters:
what - the metal the other broker wants to swap.
ounces - the number of ounces to swap.

deliver

public void deliver(int ounces)
Accepts more metal from the refiner.

Specified by:
deliver in interface Broker
Parameters:
ounces - the number of ounces of this Broker's "special" metal being delivered.