User: starksm 
  Date: 02/04/13 11:27:20

  Modified:    src/main/org/jboss/ejb/plugins AbstractInstanceCache.java
                        EntityInstanceCache.java
                        LRUEnterpriseContextCachePolicy.java
                        LRUStatefulContextCachePolicy.java
                        NoPassivationCachePolicy.java
                        StatefulSessionInstanceCache.java
  Added:       src/main/org/jboss/ejb/plugins AbstractPassivationJob.java
  Removed:     src/main/org/jboss/ejb/plugins
                        EnterpriseContextCachePolicy.java
  Log:
  Cleanup the shutdown of the cache and pool.
  Remove the JMS notification messages from the AbstractInstanceCache.
  
  Revision  Changes    Path
  1.29      +27 -247   jboss/src/main/org/jboss/ejb/plugins/AbstractInstanceCache.java
  
  Index: AbstractInstanceCache.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInstanceCache.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- AbstractInstanceCache.java        22 Feb 2002 04:24:55 -0000      1.28
  +++ AbstractInstanceCache.java        13 Apr 2002 18:27:20 -0000      1.29
  @@ -11,21 +11,9 @@
   import java.rmi.RemoteException;
   import java.rmi.NoSuchObjectException;
   import java.util.Collections;
  -import java.util.Map;
   import java.util.HashMap;
  -
  -import javax.ejb.EJBException;
  -import javax.jms.Topic;
  -import javax.jms.TopicPublisher;
  -import javax.jms.TopicSession;
  -import javax.jms.TopicConnection;
  -import javax.jms.TopicConnectionFactory;
  -import javax.jms.Message;
  -import javax.jms.Session;
  -import javax.jms.JMSException;
  -import javax.naming.Context;
  -import javax.naming.InitialContext;
  -import javax.rmi.PortableRemoteObject;
  +import java.util.Iterator;
  +import java.util.Map;
   
   import org.w3c.dom.Element;
   
  @@ -43,7 +31,6 @@
   import org.jboss.monitor.client.BeanCacheSnapshot;
   import org.jboss.monitor.MetricsConstants;
   import org.jboss.util.CachePolicy;
  -import org.jboss.util.Executable;
   import org.jboss.util.WorkerQueue;
   
   /**
  @@ -61,7 +48,7 @@
    * @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
    * @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
    *
  - * @version $Revision: 1.28 $
  + * @version $Revision: 1.29 $
    *
    *   <p><b>Revisions:</b>
    *
  @@ -120,11 +107,6 @@
      private boolean m_jmsMonitoring;
      /* Useful for log messages */
      private StringBuffer m_buffer = new StringBuffer();
  -   /* JMS log members */
  -   private TopicConnection m_jmsConnection;
  -   private Topic m_jmsTopic;
  -   private TopicSession m_jmsSession;
  -   private TopicPublisher m_jmsPublisher;
   
      // Static --------------------------------------------------------
   
  @@ -133,6 +115,9 @@
      // Monitorable implementation ------------------------------------
      public void sample(Object s)
      {
  +      if( m_cache == null )
  +         return;
  +
         synchronized (getCacheLock())
         {
            BeanCacheSnapshot snapshot = (BeanCacheSnapshot)s;
  @@ -156,40 +141,6 @@
      public void setJMSMonitoringEnabled(boolean enable) {m_jmsMonitoring = enable;}
      public boolean isJMSMonitoringEnabled() {return m_jmsMonitoring;}
   
  -   public void sendMessage(Message message)
  -   {
  -      try
  -      {
  -         message.setJMSType(BEANCACHE_METRICS);
  -         message.setJMSExpiration(5000);
  -         message.setLongProperty(TIME, System.currentTimeMillis());
  -         m_jmsPublisher.publish(m_jmsTopic, message);
  -      }
  -      catch (JMSException x)
  -      {
  -         log.error("sendMessage failed", x);
  -      }
  -   }
  -   public Message createMessage(Object id)
  -   {
  -      Message message = null;
  -      try
  -      {
  -         message = m_jmsSession.createMessage();
  -         message.setStringProperty(APPLICATION, 
getContainer().getEjbModule().getName());
  -         message.setStringProperty(BEAN, 
getContainer().getBeanMetaData().getEjbName());
  -         if (id != null)
  -         {
  -            message.setStringProperty(PRIMARY_KEY, id.toString());
  -         }
  -      }
  -      catch (JMSException x)
  -      {
  -         log.error("createMessage failed", x);
  -      }
  -      return message;
  -   }
  -
      /* From InstanceCache interface */
      public EnterpriseContext get(Object id)
         throws RemoteException, NoSuchObjectException
  @@ -350,32 +301,11 @@
      {
         getCache().create();
         m_passivationHelper = new PassivationHelper();
  -      String threadName = "Passivator Thread for " + 
getContainer().getBeanMetaData().getEjbName();
  -
  -      if (isJMSMonitoringEnabled())
  -      {
  -         // Setup JMS for cache monitoring
  -         Context namingContext = new InitialContext();
  -         Object factoryRef = namingContext.lookup("TopicConnectionFactory");
  -         TopicConnectionFactory factory = 
(TopicConnectionFactory)PortableRemoteObject.narrow(factoryRef, 
TopicConnectionFactory.class);
  -
  -         m_jmsConnection = factory.createTopicConnection();
  -
  -         Object topicRef = namingContext.lookup("topic/metrics");
  -         m_jmsTopic = (Topic)PortableRemoteObject.narrow(topicRef, Topic.class);
  -         m_jmsSession = m_jmsConnection.createTopicSession(false, 
Session.DUPS_OK_ACKNOWLEDGE);
  -         m_jmsPublisher = m_jmsSession.createPublisher(m_jmsTopic);
  -      }
      }
      /* From Service interface*/
      public void start() throws Exception
      {
         getCache().start();
  -
  -      if (isJMSMonitoringEnabled())
  -      {
  -         m_jmsConnection.start();
  -      }
      }
      /* From Service interface*/
      public void stop()
  @@ -385,29 +315,15 @@
         {
            getCache().stop();
         }
  -
  -
  -      if (isJMSMonitoringEnabled() && m_jmsConnection != null)
  -      {
  -         try
  -         {
  -            m_jmsConnection.stop();
  -         }
  -         catch (JMSException ignored) {}
  -      }
      }
      /* From Service interface*/
      public void destroy()
      {
         getCache().destroy();
  -      if (isJMSMonitoringEnabled() && m_jmsConnection != null)
  -      {
  -         try
  -         {
  -            m_jmsConnection.close();
  -         }
  -         catch (JMSException ignored) {}
  -      }
  +      this.m_cache = null;
  +      m_passivationHelper.clear();
  +      m_passivationHelper = null;
  +      m_buffer.setLength(0);
      }
   
      // Y overrides ---------------------------------------------------
  @@ -424,6 +340,7 @@
         m_passivationHelper.schedule(ctx);
         logPassivationScheduled(getKey(ctx));
      }
  +
      /**
       * Tries to unschedule the given EnterpriseContext for passivation; returns
       * the unscheduled context if it wasn't passivated yet, null if the
  @@ -446,23 +363,6 @@
            m_buffer.append(id);
            log.trace(m_buffer.toString());
         }
  -
  -      if (isJMSMonitoringEnabled())
  -      {
  -         // Prepare JMS message
  -         Message message = createMessage(id);
  -         try
  -         {
  -            message.setStringProperty(TYPE, "ACTIVATION");
  -         }
  -         catch (JMSException x)
  -         {
  -            log.error("createMessage failed", x);
  -         }
  -
  -         // Send JMS Message
  -         sendMessage(message);
  -      }
      }
   
      protected void logPassivationScheduled(Object id)
  @@ -476,24 +376,6 @@
            m_buffer.append(id);
            log.trace(m_buffer.toString());
         }
  -
  -      if (isJMSMonitoringEnabled())
  -      {
  -         // Prepare JMS message
  -         Message message = createMessage(id);
  -         try
  -         {
  -            message.setStringProperty(TYPE, "PASSIVATION");
  -            message.setStringProperty(ACTIVITY, "SCHEDULED");
  -         }
  -         catch (JMSException x)
  -         {
  -            log.error("createMessage failed", x);
  -         }
  -
  -         // Send JMS Message
  -         sendMessage(message);
  -      }
      }
   
      protected void logPassivation(Object id)
  @@ -507,25 +389,6 @@
            m_buffer.append(id);
            log.trace(m_buffer.toString());
         }
  -
  -
  -      if (isJMSMonitoringEnabled())
  -      {
  -         // Prepare JMS message
  -         Message message = createMessage(id);
  -         try
  -         {
  -            message.setStringProperty(TYPE, "PASSIVATION");
  -            message.setStringProperty(ACTIVITY, "PASSIVATED");
  -         }
  -         catch (JMSException x)
  -         {
  -            log.error("createMessage failed", x);
  -         }
  -
  -         // Send JMS Message
  -         sendMessage(message);
  -      }
      }
   
      protected void logPassivationPostponed(Object id)
  @@ -539,24 +402,6 @@
            m_buffer.append(id);
            log.trace(m_buffer.toString());
         }
  -
  -      if (isJMSMonitoringEnabled())
  -      {
  -         // Prepare JMS message
  -         Message message = createMessage(id);
  -         try
  -         {
  -            message.setStringProperty(TYPE, "PASSIVATION");
  -            message.setStringProperty(ACTIVITY, "POSTPONED");
  -         }
  -         catch (JMSException x)
  -         {
  -            log.error("createMessage failed", x);
  -         }
  -
  -         // Send JMS Message
  -         sendMessage(message);
  -      }
      }
   
      /**
  @@ -620,6 +465,18 @@
            m_passivationJobs = Collections.synchronizedMap(new HashMap());
         }
   
  +      protected void clear()
  +      {
  +         log.debug("Cancelling "+m_passivationJobs.size()+" passivation jobs");
  +         Iterator iter = m_passivationJobs.values().iterator();
  +         while( iter.hasNext() )
  +         {
  +            PassivationJob job = (PassivationJob) iter.next();
  +            job.cancel();
  +         }
  +         m_passivationJobs.clear();
  +      }
  +
         /**
          * Creates and schedules a {@link PassivationJob} for passivation
          */
  @@ -633,11 +490,10 @@
               // with a valid key because it may get freed to the InstancePool, then
               // reused before the PassivationJob executes.
               // marcf, actually for simplicity I have removed the "freed" call in 
the pool (check entity pool)
  -            PassivationJob job = new PassivationJob(bean, key)
  +            AbstractPassivationJob job = new AbstractPassivationJob(bean, key)
                  {
                     public void execute() throws Exception
                     {
  -                     EnterpriseContext ctx = this.getEnterpriseContext();
                        if (ctx.getId() == null)
                        {
                           // If this happens, then a passivation request for this 
bean was issued
  @@ -646,7 +502,6 @@
                        }
   
                        Object id = this.getKey();
  -
                        /**
                         * Synchronization / Passivation explanations:
                         * The instance interceptor (II) first acquires the Sync 
object associated
  @@ -694,9 +549,11 @@
                                 {
                                    // Verify that this ctx hasn't already
                                    // been freed and re-used by another thread.
  -                                 if 
(!((EntityEnterpriseContext)ctx).getCacheKey().equals(id))
  +                                 EntityEnterpriseContext entityCtx = 
(EntityEnterpriseContext) ctx;
  +                                 if( entityCtx.getCacheKey().equals(id) == false )
                                    {
                                       // ctx has been freed then re-used in another 
thread.
  +                                    entityCtx = null;
                                       return;
                                    }
                                 }
  @@ -816,80 +673,3 @@
         }
      }
   }
  -
  -/**
  - * Abstract class for passivation jobs.
  - * Subclasses should implement {@link #execute} synchronizing it in some way because
  - * the execute method is normally called in the passivation thread,
  - * while the cancel method is normally called from another thread.
  - * To avoid that subclasses override methods of this class without
  - * make them synchronized (except execute of course), they're declared final.
  - */
  -abstract class PassivationJob implements Executable
  -{
  -   private EnterpriseContext m_context;
  -   private Object m_key;
  -   private boolean m_cancelled;
  -   private boolean m_executed;
  -
  -   PassivationJob(EnterpriseContext ctx, Object key)
  -   {
  -      m_context = ctx;
  -      m_key = key;
  -   }
  -
  -   public abstract void execute() throws Exception;
  -
  -   /**
  -    * (Bill Burke) We can't rely on the EnterpriseContext to provide PassivationJob
  -    * with a valid key because it may get freed to the InstancePool, then
  -    * reused before the PassivationJob executes.
  -    */
  -   final Object getKey()
  -   {
  -      return m_key;
  -   }
  -   /**
  -    * Returns the EnterpriseContext associated with this passivation job,
  -    * so the bean that will be passivated.
  -    * No need to synchronize access to this method, since the returned
  -    * reference is immutable
  -    */
  -   final EnterpriseContext getEnterpriseContext()
  -   {
  -      return m_context;
  -   }
  -   /**
  -    * Mark this job for cancellation.
  -    * @see #isCancelled
  -    */
  -   final synchronized void cancel()
  -   {
  -      m_cancelled = true;
  -   }
  -   /**
  -    * Returns whether this job has been marked for cancellation
  -    * @see #cancel
  -    */
  -   final synchronized boolean isCancelled()
  -   {
  -      return m_cancelled;
  -   }
  -   /**
  -    * Mark this job as executed
  -    * @see #isExecuted
  -    */
  -   final synchronized void executed()
  -   {
  -      m_executed = true;
  -   }
  -   /**
  -    * Returns whether this job has been executed
  -    * @see #executed
  -    */
  -   final synchronized boolean isExecuted()
  -   {
  -      return m_executed;
  -   }
  -}
  -
  
  
  
  1.16      +2 -1      jboss/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java
  
  Index: EntityInstanceCache.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- EntityInstanceCache.java  12 Apr 2002 19:30:42 -0000      1.15
  +++ EntityInstanceCache.java  13 Apr 2002 18:27:20 -0000      1.16
  @@ -20,7 +20,7 @@
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
    * @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
  - * @version $Revision: 1.15 $
  + * @version $Revision: 1.16 $
    *
    * <p><b>Revisions:</b>
    * <p><b>2001/01/29: billb</b>
  @@ -82,6 +82,7 @@
      public void destroy()
      {
         this.m_container = null;
  +      super.destroy();
      }
   
        protected Object getKey(EnterpriseContext ctx) 
  
  
  
  1.16      +70 -207   
jboss/src/main/org/jboss/ejb/plugins/LRUEnterpriseContextCachePolicy.java
  
  Index: LRUEnterpriseContextCachePolicy.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/LRUEnterpriseContextCachePolicy.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- LRUEnterpriseContextCachePolicy.java      15 Jan 2002 22:55:13 -0000      1.15
  +++ LRUEnterpriseContextCachePolicy.java      13 Apr 2002 18:27:20 -0000      1.16
  @@ -7,16 +7,15 @@
   package org.jboss.ejb.plugins;
   
   import java.util.HashMap;
  -import java.util.Map;
  -import javax.jms.Message;
  -import javax.jms.JMSException;
  +import java.util.Timer;
  +import java.util.TimerTask;
   
  -import org.jboss.util.LRUCachePolicy;
  -import org.jboss.util.TimerTask;
   import org.jboss.deployment.DeploymentException;
   import org.jboss.ejb.EnterpriseContext;
  +import org.jboss.logging.Logger;
   import org.jboss.metadata.XmlLoadable;
   import org.jboss.metadata.MetaData;
  +import org.jboss.util.LRUCachePolicy;
   import org.w3c.dom.Element;
   
   import org.jboss.monitor.Monitorable;
  @@ -27,15 +26,21 @@
    *
    * @see AbstractInstanceCache
    * @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
  - * @version $Revision: 1.15 $
  + * @version $Revision: 1.16 $
    */
   public class LRUEnterpriseContextCachePolicy
      extends LRUCachePolicy
  -   implements EnterpriseContextCachePolicy, XmlLoadable, Monitorable
  +   implements XmlLoadable, Monitorable
   {
      // Constants -----------------------------------------------------
   
      // Attributes ----------------------------------------------------
  +   protected static Logger log = 
Logger.getLogger(LRUEnterpriseContextCachePolicy.class);
  +   protected static Timer tasksTimer = new Timer(true);
  +   static
  +   {
  +      log.debug("Cache policy timer started, tasksTimer="+tasksTimer);
  +   }
   
      /** The AbstractInstanceCache that uses this cache policy */
      private AbstractInstanceCache m_cache;
  @@ -100,6 +105,9 @@
   
      public void sample(Object s)
      {
  +      if( m_cache == null )
  +         return;
  +
         BeanCacheSnapshot snapshot = (BeanCacheSnapshot)s;
         LRUList list = getList();
         synchronized (m_cache.getCacheLock())
  @@ -118,26 +126,31 @@
         if (m_resizerPeriod > 0)
         {
            m_resizer = new ResizerTask(m_resizerPeriod);
  -         scheduler.schedule(m_resizer, (long)(Math.random() * m_resizerPeriod));
  +         tasksTimer.schedule(m_resizer, (long)(Math.random() * m_resizerPeriod));
         }
                                
         if (m_overagerPeriod > 0) 
         {
            m_overager = new OveragerTask(m_overagerPeriod);
  -         scheduler.schedule(m_overager, (long)(Math.random() * m_overagerPeriod));
  +         tasksTimer.schedule(m_overager, (long)(Math.random() * m_overagerPeriod));
         }
  -             
  -      // TimerTask used only to debug
  -      //             scheduler.schedule(new CacheDumper(), 3000L);
      }
  -     
  +
      public void stop() 
      {
         if (m_resizer != null) {m_resizer.cancel();}
         if (m_overager != null) {m_overager.cancel();}
         super.stop();
      }
  -   
  +
  +   public void destroy()
  +   {
  +      m_overager = null;
  +      m_resizer = null;
  +      m_cache = null;
  +      super.destroy();
  +   }
  +
      /**
       * Reads from the configuration the parameters for this cache policy, that are
       * all optionals.
  @@ -227,13 +240,18 @@
   
      // Protected -----------------------------------------------------
   
  -   protected LRUList createList() {
  +   protected LRUList createList()
  +   {
         return new ContextLRUList();
      }
   
      protected void ageOut(LRUCacheEntry entry) 
      {
  -      if (entry == null) {
  +      if( m_cache == null )
  +         return;
  +
  +      if (entry == null)
  +      {
            throw new IllegalArgumentException
               ("Cannot remove a null cache entry");
         }
  @@ -246,65 +264,23 @@
         m_buffer.append("; cache size = ");
         m_buffer.append(getList().m_count);
         log.debug(m_buffer.toString());
  -             
  -      if (m_cache.isJMSMonitoringEnabled()) 
  -      {
  -         // Prepare JMS message
  -         Message message = m_cache.createMessage(entry.m_key);
  -         try 
  -         {
  -            message.setStringProperty("TYPE", "CACHE");
  -            message.setStringProperty("ACTIVITY", "AGE-OUT");
  -         }
  -         catch (JMSException x) 
  -         {
  -            log.error("createMessage failed", x);
  -         }
  -                     
  -         // Send JMS Message
  -         m_cache.sendMessage(message);
  -      }
  -
  -      // Debug code
  -      //             new Exception().printStackTrace();
  -      //             new CacheDumper().execute();
   
         // This will schedule the passivation
         m_cache.release((EnterpriseContext)entry.m_object);
      }
  -   
  +
      protected void cacheMiss() 
      {
         LRUList list = getList();
         ++list.m_cacheMiss;
  -
  -      if (m_cache.isJMSMonitoringEnabled()) 
  -      {
  -         // Prepare JMS message
  -         Message message = m_cache.createMessage(null);
  -         try 
  -         {
  -            message.setStringProperty("TYPE", "CACHE");
  -            message.setStringProperty("ACTIVITY", "CACHE-MISS");
  -         }
  -         catch (JMSException x) 
  -         {
  -            log.error("createMessage failed", x);
  -         }
  -                     
  -         // Send JMS Message
  -         m_cache.sendMessage(message);
  -      }
      }
   
      // Private -------------------------------------------------------
   
  -   private LRUList getList() {
  +   private LRUList getList()
  +   {
         return m_list;
      }
  -   
  -   // For debug purposes
  -   //        private java.util.Map getMap() {return m_map;}
   
      // Inner classes -------------------------------------------------
      
  @@ -319,26 +295,32 @@
      {
         private String m_message;
         private StringBuffer m_buffer;
  +      private long resizerPeriod;
   
         protected ResizerTask(long resizerPeriod) 
         {
  -         super(resizerPeriod);
  +         this.resizerPeriod = resizerPeriod;
            m_message = "Resized cache for bean " +
               m_cache.getContainer().getBeanMetaData().getEjbName() +
               ": old capacity = ";
            m_buffer = new StringBuffer();
         }
         
  -      public void execute() 
  +      public void run() 
         {
            // For now implemented as a Cache Miss Frequency algorithm
  +         if( m_cache == null )
  +         {
  +            cancel();
  +            return;
  +         }
   
            LRUList list = getList();
   
            // Sync with the cache, since it is accessed also by another thread
            synchronized (m_cache.getCacheLock())
            {
  -            int period = list.m_cacheMiss == 0 ? Integer.MAX_VALUE : 
(int)(getPeriod() / list.m_cacheMiss);
  +            int period = list.m_cacheMiss == 0 ? Integer.MAX_VALUE : 
(int)(resizerPeriod / list.m_cacheMiss);
               int cap = list.m_capacity;
               if (period <= m_minPeriod && cap < list.m_maxCapacity) 
               {
  @@ -370,26 +352,6 @@
            m_buffer.append(", new capacity = ");
            m_buffer.append(newCapacity);
            log.debug(m_buffer.toString());
  -
  -         if (m_cache.isJMSMonitoringEnabled()) 
  -         {
  -            // Prepare JMS message
  -            Message message = m_cache.createMessage(null);
  -            try 
  -            {
  -               message.setStringProperty("TYPE", "RESIZER");
  -               message.setIntProperty("OLD_CAPACITY", oldCapacity);
  -               message.setIntProperty("NEW_CAPACITY", newCapacity);
  -               message.setIntProperty("SIZE", getList().m_count);
  -            }
  -            catch (JMSException x) 
  -            {
  -               log.error("createMessage failed", x);
  -            }
  -                     
  -            // Send JMS Message
  -            m_cache.sendMessage(message);
  -         }
         }
      }
      
  @@ -403,15 +365,20 @@
   
         protected OveragerTask(long period) 
         {
  -         super(period);
            m_message = getTaskLogMessage() + " " +
               m_cache.getContainer().getBeanMetaData().getEjbName() +
               " with id = ";
            m_buffer = new StringBuffer();
         }
         
  -      public void execute() 
  +      public void run() 
         {
  +         if( m_cache == null )
  +         {
  +            cancel();
  +            return;
  +         }
  +
            LRUList list = getList();
            long now = System.currentTimeMillis();
   
  @@ -451,153 +418,49 @@
            m_buffer.append(" - Cache size = ");
            m_buffer.append(count);
            log.debug(m_buffer.toString());
  -                     
  -         if (m_cache.isJMSMonitoringEnabled()) 
  -         {
  -            // Prepare JMS message
  -            Message message = m_cache.createMessage(key);
  -            try 
  -            {
  -               message.setStringProperty("TYPE", getJMSTaskType());
  -               message.setIntProperty("SIZE", count);
  -            }
  -            catch (JMSException x) 
  -            {
  -               log.error("createMessage failed", x);
  -            }
  -                     
  -            // Send JMS Message
  -            m_cache.sendMessage(message);
  -         }
         }
         
  -      protected String getTaskLogMessage() {
  +      protected String getTaskLogMessage()
  +      {
            return "Scheduling for passivation overaged bean";
         }
         
  -      protected String getJMSTaskType() {
  +      protected String getJMSTaskType()
  +      {
            return "OVERAGER";
         }
         
  -      protected void kickOut(LRUCacheEntry entry) {
  +      protected void kickOut(LRUCacheEntry entry)
  +      {
            ageOut(entry);
         }
         
  -      protected long getMaxAge() {
  +      protected long getMaxAge()
  +      {
            return m_maxBeanAge;
         }
      }
   
      /**
  -    * Subclass that send JMS messages on list activity events.
  +    * Subclass that logs list activity events.
       */
      protected class ContextLRUList extends LRUList 
      {
         protected void entryAdded(LRUCacheEntry entry) 
         {
  -         if (m_cache.isJMSMonitoringEnabled()) 
  -         {
  -            // Prepare JMS message
  -            Message message = m_cache.createMessage(entry.m_key);
  -            try 
  -            {
  -               message.setStringProperty("TYPE", "CACHE");
  -               message.setStringProperty("ACTIVITY", "ADD");
  -               message.setIntProperty("CAPACITY", m_capacity);
  -               message.setIntProperty("SIZE", m_count);
  -            }
  -            catch (JMSException x) 
  -            {
  -               log.error("createMessage failed", x);
  -            }
  -                     
  -            // Send JMS Message
  -            m_cache.sendMessage(message);
  -         }
  -      }
  -      
  +         if( log.isTraceEnabled() )
  +            log.trace("entryAdded, entry="+entry);
  +      }      
         protected void entryRemoved(LRUCacheEntry entry) 
         {
  -         if (m_cache.isJMSMonitoringEnabled()) 
  -         {
  -            // Prepare JMS message
  -            Message message = m_cache.createMessage(entry.m_key);
  -            try 
  -            {
  -               message.setStringProperty("TYPE", "CACHE");
  -               message.setStringProperty("ACTIVITY", "REMOVE");
  -               message.setIntProperty("CAPACITY", m_capacity);
  -               message.setIntProperty("SIZE", m_count);
  -            }
  -            catch (JMSException x) 
  -            {
  -               log.error("createMessage failed", x);
  -            }
  -                     
  -            // Send JMS Message
  -            m_cache.sendMessage(message);
  -         }
  +         if( log.isTraceEnabled() )
  +            log.trace("entryRemoved, entry="+entry);
         }
  -      
         protected void capacityChanged(int oldCapacity) 
         {
  -         if (m_cache.isJMSMonitoringEnabled()) 
  -         {
  -            // Prepare JMS message
  -            Message message = m_cache.createMessage(null);
  -            try 
  -            {
  -               message.setStringProperty("TYPE", "CACHE");
  -               message.setStringProperty("ACTIVITY", "CAPACITY");
  -               message.setIntProperty("OLD_CAPACITY", oldCapacity);
  -               message.setIntProperty("NEW_CAPACITY", m_capacity);
  -               message.setIntProperty("SIZE", m_count);
  -            }
  -            catch (JMSException x) 
  -            {
  -               log.error("createMessage failed", x);
  -            }
  -                     
  -            // Send JMS Message
  -            m_cache.sendMessage(message);
  -         }
  -      }
  -   }
  -     
  -   /**
  -    * Class used only for debug purposes.
  -    */
  -   /*
  -   private class CacheDumper extends TimerTask
  -   {
  -      private java.io.BufferedReader reader = new java.io.BufferedReader(new 
java.io.InputStreamReader(System.in));
  -      private CacheDumper() {super(5000L);}
  -      public void execute() 
  -      {
  -         synchronized (m_cache.getCacheLock())
  -         {
  -            if (getMap().size() > 0 && getList().m_count > 0) 
  -            {
  -               System.err.println();
  -               System.err.println("DUMPING CACHE FOR BEAN " + 
m_cache.getContainer().getBeanMetaData().getEjbName());
  -               System.err.println("THE MAP:");
  -               System.err.println(Integer.toHexString(getMap().hashCode()) + " 
size: " + getMap().size());
  -               for (java.util.Iterator i = getMap().values().iterator(); 
i.hasNext();) 
  -               {
  -                  System.err.println(i.next());
  -               }
  -               System.err.println("THE LIST:");
  -               System.err.println(getList());
  -               // readLine();
  -            }
  -         }
  -      }
  -      private void readLine() 
  -      {
  -         System.err.println("Hit a key...");
  -         try {reader.readLine();}
  -         catch (java.io.IOException x) {}
  +         if( log.isTraceEnabled() )
  +            log.trace("capacityChanged, oldCapacity="+oldCapacity);
         }
      }
  -   */
  +
   }
  
  
  
  1.7       +12 -5     
jboss/src/main/org/jboss/ejb/plugins/LRUStatefulContextCachePolicy.java
  
  Index: LRUStatefulContextCachePolicy.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/LRUStatefulContextCachePolicy.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LRUStatefulContextCachePolicy.java        15 Jan 2002 22:55:13 -0000      1.6
  +++ LRUStatefulContextCachePolicy.java        13 Apr 2002 18:27:20 -0000      1.7
  @@ -7,7 +7,8 @@
   package org.jboss.ejb.plugins;
   
   
  -import org.jboss.util.TimerTask;
  +import java.util.TimerTask;
  +
   import org.jboss.deployment.DeploymentException;
   import org.jboss.metadata.MetaData;
   
  @@ -17,7 +18,7 @@
    * Least Recently Used cache policy for StatefulSessionEnterpriseContexts.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class LRUStatefulContextCachePolicy extends LRUEnterpriseContextCachePolicy
   {
  @@ -57,7 +58,7 @@
                if (m_maxBeanLife > 0)
                {
                        m_remover = new RemoverTask(m_removerPeriod);
  -                     scheduler.schedule(m_remover, (long)(Math.random() * 
m_removerPeriod));
  +                     tasksTimer.schedule(m_remover, (long)(Math.random() * 
m_removerPeriod));
                }
        }
   
  @@ -120,12 +121,18 @@
                protected void kickOut(LRUCacheEntry entry) {remove(entry.m_key);}
                protected long getMaxAge() {return m_maxBeanLife;}
   
  -             public void execute()
  +             public void run()
                {
  +         if( m_cache == null )
  +         {
  +            cancel();
  +            return;
  +         }
  +
                        synchronized (m_cache.getCacheLock())
                        {
                                // Remove beans from cache, if present
  -                             super.execute();
  +                             super.run();
   
                                // Now remove passivated beans
                                m_cache.removePassivated(getMaxAge() - 
super.getMaxAge());
  
  
  
  1.9       +8 -4      
jboss/src/main/org/jboss/ejb/plugins/NoPassivationCachePolicy.java
  
  Index: NoPassivationCachePolicy.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationCachePolicy.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- NoPassivationCachePolicy.java     31 Jan 2002 00:04:45 -0000      1.8
  +++ NoPassivationCachePolicy.java     13 Apr 2002 18:27:20 -0000      1.9
  @@ -7,18 +7,19 @@
   package org.jboss.ejb.plugins;
   
   import java.util.HashMap;
  +
   import org.jboss.ejb.EnterpriseContext;
  -import org.jboss.ejb.plugins.EnterpriseContextCachePolicy;
  +import org.jboss.util.CachePolicy;
   
   /**
    * Implementation of a no passivation cache policy.
    *
    * @see AbstractInstanceCache
    * @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class NoPassivationCachePolicy 
  -     implements EnterpriseContextCachePolicy
  +     implements CachePolicy
   {
        // Constants -----------------------------------------------------
   
  @@ -47,7 +48,10 @@
        
        public void stop() {}
        
  -     public void destroy() {}
  +     public void destroy()
  +   {
  +      m_map.clear();
  +   }
   
        public Object get(Object key) 
        {
  
  
  
  1.18      +8 -22     
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceCache.java
  
  Index: StatefulSessionInstanceCache.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceCache.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- StatefulSessionInstanceCache.java 3 Mar 2002 18:23:08 -0000       1.17
  +++ StatefulSessionInstanceCache.java 13 Apr 2002 18:27:20 -0000      1.18
  @@ -16,9 +16,6 @@
   import javax.transaction.Status;
   import javax.transaction.SystemException;
   
  -import javax.jms.Message;
  -import javax.jms.JMSException;
  -
   import org.jboss.ejb.Container;
   import org.jboss.ejb.StatefulSessionContainer;
   import org.jboss.ejb.EnterpriseContext;
  @@ -30,7 +27,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
  - * @version $Revision: 1.17 $
  + * @version $Revision: 1.18 $
    */
   public class StatefulSessionInstanceCache
       extends AbstractInstanceCache
  @@ -55,7 +52,13 @@
       {
           m_container = (StatefulSessionContainer)c;
       }
  -    
  +
  +   public void destroy()
  +   {
  +      m_passivated.clear();
  +      super.destroy();
  +   }
  +
       // Z implementation ----------------------------------------------
   
       // Y overrides ---------------------------------------------------
  @@ -147,23 +150,6 @@
           m_buffer.append(key);
           if( log.isTraceEnabled() )
            log.trace(m_buffer.toString());
  -
  -        if (isJMSMonitoringEnabled())
  -        {
  -            // Prepare JMS message
  -            Message message = createMessage(key);
  -            try
  -            {
  -                message.setStringProperty(TYPE, "REMOVER");
  -            }
  -            catch (JMSException x)
  -            {
  -                log.error("createMessage failed", x);
  -            }
  -
  -            // Send JMS Message
  -            sendMessage(message);
  -        }
       }
   
       // Inner classes -------------------------------------------------
  
  
  
  1.1                  jboss/src/main/org/jboss/ejb/plugins/AbstractPassivationJob.java
  
  Index: AbstractPassivationJob.java
  ===================================================================
  package org.jboss.ejb.plugins;
  
  import org.jboss.ejb.EnterpriseContext;
  import org.jboss.util.Executable;
  
  /** Abstract class for passivation jobs.
  Subclasses should implement {@link #execute} synchronizing it in some way because
  the execute method is normally called in the passivation thread,
  while the cancel method is normally called from another thread.
  To avoid that subclasses override methods of this class without
  make them synchronized (except execute of course), they're declared final.
  
  @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public abstract class AbstractPassivationJob implements Executable
  {
     protected EnterpriseContext ctx;
     protected Object key;
     protected boolean isCancelled;
     protected boolean isExecuted;
  
     AbstractPassivationJob(EnterpriseContext ctx, Object key)
     {
        this.ctx = ctx;
        this.key = key;
     }
  
     /**
      * (Bill Burke) We can't rely on the EnterpriseContext to provide PassivationJob
      * with a valid key because it may get freed to the InstancePool, then
      * reused before the PassivationJob executes.
      */
     final Object getKey()
     {
        return key;
     }
     /**
      * Returns the EnterpriseContext associated with this passivation job,
      * so the bean that will be passivated.
      * No need to synchronize access to this method, since the returned
      * reference is immutable
      */
     final EnterpriseContext getEnterpriseContext()
     {
        return ctx;
     }
     /**
      * Mark this job for cancellation.
      * @see #isCancelled
      */
     final synchronized void cancel()
     {
        isCancelled = true;
     }
     /**
      * Returns whether this job has been marked for cancellation
      * @see #cancel
      */
     final synchronized boolean isCancelled()
     {
        return isCancelled;
     }
     /**
      * Mark this job as executed
      * @see #isExecuted
      */
     final synchronized void executed()
     {
        isExecuted = true;
     }
     /**
      * Returns whether this job has been executed
      * @see #executed
      */
     final synchronized boolean isExecuted()
     {
        return isExecuted;
     }
  
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to