org.jboss.ejb.plugins
Class AbstractInstanceCache

java.lang.Object
  extended byorg.jboss.ejb.plugins.AbstractInstanceCache
All Implemented Interfaces:
AllowedOperationsFlags (src) , ContainerPlugin (src) , InstanceCache (src) , MetricsConstants (src) , Monitorable (src) , Service (src) , XmlLoadable (src)
Direct Known Subclasses:
EntityInstanceCache (src) , StatefulSessionInstanceCache (src)

public abstract class AbstractInstanceCache
extends java.lang.Object
implements InstanceCache (src) , XmlLoadable (src) , Monitorable (src) , MetricsConstants (src)

Base class for caches of entity and stateful beans.

It manages the cache entries through a CachePolicy (src) object; the implementation of the cache policy object must respect the following requirements:


Field Summary
protected static Logger (src) log
           
 
Fields inherited from interface org.jboss.ejb.AllowedOperationsFlags (src)
IN_AFTER_BEGIN, IN_AFTER_COMPLETION, IN_BEFORE_COMPLETION, IN_BUSINESS_METHOD, IN_EJB_ACTIVATE, IN_EJB_CREATE, IN_EJB_FIND, IN_EJB_HOME, IN_EJB_LOAD, IN_EJB_PASSIVATE, IN_EJB_POST_CREATE, IN_EJB_REMOVE, IN_EJB_STORE, IN_EJB_TIMEOUT, IN_INTERCEPTOR_METHOD, IN_SERVICE_ENDPOINT_METHOD, IN_SET_ENTITY_CONTEXT, IN_SET_MESSAGE_DRIVEN_CONTEXT, IN_SET_SESSION_CONTEXT, IN_UNSET_ENTITY_CONTEXT, NOT_ALLOWED
 
Fields inherited from interface org.jboss.monitor.MetricsConstants (src)
ACTIVITY, APPLICATION, BEAN, BEANCACHE_METRICS, CHECKPOINT, INVOCATION_METRICS, MEMORY_MONITOR, METHOD, PRIMARY_KEY, SYSTEM_METRICS, THREAD_MONITOR, TIME, TYPE
 
Constructor Summary
AbstractInstanceCache()
           
 
Method Summary
protected abstract  EnterpriseContext (src) acquireContext()
          Acquires an EnterpriseContext from the pool
protected abstract  void activate(EnterpriseContext (src)  ctx)
          Activates the given EnterpriseContext
protected abstract  boolean canPassivate(EnterpriseContext (src)  ctx)
          Returns whether the given context can be passivated or not
 void create()
          create the service, do expensive operations etc
 void destroy()
          destroy the service, tear down
protected  boolean doActivate(EnterpriseContext (src)  ctx)
          Activate the given EnterpriseContext
 void flush()
          Flush the cache.
protected abstract  void freeContext(EnterpriseContext (src)  ctx)
          Frees the given EnterpriseContext to the pool
 EnterpriseContext (src) get(java.lang.Object id)
          Gets a bean instance from this cache given the identity.
protected  CachePolicy (src) getCache()
          Returns the cache policy used for this cache.
 java.lang.Object getCacheLock()
          Returns the mutex used to sync access to the cache policy object
 java.lang.String getCachePolicyString()
          Display the cache policy.
 long getCacheSize()
          Get the current cache size
protected abstract  Container (src) getContainer()
          Returns the container for this cache.
protected abstract  java.lang.Object getKey(EnterpriseContext (src)  ctx)
          Returns the key used by the cache to map the given context
 long getPassivatedCount()
          Get the passivated count.
 void importXml(org.w3c.dom.Element element)
           
 void insert(EnterpriseContext (src)  ctx)
          Inserts an active bean instance after creation or activation.
 boolean isActive(java.lang.Object id)
          Checks whether an instance corresponding to a particular id is active.
protected  void logActivation(java.lang.Object id)
           
protected  void logPassivation(java.lang.Object id)
           
protected abstract  void passivate(EnterpriseContext (src)  ctx)
          Passivates the given EnterpriseContext
 void release(EnterpriseContext (src)  ctx)
          Releases the given bean instance from this cache.
 void remove(java.lang.Object id)
          From InstanceCache interface
 void resetStatistic()
           
 java.util.Map retrieveStatistic()
           
 void sample(java.lang.Object s)
          Samples the status of the implementor object and register the status into the snapshot argument.
protected abstract  void setKey(java.lang.Object id, EnterpriseContext (src)  ctx)
          Sets the given id as key for the given context
 void start()
          start the service, create is already called
 void stop()
          stop the service
protected  void tryToPassivate(EnterpriseContext (src)  ctx)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.ejb.ContainerPlugin (src)
setContainer
 

Field Detail

log

protected static Logger (src)  log
Constructor Detail

AbstractInstanceCache

public AbstractInstanceCache()
Method Detail

sample

public void sample(java.lang.Object s)
Description copied from interface: Monitorable (src)
Samples the status of the implementor object and register the status into the snapshot argument.

Specified by:
sample in interface Monitorable (src)

retrieveStatistic

public java.util.Map retrieveStatistic()

resetStatistic

public void resetStatistic()

get

public EnterpriseContext (src)  get(java.lang.Object id)
                      throws java.rmi.RemoteException,
                             java.rmi.NoSuchObjectException
Description copied from interface: InstanceCache (src)
Gets a bean instance from this cache given the identity. This method may involve activation if the instance is not in the cache.

Implementation should have O(1) complexity.

This method is never called for stateless session beans.

Specified by:
get in interface InstanceCache (src)
Parameters:
id - The primary key of the bean .
Returns:
The EnterpriseContext related to the given id.
Throws:
java.rmi.NoSuchObjectException - if the bean cannot be found.
java.rmi.RemoteException - In case of illegal calls (concurrent / reentrant)
See Also:
InstanceCache.release(org.jboss.ejb.EnterpriseContext)

insert

public void insert(EnterpriseContext (src)  ctx)
Description copied from interface: InstanceCache (src)
Inserts an active bean instance after creation or activation.

Implementation should guarantee proper locking and O(1) complexity.

Specified by:
insert in interface InstanceCache (src)
Parameters:
ctx - The EnterpriseContext to insert in the cache
See Also:
InstanceCache.remove(java.lang.Object)

tryToPassivate

protected void tryToPassivate(EnterpriseContext (src)  ctx)

release

public void release(EnterpriseContext (src)  ctx)
Description copied from interface: InstanceCache (src)
Releases the given bean instance from this cache. This method may passivate the bean to get it out of the cache. Implementation should return almost immediately leaving the passivation to be executed by another thread.

Specified by:
release in interface InstanceCache (src)
Parameters:
ctx - The EnterpriseContext to release
See Also:
InstanceCache.get(java.lang.Object)

remove

public void remove(java.lang.Object id)
From InstanceCache interface

Specified by:
remove in interface InstanceCache (src)
Parameters:
id - The pimary key of the bean.
See Also:
InstanceCache.insert(org.jboss.ejb.EnterpriseContext)

isActive

public boolean isActive(java.lang.Object id)
Description copied from interface: InstanceCache (src)
Checks whether an instance corresponding to a particular id is active.

Specified by:
isActive in interface InstanceCache (src)
Parameters:
id - The pimary key of the bean.
See Also:
InstanceCache.insert(org.jboss.ejb.EnterpriseContext)

getCacheSize

public long getCacheSize()
Get the current cache size

Specified by:
getCacheSize in interface InstanceCache (src)
Returns:
the size of the cache

flush

public void flush()
Flush the cache.

Specified by:
flush in interface InstanceCache (src)

getPassivatedCount

public long getPassivatedCount()
Get the passivated count.

Returns:
the number of passivated instances.

getCachePolicyString

public java.lang.String getCachePolicyString()
Display the cache policy.

Returns:
the cache policy as a string.

importXml

public void importXml(org.w3c.dom.Element element)
               throws DeploymentException (src) 
Specified by:
importXml in interface XmlLoadable (src)
Throws:
DeploymentException (src)

create

public void create()
            throws java.lang.Exception
Description copied from interface: Service (src)
create the service, do expensive operations etc

Specified by:
create in interface Service (src)
Throws:
java.lang.Exception

start

public void start()
           throws java.lang.Exception
Description copied from interface: Service (src)
start the service, create is already called

Specified by:
start in interface Service (src)
Throws:
java.lang.Exception

stop

public void stop()
Description copied from interface: Service (src)
stop the service

Specified by:
stop in interface Service (src)

destroy

public void destroy()
Description copied from interface: Service (src)
destroy the service, tear down

Specified by:
destroy in interface Service (src)

logActivation

protected void logActivation(java.lang.Object id)

logPassivation

protected void logPassivation(java.lang.Object id)

getContainer

protected abstract Container (src)  getContainer()
Returns the container for this cache.


getCache

protected CachePolicy (src)  getCache()
Returns the cache policy used for this cache.


getCacheLock

public java.lang.Object getCacheLock()
Returns the mutex used to sync access to the cache policy object


passivate

protected abstract void passivate(EnterpriseContext (src)  ctx)
                           throws java.rmi.RemoteException
Passivates the given EnterpriseContext

Throws:
java.rmi.RemoteException

activate

protected abstract void activate(EnterpriseContext (src)  ctx)
                          throws java.rmi.RemoteException
Activates the given EnterpriseContext

Throws:
java.rmi.RemoteException

doActivate

protected boolean doActivate(EnterpriseContext (src)  ctx)
                      throws java.rmi.RemoteException
Activate the given EnterpriseContext

Parameters:
ctx - the context
Returns:
false if we recursively activating
Throws:
java.rmi.RemoteException - for any error

acquireContext

protected abstract EnterpriseContext (src)  acquireContext()
                                             throws java.lang.Exception
Acquires an EnterpriseContext from the pool

Throws:
java.lang.Exception

freeContext

protected abstract void freeContext(EnterpriseContext (src)  ctx)
Frees the given EnterpriseContext to the pool


getKey

protected abstract java.lang.Object getKey(EnterpriseContext (src)  ctx)
Returns the key used by the cache to map the given context


setKey

protected abstract void setKey(java.lang.Object id,
                               EnterpriseContext (src)  ctx)
Sets the given id as key for the given context


canPassivate

protected abstract boolean canPassivate(EnterpriseContext (src)  ctx)
Returns whether the given context can be passivated or not