nachos.threads
Class Rider

java.lang.Object
  extended by nachos.threads.Rider
All Implemented Interfaces:
Runnable, RiderInterface

public class Rider
extends Object
implements RiderInterface

A single rider. Each rider accesses the elevator bank through an instance of RiderControls.


Field Summary
 
Fields inherited from interface nachos.machine.RiderInterface
dirDown, dirNeither, dirUp
 
Constructor Summary
Rider()
          Allocate a new rider.
 
Method Summary
 void initialize(RiderControls controls, int[] stops)
          Initialize this rider.
 void run()
          Cause the rider to use the provided controls to make the stops specified in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rider

public Rider()
Allocate a new rider.

Method Detail

initialize

public void initialize(RiderControls controls,
                       int[] stops)
Initialize this rider. The rider will access the elevator bank through controls, and the rider will make stops at different floors as specified in stops. This method should return immediately after this rider is initialized, but not until the interrupt handler is set. The rider will start receiving events after this method returns, potentially before run() is called.

Specified by:
initialize in interface RiderInterface
Parameters:
controls - the rider's interface to the elevator bank. The rider must not attempt to access the elevator bank in any other way.
stops - an array of stops the rider should make; see below.

run

public void run()
Cause the rider to use the provided controls to make the stops specified in the constructor. The rider should stop at each of the floors in stops, an array of floor numbers. The rider should only make the specified stops.

For example, suppose the rider uses controls to determine that it is initially on floor 1, and suppose the stops array contains two elements: { 0, 2 }. Then the rider should get on an elevator, get off on floor 0, get on an elevator, and get off on floor 2, pushing buttons as necessary.

This method should not return, but instead should call controls.finish() when the rider is finished.

Specified by:
run in interface Runnable
Specified by:
run in interface RiderInterface