Package io.smallrye.mutiny.vertx.core
Class ContextAwareScheduler.ContextCaptureStrategy
- java.lang.Object
-
- io.smallrye.mutiny.vertx.core.ContextAwareScheduler.ContextCaptureStrategy
-
- Enclosing interface:
- ContextAwareScheduler
public static final class ContextAwareScheduler.ContextCaptureStrategy extends Object
Define how a scheduler captures a Vert.xContext
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ScheduledExecutorService
withContext(Context context)
Actions will be run on an explicitContext
.ScheduledExecutorService
withCurrentContext()
Actions will be run on a context that is captured from the thread that is calling this method.ScheduledExecutorService
withGetOrCreateContext(Vertx vertx)
Actions will be run on a context that is captured by callingVertx.getOrCreateContext()
when a scheduling method is being called likeScheduledExecutorService.schedule(Runnable, long, TimeUnit)
.ScheduledExecutorService
withGetOrCreateContextOnCurrentThread(Vertx vertx)
Actions will be run on a context that is captured by callingVertx.getOrCreateContext()
on the thread that is calling this method.
-
-
-
Method Detail
-
withContext
public ScheduledExecutorService withContext(Context context)
Actions will be run on an explicitContext
.- Parameters:
context
- the context, cannot benull
- Returns:
- the scheduler
-
withGetOrCreateContext
public ScheduledExecutorService withGetOrCreateContext(Vertx vertx)
Actions will be run on a context that is captured by callingVertx.getOrCreateContext()
when a scheduling method is being called likeScheduledExecutorService.schedule(Runnable, long, TimeUnit)
.Important. Note that in many cases such as
UniDelayOnItem
the scheduling operation happens on a worker thread and not a Vert.x thread, sowithGetOrCreateContextOnCurrentThread(Vertx)
might be the better option when data is being shared through the context.- Parameters:
vertx
- the Vert.x object, cannot benull
- Returns:
- the scheduler
-
withGetOrCreateContextOnCurrentThread
public ScheduledExecutorService withGetOrCreateContextOnCurrentThread(Vertx vertx)
Actions will be run on a context that is captured by callingVertx.getOrCreateContext()
on the thread that is calling this method. This is different towithGetOrCreateContext(Vertx)
which is late bound.- Parameters:
vertx
- the Vert.x object, cannot benull
- Returns:
- the scheduler
-
withCurrentContext
public ScheduledExecutorService withCurrentContext() throws IllegalStateException
Actions will be run on a context that is captured from the thread that is calling this method. An exception is raised when the current thread is not a Vert.x thread and hence has no associatedContext
.- Returns:
- the scheduler
- Throws:
IllegalStateException
- when the current thread is not a Vert.x thread
-
-