Interface InjectableContext

All Superinterfaces:
jakarta.enterprise.context.spi.AlterableContext, jakarta.enterprise.context.spi.Context
All Known Subinterfaces:
ManagedContext

public interface InjectableContext extends jakarta.enterprise.context.spi.AlterableContext
A context implementing this interface makes it possible to capture and view its state via the InjectableContext.ContextState.

It also allows users to destroy all contextual instances within this context.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Destroys the current context and all existing contextual instances.
    default void
    Destroy all contextual instances from the given state.
    default <T> T
    getIfActive(jakarta.enterprise.context.spi.Contextual<T> contextual, Function<jakarta.enterprise.context.spi.Contextual<T>,jakarta.enterprise.context.spi.CreationalContext<T>> creationalContextFunction)
    If the context is active then return an existing instance of certain contextual type or create a new instance, otherwise return a null value.
     
    If the context is active then return the current state.
    default boolean
     

    Methods inherited from interface jakarta.enterprise.context.spi.AlterableContext

    destroy

    Methods inherited from interface jakarta.enterprise.context.spi.Context

    get, get, getScope, isActive
  • Method Details

    • destroy

      void destroy()
      Destroys the current context and all existing contextual instances.
    • getState

      Returns:
      the current state
      Throws:
      jakarta.enterprise.context.ContextNotActiveException
    • getStateIfActive

      default InjectableContext.ContextState getStateIfActive()
      If the context is active then return the current state.
      Returns:
      the current state or null if the context is not active
    • getIfActive

      default <T> T getIfActive(jakarta.enterprise.context.spi.Contextual<T> contextual, Function<jakarta.enterprise.context.spi.Contextual<T>,jakarta.enterprise.context.spi.CreationalContext<T>> creationalContextFunction)
      If the context is active then return an existing instance of certain contextual type or create a new instance, otherwise return a null value. This allows for the Context.isActive() check and the actual creation to happen in a single method, which gives a performance benefit by performing fewer thread local operations.
      Type Parameters:
      T - the type of contextual type
      Parameters:
      contextual - the contextual type
      creationalContextFunction - the creational context function
      Returns:
      the contextual instance, or a null value
    • destroy

      default void destroy(InjectableContext.ContextState state)
      Destroy all contextual instances from the given state.

      The default implementation is not optimized and does not guarantee proper sychronization. Implementations of this interface are encouraged to provide an optimized implementation of this method.

      Parameters:
      state -
    • isNormal

      default boolean isNormal()
      Returns:
      true if this context represents a normal scope