Class AbstractContext<K>
java.lang.Object
org.exoplatform.container.context.AbstractContext<K>
- All Implemented Interfaces:
javax.enterprise.context.spi.Context,ThreadContextHolder,AdvancedContext<K>
- Direct Known Subclasses:
SharedContext,UnSharedContext
public abstract class AbstractContext<K>
extends Object
implements AdvancedContext<K>, ThreadContextHolder
This is the root class of all the implementations of an
AdvancedContext-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThis class encapsulates all the data stored into theThreadLocalvariable -
Field Summary
Fields inherited from interface org.exoplatform.container.component.ThreadContextHolder
MANAGE_THREAD_LOCAL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidActivates the current context using the given key within the context of the threadprotected abstract CreationContextStoragecreateStorage(K key) Creates aCreationContextStorageinstance from the given keyvoiddeactivate(K key) Deactivates the current context using the given key from the context of the threadprotected voiddestroy()Destroys all theCreationContextthat has been stored in the current storagevoiddestroy(javax.enterprise.context.spi.Contextual contextual) Destroy the existing contextual instance.protected voiddestroy(CreationContextStorage storage) Destroys all theCreationContextthat has been stored in the given storage<T> Tget(javax.enterprise.context.spi.Contextual<T> contextual) <T> Tget(javax.enterprise.context.spi.Contextual<T> contextual, javax.enterprise.context.spi.CreationalContext<T> creationalContext) protected <T> TGets the component from the cache if it has already been registeredprotected <T> StringgetId(javax.enterprise.context.spi.Contextual<T> contextual) Gives an id for the givenContextualprotected <T> TgetInstance(CreationContextStorage storage, String id) Gives the instance stored with the givenContextualid.protected abstract LockIn case the context is sharable, we will need a lock to synchronize the accessesprotected CreationContextStorageGives the storage to use to store and access to the CreationContextGives the value corresponding to the context of the threadbooleanisActive()protected abstract booleanIndicates whether the objects of the context that can shared or not.protected voidputInCache(AbstractContext.ThreadLocalData data, String id, Object o) Puts in the cache a given object instance corresponding to the given idvoidRegisters a new key to the contextprotected voidsetStorage(CreationContextStorage storage) Sets the current storagevoidunregister(K key) Unregisters a given key from the contextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.enterprise.context.spi.Context
getScope
-
Constructor Details
-
AbstractContext
public AbstractContext()
-
-
Method Details
-
get
public <T> T get(javax.enterprise.context.spi.Contextual<T> contextual, javax.enterprise.context.spi.CreationalContext<T> creationalContext) - Specified by:
getin interfacejavax.enterprise.context.spi.Context
-
get
public <T> T get(javax.enterprise.context.spi.Contextual<T> contextual) - Specified by:
getin interfacejavax.enterprise.context.spi.Context
-
destroy
public void destroy(javax.enterprise.context.spi.Contextual contextual) Destroy the existing contextual instance. If there is no existing instance, no action is taken.
- Specified by:
destroyin interfaceAdvancedContext<K>- Parameters:
contextual- the contextual type
-
isActive
public boolean isActive()- Specified by:
isActivein interfacejavax.enterprise.context.spi.Context
-
activate
Activates the current context using the given key within the context of the thread- Specified by:
activatein interfaceAdvancedContext<K>- Parameters:
key- the key to use to activate the context
-
deactivate
Deactivates the current context using the given key from the context of the thread- Specified by:
deactivatein interfaceAdvancedContext<K>- Parameters:
key- the key to use to deactivate the context
-
register
Registers a new key to the context- Specified by:
registerin interfaceAdvancedContext<K>- Parameters:
key- the key to register
-
unregister
Unregisters a given key from the context- Specified by:
unregisterin interfaceAdvancedContext<K>- Parameters:
key- the key to unregister
-
getId
Gives an id for the givenContextual- Parameters:
contextual- the contextual object for which we want an id
-
isSharable
protected abstract boolean isSharable()Indicates whether the objects of the context that can shared or not. sharable- Returns:
trueif the components are sharable,falseotherwise.
-
getLock
In case the context is sharable, we will need a lock to synchronize the accesses- Parameters:
id- the id of the contextual for which we want a lock- Returns:
- a lock corresponding to the given contextual within the current context
-
createStorage
Creates aCreationContextStorageinstance from the given key- Parameters:
key- the key to use to create theCreationContextStorage- Returns:
- the
CreationContextStoragecorresponding to the given key
-
getStorage
Gives the storage to use to store and access to the CreationContext- Returns:
- the
CreationContextStoragecorresponding to the current context
-
setStorage
Sets the current storage- Parameters:
storage- the new current storage. Set it tonullto remove the current storage
-
destroy
protected void destroy()Destroys all theCreationContextthat has been stored in the current storage -
destroy
Destroys all theCreationContextthat has been stored in the given storage- Parameters:
storage- the storage that we would like to cleanup
-
getInstance
Gives the instance stored with the givenContextualid.- Parameters:
storage- the storage from which we will get the instanceid- the id of the contextual for which we want the instance- Returns:
- the corresponding instance if it exists,
nullotherwise
-
getFromCache
Gets the component from the cache if it has already been registered- Parameters:
data- the data corresponding to the current contextid- the id of the component- Returns:
- the corresponding component if is already in the cache
-
putInCache
Puts in the cache a given object instance corresponding to the given id- Parameters:
data- the data corresponding to the current contextid- the id of the componento- the corresponding instance
-
getThreadContext
Gives the value corresponding to the context of the thread- Specified by:
getThreadContextin interfaceThreadContextHolder- Returns:
- a new instance of
ThreadContextif there are some valuableThreadLocalvariables to share otherwisenullis expected
-