Methods Summary |
---|
public org.jboss.ejb3.stateful.StatefulBeanContext | create()
StatefulBeanContext ctx = null;
try
{
ctx = (StatefulBeanContext) pool.get();
if (log.isTraceEnabled())
{
log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
}
synchronized (cacheMap)
{
cacheMap.put(ctx.getId(), ctx);
}
ctx.setInUse(true);
ctx.lastUsed = System.currentTimeMillis();
++createCount;
}
catch (EJBException e)
{
e.printStackTrace();
throw e;
}
catch (Exception e)
{
e.printStackTrace();
throw new EJBException(e);
}
return ctx;
|
public org.jboss.ejb3.stateful.StatefulBeanContext | create(java.lang.Class[] initTypes, java.lang.Object[] initValues)
StatefulBeanContext ctx = null;
try
{
ctx = (StatefulBeanContext) pool.get(initTypes, initValues);
if (log.isTraceEnabled())
{
log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
}
synchronized (cacheMap)
{
cacheMap.put(ctx.getId(), ctx);
}
ctx.setInUse(true);
ctx.lastUsed = System.currentTimeMillis();
++createCount;
}
catch (EJBException e)
{
e.printStackTrace();
throw e;
}
catch (Exception e)
{
e.printStackTrace();
throw new EJBException(e);
}
return ctx;
|
public void | finished(org.jboss.ejb3.stateful.StatefulBeanContext ctx)
synchronized (ctx)
{
ctx.setInUse(false);
ctx.lastUsed = System.currentTimeMillis();
if (ctx.markedForPassivation)
{
passivate(ctx);
}
}
|
public org.jboss.ejb3.stateful.StatefulBeanContext | get(java.lang.Object key)
return get(key, true);
|
public org.jboss.ejb3.stateful.StatefulBeanContext | get(java.lang.Object key, boolean markInUse)
StatefulBeanContext entry = null;
synchronized (cacheMap)
{
entry = (StatefulBeanContext) cacheMap.get(key);
}
if (entry == null)
{
entry = (StatefulBeanContext) pm.activateSession(key);
if (entry == null)
{
throw new NoSuchEJBException("Could not find stateful bean: " + key);
}
--passivatedCount;
// We cache the entry even if we will throw an exception below
// as we may still need it for its children and XPC references
if (log.isTraceEnabled())
{
log.trace("Caching activated context " + entry.getId() + " of type " + entry.getClass());
}
synchronized (cacheMap)
{
cacheMap.put(key, entry);
}
}
// Now we know entry isn't null
if (markInUse)
{
if (entry.isRemoved())
{
throw new NoSuchEJBException("Could not find stateful bean: " + key +
" (bean was marked as removed");
}
entry.setInUse(true);
entry.lastUsed = System.currentTimeMillis();
}
return entry;
|
public int | getAvailableCount()
return -1;
|
public int | getCacheSize()
return cacheMap.size();
|
public int | getCreateCount()
return createCount;
|
public int | getCurrentSize()
return cacheMap.size();
|
public int | getMaxSize()
return maxSize;
|
public int | getPassivatedCount()
return passivatedCount;
|
public int | getRemoveCount()
return removeCount;
|
public int | getTotalSize()
return cacheMap.size() + pm.getNumPassivatedBeans();
|
public void | initialize(org.jboss.ejb3.Container container)
Advisor advisor = (Advisor) container;
this.pool = container.getPool();
cacheMap = new CacheMap();
PersistenceManager pmConfig = (PersistenceManager) advisor.resolveAnnotation(PersistenceManager.class);
this.pm = (StatefulSessionPersistenceManager) pmConfig.value().newInstance();
pm.initialize(container);
CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
maxSize = config.maxSize();
sessionTimeout = config.idleTimeoutSeconds();
removalTimeout = config.removalTimeoutSeconds();
log = Logger.getLogger(getClass().getName() + "." + container.getEjbName());
log.debug("Initializing SimpleStatefulCache with maxSize: " +maxSize + " timeout: " +sessionTimeout +
" for " +container.getObjectName().getCanonicalName() );
timeoutTask = new SessionTimeoutTask("SFSB Passivation Thread - " + container.getObjectName().getCanonicalName());
if (removalTimeout > 0)
removalTask = new RemovalTimeoutTask("SFSB Removal Thread - " + container.getObjectName().getCanonicalName());
|
protected void | passivate(org.jboss.ejb3.stateful.StatefulBeanContext ctx)
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader(((EJBContainer) ctx.getContainer()).getClassloader());
pm.passivateSession(ctx);
++passivatedCount;
}
finally
{
Thread.currentThread().setContextClassLoader(oldCl);
}
|
public void | remove(java.lang.Object key)
StatefulBeanContext ctx = null;
synchronized (cacheMap)
{
ctx = (StatefulBeanContext) cacheMap.get(key);
}
if (ctx != null)
{
if (!ctx.isRemoved())
pool.remove(ctx);
++removeCount;
if (ctx.getCanRemoveFromCache())
{
synchronized (cacheMap)
{
cacheMap.remove(key);
}
}
}
|
public void | start()
running = true;
timeoutTask.start();
if (removalTask != null)
removalTask.start();
|
public void | stop()
synchronized (cacheMap)
{
running = false;
timeoutTask.interrupt();
if (removalTask != null)
removalTask.interrupt();
cacheMap.clear();
try
{
pm.destroy();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
|