Class ExecutorNotifier

java.lang.Object
org.apache.flink.runtime.source.coordinator.ExecutorNotifier

public class ExecutorNotifier extends Object
This class is used to coordinate between two components, where one component has an executor following the mailbox model and the other component notifies it when needed.
  • Constructor Details

  • Method Details

    • notifyReadyAsync

      public <T> void notifyReadyAsync(Callable<T> callable, BiConsumer<T,Throwable> handler)
      Call the given callable once. Notify the executorToNotify to execute the handler.

      Note that when this method is invoked multiple times, it is possible that multiple callables are executed concurrently, so do the handlers. For example, assuming both the workerExecutor and executorToNotify are single threaded. The following code may still throw a ConcurrentModificationException.

      
       final List<Integer> list = new ArrayList<>();
      
       // The callable adds an integer 1 to the list, while it works at the first glance,
       // A ConcurrentModificationException may be thrown because the caller and
       // handler may modify the list at the same time.
       notifier.notifyReadyAsync(
       	() -> list.add(1),
       	(ignoredValue, ignoredThrowable) -> list.add(2));
       

      Instead, the above logic should be implemented in as:

      
       // Modify the state in the handler.
       notifier.notifyReadyAsync(() -> 1, (v, ignoredThrowable) -> {
       	list.add(v));
       	list.add(2);
       });
       
      Parameters:
      callable - the callable to invoke before notifying the executor.
      handler - the handler to handle the result of the callable.
    • notifyReadyAsync

      public <T> void notifyReadyAsync(Callable<T> callable, BiConsumer<T,Throwable> handler, long initialDelayMs, long periodMs)
      Call the given callable once. Notify the executorToNotify to execute the handler.

      Note that when this method is invoked multiple times, it is possible that multiple callables are executed concurrently, so do the handlers. For example, assuming both the workerExecutor and executorToNotify are single threaded. The following code may still throw a ConcurrentModificationException.

      
       final List<Integer> list = new ArrayList<>();
      
       // The callable adds an integer 1 to the list, while it works at the first glance,
       // A ConcurrentModificationException may be thrown because the caller and
       // handler may modify the list at the same time.
       notifier.notifyReadyAsync(
       	() -> list.add(1),
       	(ignoredValue, ignoredThrowable) -> list.add(2));
       

      Instead, the above logic should be implemented in as:

      
       // Modify the state in the handler.
       notifier.notifyReadyAsync(() -> 1, (v, ignoredThrowable) -> {
       	list.add(v));
       	list.add(2);
       });
       
      Parameters:
      callable - the callable to execute before notifying the executor to notify.
      handler - the handler that handles the result from the callable.
      initialDelayMs - the initial delay in ms before invoking the given callable.
      periodMs - the interval in ms to invoke the callable.