eXo Kernel :: Container 2.5.0-GA

org.exoplatform.container.context
Class AbstractContext<K>

java.lang.Object
  extended by 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

Version:
$Id$
Author:
Nicolas Filotto

Field Summary
 
Fields inherited from interface org.exoplatform.container.component.ThreadContextHolder
MANAGE_THREAD_LOCAL
 
Constructor Summary
AbstractContext()
           
 
Method Summary
 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> 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.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.enterprise.context.spi.Context
getScope
 

Constructor Detail

AbstractContext

public AbstractContext()
Method Detail

get

public <T> T get(javax.enterprise.context.spi.Contextual<T> contextual,
                 javax.enterprise.context.spi.CreationalContext<T> creationalContext)

Specified by:
get in interface javax.enterprise.context.spi.Context

get

public <T> T get(javax.enterprise.context.spi.Contextual<T> contextual)

Specified by:
get in interface javax.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:
destroy in interface AdvancedContext<K>
Parameters:
contextual - the contextual type

isActive

public boolean isActive()

Specified by:
isActive in interface javax.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:
activate in interface AdvancedContext<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:
deactivate in interface AdvancedContext<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:
register in interface AdvancedContext<K>
Parameters:
key - the key to register

unregister

public void unregister(K key)
Unregisters a given key from the context

Specified by:
unregister in interface AdvancedContext<K>
Parameters:
key - the key to unregister

getId

protected <T> String getId(javax.enterprise.context.spi.Contextual<T> contextual)
Gives an id for the given Contextual

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:
true if the components are sharable, false otherwise.

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 a CreationContextStorage instance from the given key

Parameters:
key - the key to use to create the CreationContextStorage
Returns:
the CreationContextStorage corresponding to the given key

getStorage

protected CreationContextStorage getStorage()
Gives the storage to use to store and access to the CreationContext

Returns:
the CreationContextStorage corresponding to the current context

setStorage

protected void setStorage(CreationContextStorage storage)
Sets the current storage

Parameters:
storage - the new current storage. Set it to null to remove the current storage

destroy

protected void destroy()
Destroys all the CreationContext that has been stored in the current storage


destroy

protected void destroy(CreationContextStorage storage)
Destroys all the CreationContext that 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 given Contextual id.

Parameters:
storage - the storage from which we will get the instance
id - the id of the contextual for which we want the instance
Returns:
the corresponding instance if it exists, null otherwise

getThreadContext

public ThreadContext getThreadContext()
Gives the value corresponding to the context of the thread

Specified by:
getThreadContext in interface ThreadContextHolder
Returns:
a new instance of ThreadContext if there are some valuable ThreadLocal variables to share otherwise null is expected

eXo Kernel :: Container 2.5.0-GA

Copyright © 2014 eXo Platform SAS. All Rights Reserved.