Class CancellationUtil

java.lang.Object
com.complexible.common.cancellation.CancellationUtil

public class CancellationUtil extends Object
Utility methods for monitoring and cancellation of abstract processes.
Since:
8.2
Author:
Pavel Klinov
  • Constructor Details

    • CancellationUtil

      public CancellationUtil()
  • Method Details

    • monitorAsync

      public static void monitorAsync(Runnable process, Runnable killer, CancelCheck cancelCheck)
    • monitorAsync

      public static <T> T monitorAsync(Callable<T> process, Runnable killer, CancelCheck cancelCheck)
      Starts a process in a separate thread and lets it run till canceled. If the process should be canceled, it runs the kill function but does not wait for the process to actually terminate. If it should wait, use monitorSync(Callable, Runnable, CancelCheck) method.

      If the process is not cancelled, the method returns the value returned by the process function. If the process throws, its exception is propagated.

      Type Parameters:
      T - the type of the process return value
      Parameters:
      process - the process function
      killer - the kill function, it will be called only once
      cancelCheck - the cancel check to receive external cancellation signals
      Returns:
      the process return value.
    • monitorSync

      public static void monitorSync(Runnable process, Runnable killer, CancelCheck cancelCheck)
    • monitorSync

      public static <T> T monitorSync(Callable<T> process, Runnable killer, CancelCheck cancelCheck)
      Starts a process and monitor it from a separate thread. If the process should be canceled, it runs the kill function and then blocks till the process actually terminates. If it should not wait, use monitorAsync(Callable, Runnable, CancelCheck) method.

      If the process is not cancelled, the method returns the value returned by the process function. If the process throws, its exception is propagated.

      Type Parameters:
      T - the type of the process return value
      Parameters:
      process - the process function
      killer - the kill function, it will be called only once
      cancelCheck - the cancel check to receive external cancellation signals
      Returns:
      the process return value.