/**
   * Applies all modifications to the index in parallel using the workers executor
   *
   * @throws ExecutionException
   * @throws InterruptedException
   */
  private void applyUpdates() throws InterruptedException, ExecutionException {
    AbstractWorkspaceImpl workspace = resources.getWorkspace();

    ErrorContextBuilder errorContextBuilder = new ErrorContextBuilder();
    errorContextBuilder.allWorkToBeDone(workList);

    IndexWriter indexWriter = workspace.getIndexWriter(errorContextBuilder);
    if (indexWriter == null) {
      log.cannotOpenIndexWriterCausePreviousError();
      return;
    }

    boolean taskExecutionSuccessful = true;

    try {
      if (workList.size() == 1) {
        taskExecutionSuccessful = runSingleTask(workList.get(0), indexWriter, errorContextBuilder);
      } else {
        taskExecutionSuccessful = runMultipleTasks(indexWriter, errorContextBuilder);
      }
      if (!taskExecutionSuccessful) {
        resources.getErrorHandler().handle(errorContextBuilder.createErrorContext());
      } else {
        workspace.optimizerPhase();
      }
    } finally {
      workspace.afterTransactionApplied(!taskExecutionSuccessful, false);
    }
  }
 public void shutdown() {
   // need to close them in this specific order:
   try {
     flushCloseExecutor();
   } finally {
     workspace.shutDownNow();
   }
 }