Package io.micronaut.http.netty
Class EventLoopFlow
java.lang.Object
io.micronaut.http.netty.EventLoopFlow
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:
- There must be no concurrent calls to
executeNow(java.lang.Runnable)
. - When
executeNow(java.lang.Runnable)
returnstrue
, the subsequent execution of the child method (onNext0
in the above example) must fully complete before the nextexecuteNow(java.lang.Runnable)
call. This ensures that there are no concurrent calls to the child method.
- Since:
- 4.4.0
- Author:
- Jonas Konrad
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
executeNow
(Runnable delayTask) Determine whether the next step can be executed immediately.
-
Constructor Details
-
EventLoopFlow
public EventLoopFlow(io.netty.util.concurrent.OrderedEventExecutor loop)
-
-
Method Details
-
executeNow
Determine whether the next step can be executed immediately. Iff this method returnstrue
,delayTask
will be ignored and the caller should call the target method manually. Iff this method returnsfalse
, the caller should take no further action asdelayTask
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
-