Esempio n. 1
0
  /**
   * This method is called when the user asks to start the simulation in the context of the main UI
   * Thread. It creates the designated number of Palantiri and adds them to the PalantiriManager. It
   * then creates a Thread for each Being and has each Being attempt to acquire a Palantir for
   * gazing, mediated by the PalantiriManager. The BeingTheads call methods from the
   * MVP.RequiredViewOps interface to visualize what is happening to the user.
   */
  @Override
  public void start() {
    // Initialize the Palantiri.
    getModel().makePalantiri(Options.instance().numberOfPalantiri());

    // Initialize the count of the number of threads Beings use to gaze.
    mGazingTasks = new AtomicLong(0);

    // Show the Beings on the UI.
    mView.get().showBeings();

    // Show the palantiri on the UI.
    mView.get().showPalantiri();

    // Spawn a thread that waits for all the Being threads to finish.
    joinBeingsTasks();

    // Create and execute an AsyncBeingTask for each Being.
    Log.i(TAG, "Before createAndExecuteBeingsTasks");
    createAndExecuteBeingsTasks(Options.instance().numberOfBeings());
    Log.i(TAG, "After createAndExecuteBeingsTasks");
  }