Class ComponentClosingUtils

java.lang.Object
org.apache.flink.runtime.operators.coordination.ComponentClosingUtils

public class ComponentClosingUtils extends Object
A util class to help with a clean component shutdown.
  • Method Details

    • closeAsyncWithTimeout

      public static CompletableFuture<Void> closeAsyncWithTimeout(String componentName, Runnable closingSequence, Duration closeTimeout)
      Close a component with a timeout.
      Parameters:
      componentName - the name of the component.
      closingSequence - the closing logic which is a callable that can throw exceptions.
      closeTimeout - the timeout to wait for the component to close.
      Returns:
      An optional throwable which is non-empty if an error occurred when closing the component.
    • closeAsyncWithTimeout

      public static CompletableFuture<Void> closeAsyncWithTimeout(String componentName, org.apache.flink.util.function.ThrowingRunnable<Exception> closingSequence, Duration closeTimeout)
      Close a component with a timeout.
      Parameters:
      componentName - the name of the component.
      closingSequence - the closing logic.
      closeTimeout - the timeout to wait for the component to close.
      Returns:
      An optional throwable which is non-empty if an error occurred when closing the component.
    • tryShutdownExecutorElegantly

      public static boolean tryShutdownExecutorElegantly(ExecutorService executor, Duration timeout)
      A util method that tries to shut down an ExecutorService elegantly within the given timeout. If the executor has not been shut down before it hits timeout or the thread is interrupted when waiting for the termination, a forceful shutdown will be attempted on the executor.
      Parameters:
      executor - the ExecutorService to shut down.
      timeout - the timeout duration.
      Returns:
      true if the given executor has been successfully closed, false otherwise.
    • shutdownExecutorForcefully

      public static boolean shutdownExecutorForcefully(ExecutorService executor, Duration timeout)
      Shutdown the given executor forcefully within the given timeout. The method returns if it is interrupted.
      Parameters:
      executor - the executor to shut down.
      timeout - the timeout duration.
      Returns:
      true if the given executor is terminated, false otherwise.
    • shutdownExecutorForcefully

      public static boolean shutdownExecutorForcefully(ExecutorService executor, Duration timeout, boolean interruptable)
      Shutdown the given executor forcefully within the given timeout.
      Parameters:
      executor - the executor to shut down.
      timeout - the timeout duration.
      interruptable - when set to true, the method can be interrupted. Each interruption to the thread results in another ExecutorService.shutdownNow() call to the shutting down executor.
      Returns:
      true if the given executor is terminated, false otherwise.