nachos.machine
Class ElevatorBank

java.lang.Object
  extended by nachos.machine.ElevatorBank
All Implemented Interfaces:
Runnable

public final class ElevatorBank
extends Object
implements Runnable

A bank of elevators.


Field Summary
static int dirDown
          Indicates an elevator intends to move down.
static int dirNeither
          Indicates an elevator intends not to move.
static int dirUp
          Indicates an elevator intends to move up.
 
Constructor Summary
ElevatorBank(Privilege privilege)
          Allocate a new elevator bank.
 
Method Summary
 RiderControls addRider(RiderInterface rider, int floor, int[] stops)
          Add a rider to the simulation.
 void enableGui()
          Create a GUI for this elevator bank.
 void init(int numElevators, int numFloors, ElevatorControllerInterface controller)
          Initialize this elevator bank with the specified number of elevators and the specified number of floors.
 void run()
          Run a simulation.
static void selfTest()
          Tests whether this module is working.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dirDown

public static final int dirDown
Indicates an elevator intends to move down.

See Also:
Constant Field Values

dirNeither

public static final int dirNeither
Indicates an elevator intends not to move.

See Also:
Constant Field Values

dirUp

public static final int dirUp
Indicates an elevator intends to move up.

See Also:
Constant Field Values
Constructor Detail

ElevatorBank

public ElevatorBank(Privilege privilege)
Allocate a new elevator bank.

Parameters:
privilege - encapsulates privileged access to the Nachos machine.
Method Detail

init

public void init(int numElevators,
                 int numFloors,
                 ElevatorControllerInterface controller)
Initialize this elevator bank with the specified number of elevators and the specified number of floors. The software elevator controller must also be specified. This elevator must not already be running a simulation.

Parameters:
numElevators - the number of elevators in the bank.
numFloors - the number of floors in the bank.
controller - the elevator controller.

addRider

public RiderControls addRider(RiderInterface rider,
                              int floor,
                              int[] stops)
Add a rider to the simulation. This method must not be called after run() is called.

Parameters:
rider - the rider to add.
floor - the floor the rider will start on.
stops - the array to pass to the rider's initialize() method.
Returns:
the controls that will be given to the rider.

enableGui

public void enableGui()
Create a GUI for this elevator bank.


run

public void run()
Run a simulation. Initialize all elevators and riders, and then fork threads to each of their run() methods. Return when the simulation is finished.

Specified by:
run in interface Runnable

selfTest

public static void selfTest()
Tests whether this module is working.