tfg.subsumption
Class ArbitratorEx

java.lang.Object
  extended by tfg.subsumption.ArbitratorEx

public class ArbitratorEx
extends Object

ArbitratorS controls which behavior should currently be active in a behavior control system. Make sure to call start() after the ArbitratorS is instantiated.
This class has three major responsibilities:
1. Determine the highest priority behavior that returns true to takeControl()
2. Suppress the currently active behavior if its priority is less than highest priority.
3. When the action() method exits, it calls action() on the Behavior of highest priority. this class ia a simplified version of Arbitrator. The differences are:
It assumes that a Behavior is no longer active when action() exits.
Therefore it will only call suppress() on the Behavior whose action() method is running.
It can make consecutive calls of action() on the same Behavior.
Requirements for a Behavior:
When suppress() is called, terminate action() immediately.

Author:
Roger Glassey
See Also:
Behavior

Nested Class Summary
private  class ArbitratorEx.Monitor
          Finds the highest priority behavior that returns true to takeControl(); If this priority is higher than the current behavior, it calls current.suppress().
 
Field Summary
private  Behavior[] _behavior
           
private  int _current
           
private  int _highestPriority
           
private  boolean _returnWhenInactive
           
private  ArbitratorEx.Monitor monitor
          Monitor is an inner class.
private  int NONE
           
 
Constructor Summary
ArbitratorEx(Behavior[] behaviorList)
          Same as Arbitrator(behaviorList, false) Arbitrator start() never exits
ArbitratorEx(Behavior[] behaviorList, boolean returnWhenInactive)
          Allocates an ArbitratorS object and initializes it with an array of Behavior objects.
 
Method Summary
 void start()
          This method starts the arbitration of Behaviors and runs an endless loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

private final int NONE
See Also:
Constant Field Values

_behavior

private Behavior[] _behavior

_highestPriority

private int _highestPriority

_current

private int _current

_returnWhenInactive

private boolean _returnWhenInactive

monitor

private ArbitratorEx.Monitor monitor
Monitor is an inner class. It polls the behavior array to find the behavior of hightst priority. If higher than the current active behavior, it calls current.suppress()

Constructor Detail

ArbitratorEx

public ArbitratorEx(Behavior[] behaviorList,
                    boolean returnWhenInactive)
Allocates an ArbitratorS object and initializes it with an array of Behavior objects. The index of a behavior in this array is its priority level, so the behavior of the largest index has the highest the priority level. The behaviors in an Arbitrator can not be changed once the arbitrator is initialized.
NOTE: Once the Arbitrator is initialized, the method start() must be called to begin the arbitration.

Parameters:
behaviorList - an array of Behavior objects.
returnWhenInactive - if true, the start() method returns when no Behavior is active.

ArbitratorEx

public ArbitratorEx(Behavior[] behaviorList)
Same as Arbitrator(behaviorList, false) Arbitrator start() never exits

Parameters:
behaviorList - An array of Behavior objects.
Method Detail

start

public void start()
This method starts the arbitration of Behaviors and runs an endless loop.
Note: Arbitrator does not run in a separate thread. The start() method will never return unless
1. no action() method is running and
2. no behavior takeControl() returns true and
3. the returnWhenInacative flag is true,