Class CancellationUtil


  • public class CancellationUtil
    extends java.lang.Object
    Utility methods for monitoring and cancellation of abstract processes.
    Since:
    8.2
    Author:
    Pavel Klinov
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void monitorAsync​(java.lang.Runnable process, java.lang.Runnable killer, CancelCheck cancelCheck)  
      static <T> T monitorAsync​(java.util.concurrent.Callable<T> process, java.lang.Runnable killer, CancelCheck cancelCheck)
      Starts a process in a separate thread and lets it run till canceled.
      static void monitorSync​(java.lang.Runnable process, java.lang.Runnable killer, CancelCheck cancelCheck)  
      static <T> T monitorSync​(java.util.concurrent.Callable<T> process, java.lang.Runnable killer, CancelCheck cancelCheck)
      Starts a process and monitor it from a separate thread.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CancellationUtil

        public CancellationUtil()
    • Method Detail

      • monitorAsync

        public static void monitorAsync​(java.lang.Runnable process,
                                        java.lang.Runnable killer,
                                        CancelCheck cancelCheck)
      • monitorAsync

        public static <T> T monitorAsync​(java.util.concurrent.Callable<T> process,
                                         java.lang.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​(java.lang.Runnable process,
                                       java.lang.Runnable killer,
                                       CancelCheck cancelCheck)
      • monitorSync

        public static <T> T monitorSync​(java.util.concurrent.Callable<T> process,
                                        java.lang.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.