Class VertxContext

java.lang.Object
net.bluemind.lib.vertx.VertxContext

public class VertxContext extends Object
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.

  • 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 be null
      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 be null
      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, null if 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 returns null.
      Returns:
      a new duplicated context if called from a Vert.x thread, null otherwise.
    • 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 is null, it returns null
      Returns:
      a new duplicated context created from the given context, null is the passed context is null
    • 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 be null
      Returns:
      true if the given context is a duplicated context, false otherwise.
    • 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:
      true if the method is called from a duplicated context, false otherwise.
    • 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 be null
      Returns:
      the root context if the given context is a duplicated context, returns the given context otherwise.