Package com.vaadin.cdi.util
Class ContextualStorage
java.lang.Object
com.vaadin.cdi.util.ContextualStorage
- All Implemented Interfaces:
Serializable
This Storage holds all information needed for storing Contextual Instances in
a Context.
It also addresses Serialisation in case of passivating scopes.
- Since:
- 15.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionContextualStorage(jakarta.enterprise.inject.spi.BeanManager beanManager, boolean concurrent, boolean passivationCapable) Creates a new contextual storage. -
Method Summary
Modifier and TypeMethodDescription<T> TcreateContextualInstance(jakarta.enterprise.context.spi.Contextual<T> bean, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext) Creates a new contextual instance of the given bean and stores it in this storage.jakarta.enterprise.context.spi.Contextual<?> Restores the Bean from its beanKey.<T> ObjectgetBeanKey(jakarta.enterprise.context.spi.Contextual<T> bean) If the context is a passivating scope then we return the passivationId of the Bean.Gets the underlying storage map.booleanChecks whether the ContextualStorage might get accessed concurrently.
-
Constructor Details
-
ContextualStorage
public ContextualStorage(jakarta.enterprise.inject.spi.BeanManager beanManager, boolean concurrent, boolean passivationCapable) Creates a new contextual storage.- Parameters:
beanManager- is needed for serialisationconcurrent- whether the ContextualStorage might get accessed concurrently by different threadspassivationCapable- whether the storage is for passivation capable Scopes
-
-
Method Details
-
getStorage
Gets the underlying storage map.- Returns:
- the underlying storage map.
-
isConcurrent
public boolean isConcurrent()Checks whether the ContextualStorage might get accessed concurrently.- Returns:
- whether the ContextualStorage might get accessed concurrently by different threads.
-
createContextualInstance
public <T> T createContextualInstance(jakarta.enterprise.context.spi.Contextual<T> bean, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext) Creates a new contextual instance of the given bean and stores it in this storage. For concurrent storages, an already existing instance is returned instead of creating a new one.- Type Parameters:
T- the type of the contextual instance- Parameters:
bean- the bean to create an instance ofcreationalContext- the creational context to use for creating the instance- Returns:
- the contextual instance
-
getBeanKey
If the context is a passivating scope then we return the passivationId of the Bean. Otherwise we use the Bean directly.- Type Parameters:
T- the type of the contextual instance- Parameters:
bean- the bean to get the key for- Returns:
- the key to use in the context map
-
getBean
Restores the Bean from its beanKey.- Parameters:
beanKey- the key of the bean, as returned bygetBeanKey(Contextual)- Returns:
- the bean for the given key
- See Also:
-