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 anAdvancedContext- Version:
- $Id$
- Author:
- Nicolas Filotto
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractContext.ThreadLocalDataThis 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 Constructor Description AbstractContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidactivate(K key)Activates 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> TgetFromCache(AbstractContext.ThreadLocalData data, String id)Gets 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 LockgetLock(String id)In case the context is sharable, we will need a lock to synchronize the accessesprotected CreationContextStoragegetStorage()Gives the storage to use to store and access to the CreationContextThreadContextgetThreadContext()Gives the value corresponding to the context of the threadbooleanisActive()protected abstract booleanisSharable()Indicates 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 idvoidregister(K key)Registers a new key to the contextprotected voidsetStorage(CreationContextStorage storage)Sets the current storagevoidunregister(K key)Unregisters a given key from the context
-
-
-
Method Detail
-
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
public void activate(K key)
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
public void deactivate(K key)
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
public void register(K key)
Registers a new key to the context- Specified by:
registerin interfaceAdvancedContext<K>- Parameters:
key- the key to register
-
unregister
public void unregister(K key)
Unregisters a given key from the context- Specified by:
unregisterin interfaceAdvancedContext<K>- Parameters:
key- the key to unregister
-
getId
protected <T> String getId(javax.enterprise.context.spi.Contextual<T> contextual)
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
protected abstract Lock getLock(String id)
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
protected abstract CreationContextStorage createStorage(K key)
Creates aCreationContextStorageinstance from the given key- Parameters:
key- the key to use to create theCreationContextStorage- Returns:
- the
CreationContextStoragecorresponding to the given key
-
getStorage
protected CreationContextStorage getStorage()
Gives the storage to use to store and access to the CreationContext- Returns:
- the
CreationContextStoragecorresponding to the current context
-
setStorage
protected void setStorage(CreationContextStorage storage)
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
protected void destroy(CreationContextStorage storage)
Destroys all theCreationContextthat has been stored in the given storage- Parameters:
storage- the storage that we would like to cleanup
-
getInstance
protected <T> T getInstance(CreationContextStorage storage, String id)
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
protected <T> T getFromCache(AbstractContext.ThreadLocalData data, String id)
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
protected void putInCache(AbstractContext.ThreadLocalData data, String id, Object o)
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
public ThreadContext 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
-
-