Пример #1
0
  private void checkTasks() {
    if (stored >= minimalStore && replicated >= minimalReplicated && paged >= minimalPage) {
      Iterator<TaskHolder> iter = tasks.iterator();
      while (iter.hasNext()) {
        TaskHolder holder = iter.next();
        if (stored >= holder.storeLined
            && replicated >= holder.replicationLined
            && paged >= holder.pageLined) {
          // If set, we use an executor to avoid the server being single threaded
          execute(holder.task);

          iter.remove();
        } else {
          // End of list here. No other task will be completed after this
          break;
        }
      }
    }
  }
Пример #2
0
  public void executeOnCompletion(final IOAsyncTask completion) {
    if (errorCode != -1) {
      completion.onError(errorCode, errorMessage);
      return;
    }

    boolean executeNow = false;

    synchronized (this) {
      if (tasks == null) {
        tasks = new LinkedList<TaskHolder>();
        minimalReplicated = replicationLineUp.intValue();
        minimalStore = storeLineUp.intValue();
        minimalPage = pageLineUp.intValue();
      }

      // On this case, we can just execute the context directly
      if (replicationLineUp.intValue() == replicated
          && storeLineUp.intValue() == stored
          && pageLineUp.intValue() == paged) {
        // We want to avoid the executor if everything is complete...
        // However, we can't execute the context if there are executions pending
        // We need to use the executor on this case
        if (executorsPending.get() == 0) {
          // No need to use an executor here or a context switch
          // there are no actions pending.. hence we can just execute the task directly on the same
          // thread
          executeNow = true;
        } else {
          execute(completion);
        }
      } else {
        tasks.add(new TaskHolder(completion));
      }
    }

    if (executeNow) {
      // Executing outside of any locks
      completion.done();
    }
  }