public abstract class AbstractContext<K> extends Object implements AdvancedContext<K>, ThreadContextHolder
AdvancedContext| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractContext.ThreadLocalData
This class encapsulates all the data stored into the
ThreadLocal variable |
MANAGE_THREAD_LOCAL| Constructor and Description |
|---|
AbstractContext() |
| Modifier and Type | Method and Description |
|---|---|
void |
activate(K key)
Activates the current context using the given key within the context of the thread
|
protected abstract CreationContextStorage |
createStorage(K key)
Creates a
CreationContextStorage instance from the given key |
void |
deactivate(K key)
Deactivates the current context using the given key from the context of the thread
|
protected void |
destroy()
Destroys all the
CreationContext that has been stored in the current storage |
void |
destroy(javax.enterprise.context.spi.Contextual contextual)
Destroy the existing contextual instance.
|
protected void |
destroy(CreationContextStorage storage)
Destroys all the
CreationContext that has been stored in the given storage |
<T> T |
get(javax.enterprise.context.spi.Contextual<T> contextual) |
<T> T |
get(javax.enterprise.context.spi.Contextual<T> contextual,
javax.enterprise.context.spi.CreationalContext<T> creationalContext) |
protected <T> T |
getFromCache(AbstractContext.ThreadLocalData data,
String id)
Gets the component from the cache if it has already been registered
|
protected <T> String |
getId(javax.enterprise.context.spi.Contextual<T> contextual)
Gives an id for the given
Contextual |
protected <T> T |
getInstance(CreationContextStorage storage,
String id)
Gives the instance stored with the given
Contextual id. |
protected abstract Lock |
getLock(String id)
In case the context is sharable, we will need a lock to synchronize the accesses
|
protected CreationContextStorage |
getStorage()
Gives the storage to use to store and access to the CreationContext
|
ThreadContext |
getThreadContext()
Gives the value corresponding to the context of the thread
|
boolean |
isActive() |
protected abstract boolean |
isSharable()
Indicates whether the objects of the context that can shared or not.
|
protected void |
putInCache(AbstractContext.ThreadLocalData data,
String id,
Object o)
Puts in the cache a given object instance corresponding to the given id
|
void |
register(K key)
Registers a new key to the context
|
protected void |
setStorage(CreationContextStorage storage)
Sets the current storage
|
void |
unregister(K key)
Unregisters a given key from the context
|
public <T> T get(javax.enterprise.context.spi.Contextual<T> contextual,
javax.enterprise.context.spi.CreationalContext<T> creationalContext)
get in interface javax.enterprise.context.spi.Contextpublic <T> T get(javax.enterprise.context.spi.Contextual<T> contextual)
get in interface javax.enterprise.context.spi.Contextpublic void destroy(javax.enterprise.context.spi.Contextual contextual)
Destroy the existing contextual instance. If there is no existing instance, no action is taken.
destroy in interface AdvancedContext<K>contextual - the contextual typepublic boolean isActive()
isActive in interface javax.enterprise.context.spi.Contextpublic void activate(K key)
activate in interface AdvancedContext<K>key - the key to use to activate the contextpublic void deactivate(K key)
deactivate in interface AdvancedContext<K>key - the key to use to deactivate the contextpublic void register(K key)
register in interface AdvancedContext<K>key - the key to registerpublic void unregister(K key)
unregister in interface AdvancedContext<K>key - the key to unregisterprotected <T> String getId(javax.enterprise.context.spi.Contextual<T> contextual)
Contextualcontextual - the contextual object for which we want an idprotected abstract boolean isSharable()
true if the components are sharable, false otherwise.protected abstract Lock getLock(String id)
id - the id of the contextual for which we want a lockprotected abstract CreationContextStorage createStorage(K key)
CreationContextStorage instance from the given keykey - the key to use to create the CreationContextStorageCreationContextStorage corresponding to the given keyprotected CreationContextStorage getStorage()
CreationContextStorage corresponding to the current contextprotected void setStorage(CreationContextStorage storage)
storage - the new current storage. Set it to null to remove the current storageprotected void destroy()
CreationContext that has been stored in the current storageprotected void destroy(CreationContextStorage storage)
CreationContext that has been stored in the given storagestorage - the storage that we would like to cleanupprotected <T> T getInstance(CreationContextStorage storage, String id)
Contextual id.storage - the storage from which we will get the instanceid - the id of the contextual for which we want the instancenull otherwiseprotected <T> T getFromCache(AbstractContext.ThreadLocalData data, String id)
data - the data corresponding to the current contextid - the id of the componentprotected void putInCache(AbstractContext.ThreadLocalData data, String id, Object o)
data - the data corresponding to the current contextid - the id of the componento - the corresponding instancepublic ThreadContext getThreadContext()
getThreadContext in interface ThreadContextHolderThreadContext if there are some
valuable ThreadLocal variables to share otherwise null
is expectedCopyright © 2020 eXo Platform SAS. All Rights Reserved.