lejos.subsumption
Class Arbitrator2

java.lang.Object
  extended by lejos.subsumption.Arbitrator2

public class Arbitrator2
extends Object

Arbitrator2 controls which behavior should currently be active in a behavior control system. This implementation is simpler than the original, but the behaviors it uses must implement the Behavior2 interface. In this architecture, when a behavior wants control, it must call arbitrator.wantControl();

Version:
1 27-sept 2007
Author:
Roger Glassey (after Brian Bagnall)

Constructor Summary
Arbitrator2(Behavior2[] behaviors)
          Allocates an Arbitrator2 object and initializes it with an array of Behavior2 objects.
 
Method Summary
 void start()
          This method starts the arbitration of Behaviors.
It iterates over the array of behaviors, highest priority first.
 void wantControl(Behavior2 theBehavior)
          If the behavior that sent this message has higher priority than the active behavior, the active behavior is suppressed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

Arbitrator2

public Arbitrator2(Behavior2[] behaviors)
Allocates an Arbitrator2 object and initializes it with an array of Behavior2 objects. The largest index in the Behavior array will have the highest priority level, and hence will suppress all lower priority behaviors if it calls wantContorol on this. The new arbitrator calls setArbitrator() on each Behavior to establish the call back link. The Behaviors in an Arbitrator can not be changed once the arbitrator is initialized.
NOTE: Once the Arbitrator is initialized, the method go() must be called to begin the arbitration.

Parameters:
behaviors - An array of Behavior objects. The behavior of largest index has the highest proiroty.
Method Detail

start

public void start()
This method starts the arbitration of Behaviors.
It iterates over the array of behaviors, highest priority first. and calls the takeControl() method. If true is returned, it calls action() on that behavior. When the action() method returns (either because it was completed or it was suppressed) the search starts again. If no behavior returns true, this method exits.


wantControl

public void wantControl(Behavior2 theBehavior)
If the behavior that sent this message has higher priority than the active behavior, the active behavior is suppressed.

Parameters:
theBehavior -