|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Trader
CS 537, Fall 2002, Project 3. A centralized trader. This trader "manufactures" one unit of each commodity from time to time and server customers' requests as soon as possible. If it has multiple requests, it satisfies them in a variety of orders, depending on the algorithm specified in the constructor.
Copyright © 2002 by Marvin Solomon. All rights reserved.
Field Summary | |
private int |
algorithm
The algorithm used by this Trader. |
private int[] |
delivered
The total amount delivered to Customers |
private boolean |
done
Flag to indicate that the Supplier has told us to shut down. |
private int |
fulfilled
Number of requests fulfilled |
private int |
iterations
The number of iterations to run. |
private static int |
NUM_ALGORITHMS
The number of algorithms implemented. |
private int[] |
onHand
The current stock on hand of each of the commodities |
private int |
shutdownCount
Used to keep track of the number of Customers who have been informed that the system is shutting down. |
private int[] |
supplied
The total amount received from the Supplier |
private List |
waiters
Queue of waiting customers. |
Fields inherited from interface Enron |
cname, COAL, COMMODITIES, cunit, ELEC, GAS, OIL |
Constructor Summary | |
Trader(int algorithm)
Creates a new Trader. |
Method Summary | |
private void |
algorithm1()
Tries to satisfy and release one or more customers. |
private void |
algorithm2()
Tries to satisfy and release one or more customers. |
private void |
algorithm3()
Tries to satisfy and release one or more customers. |
private void |
algorithm4()
Tries to satisfy and release one or more customers. |
boolean |
buy(int id,
int[] amt)
Accepts a request from a customer and blocks the customer until the request can be satisfied. |
private Order |
enqueue(int id,
int[] amt)
Creates an Order object and places it onto the waiters list. |
private static void |
incr(int[] a,
int[] b)
Utility procedure to update an array. |
private static void |
pl(Object o)
Abbreviation for System.out.println. |
private void |
recordFulfillment(int[] amt)
Record the fact that an order was fulfilled. |
void |
run()
Main loop. |
private void |
showQueue()
|
void |
shutDown()
Tells this Trader to shut down. |
void |
supply(int[] amount)
Accepts more resources from the supplier. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private int iterations
private int algorithm
private static final int NUM_ALGORITHMS
private boolean done
private List waiters
private int[] onHand
private int[] supplied
private int fulfilled
private int[] delivered
private int shutdownCount
Constructor Detail |
public Trader(int algorithm)
algorithm
- the algorithm used to choose among requests.Method Detail |
public void supply(int[] amount)
amount
- the number of each commodity being supplied.public boolean buy(int id, int[] amt)
id
- the requesting customer's id (for debugging output).amt
- the request.
public void shutDown()
private Order enqueue(int id, int[] amt)
id
- the requesting customer's id (for debugging output).amt
- the request.
private static void pl(Object o)
o
- the object to be printed.public void run()
run
in interface Runnable
private void showQueue()
private void algorithm1()
private void algorithm2()
private void algorithm3()
private void algorithm4()
private static void incr(int[] a, int[] b)
a
- the array to be updated.b
- the amount by which to update.private void recordFulfillment(int[] amt)
amt
- the order.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |