|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
ObjectWarehouse
public class Warehouse
A centralized supplier of grain.
CS 537, Spring 2007, Project 3.
This class replaces the Traders of Project 2.
A Warehouse accepts request from Brewers and serves them as fast as
possible. If it has multiple requests, it satisfies them in a variety of
orders, depending on the algorithm specified in the constructor.
| Field Summary | |
|---|---|
private int |
algorithm
The algorithm used by this Warehouse. |
private Order |
delivered
The total amount delivered to Customers. |
private int |
fulfilled
Number of requests fulfilled. |
private static int |
NUM_ALGORITHMS
The number of algorithms implemented. |
private Order |
onHand
The current stock on hand. |
private Order |
supplied
The total amount received from the Supplier. |
private static int |
VERSION
Source version number. |
private List<Request> |
waiters
Queue of waiting requests. |
| Constructor Summary | |
|---|---|
Warehouse(int algorithm)
Creates a new Warehouse. |
|
| 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. |
void |
deliver(Order amount)
Accepts more grain from the supplier. |
private Request |
enqueue(int id,
Order amt)
Creates a Request object and places it onto the waiters list. |
void |
get(int id,
Order amt)
Accepts a request from a Brewer and blocks the Brewer until the request can be satisfied. |
Order |
getAmountOnHand()
Reports on the total amount of grain held by this Warehouse. |
private void |
recordFulfillment(Order amt)
Record the fact that an order was fulfilled. |
void |
run()
Main loop. |
void |
undo(Order amount)
Accepts back grain from an interrupted request. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final int VERSION
private int algorithm
private static final int NUM_ALGORITHMS
private List<Request> waiters
private Order onHand
private Order supplied
private int fulfilled
private Order delivered
| Constructor Detail |
|---|
public Warehouse(int algorithm)
algorithm - the algorithm used to choose among requests.| Method Detail |
|---|
public void deliver(Order amount)
amount - the amount being supplied.public void undo(Order amount)
amount - the amount being returned.
public void get(int id,
Order amt)
throws InterruptedException
id - the requesting Brewer's id (for debugging output).amt - the request.
InterruptedException - if the Brewer thread is interrupted while
waiting for the request to be filled.
private Request enqueue(int id,
Order amt)
id - the requesting customer's id (for debugging output).amt - the request.
public void run()
run in interface Runnablepublic Order getAmountOnHand()
private void algorithm1()
private void algorithm2()
private void algorithm3()
private void algorithm4()
private void recordFulfillment(Order amt)
amt - the order.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||