Class VertxContext
The rationale for this class is to avoid end-users to use the Vert.x internal API, and avoids common mistakes when dealing with Contexts and duplicated Contexts.
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.vertx.core.ContextCreates a new duplicated context, even if the current one is already a duplicated context.static io.vertx.core.ContextcreateNewDuplicatedContext(io.vertx.core.Context context) Creates a new duplicated context, even if the passed one is already a duplicated context.static io.vertx.core.ContextGets or creates a duplicated context.static io.vertx.core.ContextgetOrCreateDuplicatedContext(io.vertx.core.Context context) Gets or creates a duplicated context.static io.vertx.core.ContextgetOrCreateDuplicatedContext(io.vertx.core.Vertx vertx) Gets or creates a duplicated context.static io.vertx.core.ContextgetRootContext(io.vertx.core.Context context) Returns the parent context from a given Vert.x context.static booleanisDuplicatedContext(io.vertx.core.Context context) Checks if the given context is a duplicated context.static booleanChecks if the current context is a duplicated context.
-
Method Details
-
getOrCreateDuplicatedContext
public static io.vertx.core.Context getOrCreateDuplicatedContext(io.vertx.core.Context context) Gets or creates a duplicated context. If the given context is already a duplicated context, it returns this duplicated context. Otherwise, it creates a new duplicated context, using the given context as root context.- Parameters:
context- the context, must not benull- Returns:
- the given context if it's a duplicated context, or a new duplicated context using the given one as root.
-
getOrCreateDuplicatedContext
public static io.vertx.core.Context getOrCreateDuplicatedContext(io.vertx.core.Vertx vertx) Gets or creates a duplicated context.If this method is called from a non-Vert.x thread (so, there is no current context), it creates a new (event loop) context and a duplicated context (and returns the duplicated context).
If this method is called from a Vert.x thread (so, there is a current context), and if the current context is already a duplicated context, it returns the current duplicated context.
It this method is called from a Vert.x thread (so, there is a current context), and if the current context is not a duplicated context, it creates a new duplicated context, using the current context as root context.
- Parameters:
vertx- the Vert.x instance to use to create the context if needed. Must not benull- Returns:
- the current context if it's a duplicated context, or a new duplicated context.
- See Also:
-
getOrCreateDuplicatedContext
public static io.vertx.core.Context getOrCreateDuplicatedContext()Gets or creates a duplicated context.If the method is not called from a Vert.x thread, it returns
null. If the caller context is already a duplicated context, it returns this duplicated context. Otherwise, it creates a new duplicated context, using current context as root context.- Returns:
- the current context if it's a duplicated context, a new duplicated
context using the given one as root,
nullif not called from a Vert.x thread. - See Also:
-
createNewDuplicatedContext
public static io.vertx.core.Context createNewDuplicatedContext()Creates a new duplicated context, even if the current one is already a duplicated context. If the method is not called from a Vert.x thread, it returnsnull.- Returns:
- a new duplicated context if called from a Vert.x thread,
nullotherwise.
-
createNewDuplicatedContext
public static io.vertx.core.Context createNewDuplicatedContext(io.vertx.core.Context context) Creates a new duplicated context, even if the passed one is already a duplicated context. If the passed context isnull, it returnsnull- Returns:
- a new duplicated context created from the given context,
nullis the passed context isnull
-
isDuplicatedContext
public static boolean isDuplicatedContext(io.vertx.core.Context context) Checks if the given context is a duplicated context.- Parameters:
context- the context, must not benull- Returns:
trueif the given context is a duplicated context,falseotherwise.
-
isOnDuplicatedContext
public static boolean isOnDuplicatedContext()Checks if the current context is a duplicated context. If the method is called from a Vert.x thread, it retrieves the current context and checks if it's a duplicated context. Otherwise, it returns false.- Returns:
trueif the method is called from a duplicated context,falseotherwise.
-
getRootContext
public static io.vertx.core.Context getRootContext(io.vertx.core.Context context) Returns the parent context from a given Vert.x context.A duplicate context returns the wrapped context otherwise the given context is returned.
- Parameters:
context- the context, must not benull- Returns:
- the root context if the given context is a duplicated context, returns the given context otherwise.
-