code: public void close(final byte[] message) {
      LOG.log(Level.FINEST, "Triggering Task close.");
      synchronized (this.heartBeatManager) {
        if (this.currentStatus.isNotRunning()) {
          LOG.log(Level.WARNING, "Trying to close a task that is in state: {0}. Ignoring.",
              this.currentStatus.getState());
        } else {
          try {
            this.closeTask(message);
            this.currentStatus.setCloseRequested();
          } catch (final TaskCloseHandlerFailure taskCloseHandlerFailure) {
            LOG.log(Level.WARNING, "Exception while executing task close handler.",
                taskCloseHandlerFailure.getCause());
            this.currentStatus.setException(taskCloseHandlerFailure.getCause());
          }
        }
      }
    }
docs: Close the Task. This calls the configured close handler.
  
  @param message the optional message for the close handler or null if there none.