FileDocCategorySizeDatePackage
NoPassivationCache.javaAPI DocJBoss 4.2.14774Fri Jul 13 20:53:48 BST 2007org.jboss.ejb3.cache

NoPassivationCache

public class NoPassivationCache extends Object implements StatefulCache
Comment
author
Bill Burke
version
$Revision: 61329 $

Fields Summary
private org.jboss.ejb3.Pool
pool
private HashMap
cacheMap
protected int
createCount
protected int
removeCount
Constructors Summary
public NoPassivationCache()

   
Methods Summary
public org.jboss.ejb3.stateful.StatefulBeanContextcreate()

      StatefulBeanContext ctx = null;
      try
      {
         ctx = (StatefulBeanContext) pool.get();
         ++createCount;
         synchronized (cacheMap)
         {
            cacheMap.put(ctx.getId(), ctx);
         }
      }
      catch (EJBException e)
      {
         e.printStackTrace();
         throw e;
      }
      catch (Exception e)
      {
         e.printStackTrace();
         throw new EJBException(e);
      }
      return ctx;
   
public org.jboss.ejb3.stateful.StatefulBeanContextcreate(java.lang.Class[] initTypes, java.lang.Object[] initValues)

      StatefulBeanContext ctx = null;
      try
      {
         ctx = (StatefulBeanContext) pool.get(initTypes, initValues);
         synchronized (cacheMap)
         {
            cacheMap.put(ctx.getId(), ctx);
         }
      }
      catch (EJBException e)
      {
         throw e;
      }
      catch (Exception e)
      {
         throw new EJBException(e);
      }
      return ctx;
   
public voidfinished(org.jboss.ejb3.stateful.StatefulBeanContext ctx)

      synchronized (ctx)
      {
         ctx.setInUse(false);
         ctx.lastUsed = System.currentTimeMillis();
      }
   
public org.jboss.ejb3.stateful.StatefulBeanContextget(java.lang.Object key)

      return get(key, true);
   
public org.jboss.ejb3.stateful.StatefulBeanContextget(java.lang.Object key, boolean markInUse)

      StatefulBeanContext entry = null;
      synchronized (cacheMap)
      {
         entry = (StatefulBeanContext) cacheMap.get(key);
      }
      
      if (entry == null)
      {
         throw new NoSuchEJBException("Could not find Stateful bean: " + key);
      }      
      
      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 intgetAvailableCount()

      return -1;
   
public intgetCacheSize()

	   return cacheMap.size();
   
public intgetCreateCount()

	   return createCount;
   
public intgetCurrentSize()

      return cacheMap.size();
   
public intgetMaxSize()

      return -1;
   
public intgetPassivatedCount()

	   return 0;
   
public intgetRemoveCount()

      return removeCount;
   
public intgetTotalSize()

      return cacheMap.size();
   
public voidinitialize(org.jboss.ejb3.Container container)


        
   
      this.pool = container.getPool();
      cacheMap = new HashMap();
   
public voidremove(java.lang.Object key)

      StatefulBeanContext ctx = null;
      synchronized (cacheMap)
      {
         ctx = (StatefulBeanContext) cacheMap.remove(key);
      }
      if (ctx != null)
      {
         pool.remove(ctx);
         ++removeCount;
      }
   
public voidstart()

   
public voidstop()

      synchronized (cacheMap)
      {
         cacheMap.clear();
      }