Package io.quarkus.arc
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 -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Destroys the current context and all existing contextual instances.default voidDestroy all contextual instances from the given state.default <T> TgetIfActive(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.getState()default InjectableContext.ContextStateIf the context is active then return the current state.default booleanisNormal()Methods inherited from interface jakarta.enterprise.context.spi.AlterableContext
destroyMethods 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
InjectableContext.ContextState getState()- Returns:
- the current state
- Throws:
jakarta.enterprise.context.ContextNotActiveException
-
getStateIfActive
If the context is active then return the current state.- Returns:
- the current state or
nullif 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 theContext.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 typecreationalContextFunction- the creational context function- Returns:
- the contextual instance, or a null value
-
destroy
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:
trueif this context represents a normal scope
-