Ejemplo n.º 1
0
  /**
   * when requesting a confirmation to the task master we anyhow allocate temporary the resources
   *
   * @param t task to be confirmed
   */
  private void getConfirm(TaskPlaceholder.Deferred t) {
    // here we temporary block resources
    // and ask for confirmation
    borrowers.lend(t.taskMaster, t.required);
    waitingConfirmation.put(t.getId(), t);

    trigger(new Resources.Confirm(t), workerPort);
  }
Ejemplo n.º 2
0
  private void allocateDirectly(TaskPlaceholder.Direct placeholder) {
    // here we allocate resources and start the timers
    borrowers.lend(placeholder.taskMaster, placeholder.task.required);

    res.workingQueue.running.put(placeholder.getId(), placeholder);

    log.info("{} Allocated {}", getId(), placeholder.getId());

    runTask(placeholder.task);
  }
Ejemplo n.º 3
0
 @Override
 public void handle(Resources.Allocate event) {
   TaskPlaceholder.Deferred placeholder = waitingConfirmation.remove(event.originalTaskId);
   assert placeholder != null;
   log.info("{} Allocating task {}", getId(), event.task.id);
   borrowers.updateCredit(placeholder.taskMaster, placeholder.required, event.task.required);
   TaskPlaceholder.Direct run = new TaskPlaceholder.Direct(event.taskMaster, event.task);
   res.workingQueue.running.put(event.task.id, run);
   runTask(event.task);
 }
Ejemplo n.º 4
0
 @Override
 public void handle(Resources.Cancel event) {
   TaskPlaceholder.Deferred placeholder = waitingConfirmation.remove(event.taskId);
   if (placeholder != null) {
     borrowers.claim(placeholder.taskMaster, placeholder.required);
     // res.workingQueue.running.remove(remove.getId());
     log.debug("{} REMOVED {}", getId(), event.taskId);
     pop();
   } else {
     log.warn("Cancelling a non-waiting task?");
   }
 }
Ejemplo n.º 5
0
        @Override
        public void handle(FdetPort.Dead event) {
          ArrayList<Long> removed = new ArrayList<Long>();
          boolean popAfter = false;

          Iterator<Entry<Long, TaskPlaceholder.Direct>> i =
              res.workingQueue.running.entrySet().iterator();
          while (i.hasNext()) {
            Entry<Long, TaskPlaceholder.Direct> e = i.next();
            TaskPlaceholder.Direct tph = e.getValue();
            if (tph.taskMaster.equals(event.ref)) {
              borrowers.claim(event.ref, tph.task.required);
              removed.add(e.getKey());
              i.remove();
              popAfter = true;
            }
          }

          Iterator<Entry<Long, Deferred>> j = waitingConfirmation.entrySet().iterator();
          while (j.hasNext()) {
            Entry<Long, TaskPlaceholder.Deferred> e = j.next();
            TaskPlaceholder.Deferred tph = e.getValue();
            if (tph.taskMaster.equals(event.ref)) {
              borrowers.claim(event.ref, tph.required);
              removed.add(e.getKey());
              j.remove();
            }
          }

          assert borrowers.countCredits(event.ref) == 0;
          log.debug(
              getId() + ": {} DETECTED AS DEAD. RELEASED RESOURCES FOR {}",
              event.ref.getIp().getHostAddress(),
              removed);

          /* If we eliminated at least one running task, the pop() call will be skipped.
           * We need therefore to do it here. */
          if (popAfter) pop();
        }
Ejemplo n.º 6
0
        @Override
        public void handle(TaskDone event) {
          TaskPlaceholder.Direct tph = res.workingQueue.running.remove(event.referenceId);
          if (tph == null) {
            log.error(getId() + " IGNORING TASK " + event.referenceId + ", TASK MASTER WAS FAULTY");
          } else {
            Task t = tph.task;
            t.deallocate();
            borrowers.claim(tph.taskMaster, t.required);
            res.workingQueue.done.add(t);
            log.info(
                "{} Done {}, QueueTime={}, TotalTime={}",
                new Object[] {
                  getId(), t.id, t.getQueueTime(), (float) (t.timeToHoldResource) / t.getTotalTime()
                });
            trigger(new Resources.Completed(tph.taskMaster, t), workerPort);

            /* last */
            pop();
          }
        }