docs: public final void close(final int retryCloseTimeoutMs, final Consumer<Thread> closeFailAction)
      {
          isRunning = false;
  
          final Thread thread = this.thread.getAndSet(TOMBSTONE);
          if (null == thread)
          {
              try
              {
                  agent.onClose();
              }
              catch (final Throwable throwable)
              {
                  errorHandler.onError(throwable);
              }
              finally
              {
                  isClosed = true;
              }
          }
          else if (TOMBSTONE != thread)
          {
              while (true)
              {
                  try
                  {
                      thread.join(retryCloseTimeoutMs);
  
                      if (!thread.isAlive() || isClosed)
                      {
                          return;
                      }
  
                      if (null == closeFailAction)
                      {
                          System.err.println(
                              "timeout waiting for agent '" + agent.roleName() + "' to close, " + "retrying...");
                      }
                      else
                      {
                          closeFailAction.accept(thread);
                      }
  
                      if (!thread.isInterrupted())
                      {
                          thread.interrupt();
                      }
                  }
                  catch (final InterruptedException ignore)
                  {
                      if (null == closeFailAction)
                      {
                          System.err.println(
                              "close failed for agent '" + agent.roleName() + "' due to InterruptedException");
                      }
                      else
                      {
                          closeFailAction.accept(thread);
                      }
  
                      Thread.currentThread().interrupt();
                      return;
                  }
              }
          }
      }