Package io.quarkus.arc
Interface InjectableContext
-
- All Superinterfaces:
javax.enterprise.context.spi.AlterableContext
,javax.enterprise.context.spi.Context
- All Known Subinterfaces:
ManagedContext
public interface InjectableContext extends javax.enterprise.context.spi.AlterableContext
A context implementing this interface makes it possible to capture and view its state via theInjectableContext.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
InjectableContext.ContextState
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
destroy()
Destroy all existing contextual instances.default void
destroy(InjectableContext.ContextState state)
Destroy all contextual instances from the given state.default <T> T
getIfActive(javax.enterprise.context.spi.Contextual<T> contextual, Function<javax.enterprise.context.spi.Contextual<T>,javax.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.InjectableContext.ContextState
getState()
default InjectableContext.ContextState
getStateIfActive()
If the context is active then return the current state.default boolean
isNormal()
-
-
-
Method Detail
-
destroy
void destroy()
Destroy all existing contextual instances.
-
getState
InjectableContext.ContextState getState()
- Returns:
- the current state
- Throws:
javax.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(javax.enterprise.context.spi.Contextual<T> contextual, Function<javax.enterprise.context.spi.Contextual<T>,javax.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
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
-
-