Class EventLoopFlow

java.lang.Object
io.micronaut.http.netty.EventLoopFlow

@Internal public final class EventLoopFlow extends Object
This class forwards reactive operations onto an EventLoop if they are called from outside that loop. It avoids unnecessary Executor.execute(java.lang.Runnable) calls when the reactive methods are called inside the loop. All the while it ensures the operations remain serialized (in the same order).

Should be used like this:

     public void onNext(Object item) {
         if (serializer.executeNow(() -> onNext0(item))) {
             onNext0(item);
         }
     }

     private void onNext0(Object item) {
         ...
     }
 

This class is not thread-safe: The invariants for calls to executeNow(java.lang.Runnable) are very strict. In particular:

Both of these invariants are guaranteed by the reactive spec, but may not apply to other use cases.
Since:
4.4.0
Author:
Jonas Konrad
  • Constructor Details

    • EventLoopFlow

      public EventLoopFlow(io.netty.util.concurrent.OrderedEventExecutor loop)
  • Method Details

    • executeNow

      public boolean executeNow(Runnable delayTask)
      Determine whether the next step can be executed immediately. Iff this method returns true, delayTask will be ignored and the caller should call the target method manually. Iff this method returns false, the caller should take no further action as delayTask will be run in the future.
      Parameters:
      delayTask - The task to run if it can't be run immediately
      Returns:
      true if the caller should instead run the task immediately