org.jboss.ejb.plugins
Class AbstractInstanceCache

java.lang.Object
  extended byorg.jboss.ejb.plugins.AbstractInstanceCache
All Implemented Interfaces:
AbstractInstanceCacheMBean, ContainerPlugin, InstanceCache, MetricsConstants, Monitorable, org.jboss.system.Service, XmlLoadable
Direct Known Subclasses:
EntityInstanceCache, StatefulSessionInstanceCache

public abstract class AbstractInstanceCache
extends Object
implements InstanceCache, XmlLoadable, Monitorable, MetricsConstants, AbstractInstanceCacheMBean

Base class for caches of entity and stateful beans.

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

Version:
$Revision: 1.32.2.15 $
Author:
Simone Bordet, Bill Burke, Marc Fleury, Scott.Stark@jboss.org

Field Summary
protected static org.jboss.logging.Logger log
           
 
Fields inherited from interface org.jboss.monitor.MetricsConstants
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 acquireContext()
          Acquires an EnterpriseContext from the pool
protected abstract  void activate(EnterpriseContext ctx)
          Activates the given EnterpriseContext
protected abstract  boolean canPassivate(EnterpriseContext ctx)
          Returns whether the given context can be passivated or not
 void create()
           
 void destroy()
           
protected  boolean doActivate(EnterpriseContext ctx)
          Activate the given EnterpriseContext
 void flush()
          Flush the cache.
protected abstract  void freeContext(EnterpriseContext ctx)
          Frees the given EnterpriseContext to the pool
 EnterpriseContext get(Object id)
          Gets a bean instance from this cache given the identity.
protected  org.jboss.util.CachePolicy getCache()
          Returns the cache policy used for this cache.
 Object getCacheLock()
          Returns the mutex used to sync access to the cache policy object
 String getCachePolicyString()
          Display the cache policy.
 long getCacheSize()
          Get the current cache size
protected abstract  Container getContainer()
          Returns the container for this cache.
protected abstract  Object getKey(EnterpriseContext ctx)
          Returns the key used by the cache to map the given context
 long getPassivatedCount()
          Get the passivated count.
 void importXml(Element element)
           
 void insert(EnterpriseContext ctx)
          Inserts an active bean instance after creation or activation.
 boolean isActive(Object id)
          Checks whether an instance corresponding to a particular id is active.
protected  void logActivation(Object id)
           
protected  void logPassivation(Object id)
           
protected abstract  void passivate(EnterpriseContext ctx)
          Passivates the given EnterpriseContext
 void release(EnterpriseContext ctx)
          Releases the given bean instance from this cache.
 void remove(Object id)
          From InstanceCache interface
 void resetStatistic()
           
 Map retrieveStatistic()
           
 void sample(Object s)
          Samples the status of the implementor object and register the status into the snapshot argument.
protected abstract  void setKey(Object id, EnterpriseContext ctx)
          Sets the given id as key for the given context
 void start()
           
 void stop()
           
protected  void tryToPassivate(EnterpriseContext 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
setContainer
 

Field Detail

log

protected static org.jboss.logging.Logger log
Constructor Detail

AbstractInstanceCache

public AbstractInstanceCache()
Method Detail

sample

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

Specified by:
sample in interface Monitorable

retrieveStatistic

public Map retrieveStatistic()

resetStatistic

public void resetStatistic()

get

public EnterpriseContext get(Object id)
                      throws RemoteException,
                             NoSuchObjectException
Description copied from interface: InstanceCache
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
Parameters:
id - The primary key of the bean .
Returns:
The EnterpriseContext related to the given id.
Throws:
RemoteException - In case of illegal calls (concurrent / reentrant)
NoSuchObjectException - if the bean cannot be found.
See Also:
InstanceCache.release(org.jboss.ejb.EnterpriseContext)

insert

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

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

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

tryToPassivate

protected void tryToPassivate(EnterpriseContext ctx)

release

public void release(EnterpriseContext ctx)
Description copied from interface: InstanceCache
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
Parameters:
ctx - The EnterpriseContext to release
See Also:
InstanceCache.get(java.lang.Object)

remove

public void remove(Object id)
From InstanceCache interface

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

isActive

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

Specified by:
isActive in interface InstanceCache
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
Returns:
the size of the cache

flush

public void flush()
Flush the cache.

Specified by:
flush in interface InstanceCache

getPassivatedCount

public long getPassivatedCount()
Get the passivated count.

Specified by:
getPassivatedCount in interface AbstractInstanceCacheMBean
Returns:
the number of passivated instances.

getCachePolicyString

public String getCachePolicyString()
Display the cache policy.

Specified by:
getCachePolicyString in interface AbstractInstanceCacheMBean
Returns:
the cache policy as a string.

importXml

public void importXml(Element element)
               throws org.jboss.deployment.DeploymentException
Specified by:
importXml in interface XmlLoadable
Throws:
org.jboss.deployment.DeploymentException

create

public void create()
            throws Exception
Specified by:
create in interface org.jboss.system.Service
Throws:
Exception

start

public void start()
           throws Exception
Specified by:
start in interface org.jboss.system.Service
Throws:
Exception

stop

public void stop()
Specified by:
stop in interface org.jboss.system.Service

destroy

public void destroy()
Specified by:
destroy in interface org.jboss.system.Service

logActivation

protected void logActivation(Object id)

logPassivation

protected void logPassivation(Object id)

getContainer

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


getCache

protected org.jboss.util.CachePolicy getCache()
Returns the cache policy used for this cache.


getCacheLock

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


passivate

protected abstract void passivate(EnterpriseContext ctx)
                           throws RemoteException
Passivates the given EnterpriseContext

Throws:
RemoteException

activate

protected abstract void activate(EnterpriseContext ctx)
                          throws RemoteException
Activates the given EnterpriseContext

Throws:
RemoteException

doActivate

protected boolean doActivate(EnterpriseContext ctx)
                      throws RemoteException
Activate the given EnterpriseContext

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

acquireContext

protected abstract EnterpriseContext acquireContext()
                                             throws Exception
Acquires an EnterpriseContext from the pool

Throws:
Exception

freeContext

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


getKey

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


setKey

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


canPassivate

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



Copyright © 2002 JBoss Group, LLC. All Rights Reserved.