Top Description Constructors Methods
io.smallrye.common.vertx

public Class VertxContext

extends Object
Class Inheritance
Imports
io.smallrye.common.constraint.Assert, .Nullable, io.vertx.core.Context, .Vertx, io.vertx.core.impl.ContextInternal

Utility classes allowing to create duplicated contexts.

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.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Context

Returns:

a new duplicated context if called from a Vert.x thread, null otherwise.
createNewDuplicatedContext
()

Creates a new duplicated context, even if the current one is already a duplicated context.

public static Context

Returns:

a new duplicated context created from the given context, null is the passed context is null
createNewDuplicatedContext
(Context
the context
context
)

Creates a new duplicated context, even if the passed one is already a duplicated context.

public static Context

Returns:

the given context if it's a duplicated context, or a new duplicated context using the given one as root.
getOrCreateDuplicatedContext
(Context
the context, must not be null
context
)

Gets or creates a duplicated context.

public static Context

Returns:

the current context if it's a duplicated context, or a new duplicated context.
getOrCreateDuplicatedContext
(Vertx
the Vert.x instance to use to create the context if needed. Must not be null
vertx
)

Gets or creates a duplicated context.

public static Context

Returns:

the current context if it's a duplicated context, a new duplicated context using the given one as root, null if not called from a Vert.x thread.
getOrCreateDuplicatedContext
()

Gets or creates a duplicated context.

public static Context

Returns:

the root context if the given context is a duplicated context, returns the given context otherwise.
getRootContext
(Context
the context, must not be null
context
)

Returns the parent context from a given Vert.x context.

public static boolean

Returns:

true if the given context is a duplicated context, false otherwise.
isDuplicatedContext
(Context
the context, must not be null
context
)

Checks if the given context is a duplicated context.

public static boolean

Returns:

true if the method is called from a duplicated context, false otherwise.
isOnDuplicatedContext
()

Checks if the current context is a duplicated context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

VertxContextback to summary
private VertxContext()

Method Detail

createNewDuplicatedContextback to summary
public static 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 returns null.

Returns:Context

a new duplicated context if called from a Vert.x thread, null otherwise.

Annotations
@Nullable
createNewDuplicatedContextback to summary
public static Context createNewDuplicatedContext(Context context)

Creates a new duplicated context, even if the passed one is already a duplicated context. If the passed context is null, it returns null

Parameters
context:Context

the context

Returns:Context

a new duplicated context created from the given context, null is the passed context is null

Annotations
@Nullable
getOrCreateDuplicatedContextback to summary
public static Context getOrCreateDuplicatedContext(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:Context

the context, must not be null

Returns:Context

the given context if it's a duplicated context, or a new duplicated context using the given one as root.

getOrCreateDuplicatedContextback to summary
public static Context getOrCreateDuplicatedContext(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:Vertx

the Vert.x instance to use to create the context if needed. Must not be null

Returns:Context

the current context if it's a duplicated context, or a new duplicated context.

See Also
getOrCreateDuplicatedContext(Context)
getOrCreateDuplicatedContextback to summary
public static 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:Context

the current context if it's a duplicated context, a new duplicated context using the given one as root, null if not called from a Vert.x thread.

Annotations
@Nullable
See Also
getOrCreateDuplicatedContext(Context)
getRootContextback to summary
public static Context getRootContext(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:Context

the context, must not be null

Returns:Context

the root context if the given context is a duplicated context, returns the given context otherwise.

isDuplicatedContextback to summary
public static boolean isDuplicatedContext(Context context)

Checks if the given context is a duplicated context.

Parameters
context:Context

the context, must not be null

Returns:boolean

true if the given context is a duplicated context, false otherwise.

isOnDuplicatedContextback to summary
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:boolean

true if the method is called from a duplicated context, false otherwise.