Esempio n. 1
0
  /**
   * This method starts the arbitration of behaviours and runs an endless loop. <br>
   * Note: Arbitrator does not run in a separate thread. The start() method will never return unless
   * <br>
   * 1. no action() method is running and <br>
   * 2. no behaviour takeControl() returns <B> true </B> and <br>
   * 3. the <i>returnWhenInacative </i> flag is true,
   */
  public void start() {
    //	  int i =0;
    monitor.start();

    while (_highestPriority == NONE) {
      Thread.yield(); // wait for some behaviour to take contro
    }
    while (true) {
      synchronized (monitor) {
        if (_highestPriority != NONE) {
          _active = _highestPriority;

        } else if (_returnWhenInactive) { // no behaviour wants to run
          monitor.more = false; // 9 shut down monitor thread
          return;
        }
      }

      // monotor released before action is called
      if (_active != NONE) // _highestPrioirty could be NONE
      {
        visCall = 0;
        _behaviour[_active].action();
        _active = NONE; // no active behaviour at the moment
      }
      Thread.yield();
      // i++;
      // System.out.println("i " + i);
      // if (i==10) return;
    }
  }