[jboss-cvs] JBossAS SVN: r70747 - in projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache: spi/impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 11 13:01:59 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-03-11 13:01:59 -0400 (Tue, 11 Mar 2008)
New Revision: 70747

Added:
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/spi/impl/AbstractPassivatingIntegratedObjectStore.java
Modified:
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/backing/SimplePassivatingIntegratedObjectStore.java
Log:
[EJBTHREE-1026] Factor common behavior out of SimplePassivatingIntegratedObjectStore

Modified: projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/backing/SimplePassivatingIntegratedObjectStore.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/backing/SimplePassivatingIntegratedObjectStore.java	2008-03-11 16:29:33 UTC (rev 70746)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/backing/SimplePassivatingIntegratedObjectStore.java	2008-03-11 17:01:59 UTC (rev 70747)
@@ -31,10 +31,9 @@
 import org.jboss.ejb3.cache.CacheItem;
 import org.jboss.ejb3.cache.spi.BackingCacheEntry;
 import org.jboss.ejb3.cache.spi.ObjectStore;
-import org.jboss.ejb3.cache.spi.PassivatingBackingCache;
 import org.jboss.ejb3.cache.spi.PassivatingIntegratedObjectStore;
+import org.jboss.ejb3.cache.spi.impl.AbstractPassivatingIntegratedObjectStore;
 import org.jboss.ejb3.cache.spi.impl.CacheableTimestamp;
-import org.jboss.ejb3.cache.spi.impl.PassivationExpirationRunner;
 import org.jboss.logging.Logger;
 
 /**
@@ -46,7 +45,7 @@
  * @version $Revision$
  */
 public class SimplePassivatingIntegratedObjectStore<C extends CacheItem, T extends BackingCacheEntry<C>>
-      implements PassivatingIntegratedObjectStore<C, T>
+      extends AbstractPassivatingIntegratedObjectStore<C, T>
 {
    private static final Logger log = Logger.getLogger(SimplePassivatingIntegratedObjectStore.class);
    
@@ -55,36 +54,19 @@
    private Map<Object, Long> passivatedEntries;
    
    /**
-    * Support callbacks when our SessionTimeoutThread decides to
-    * evict an entry.
-    */
-   private PassivatingBackingCache<C, T> owningCache;   
-   private int interval;
-   private int maxSize;
-   private long idleTimeSeconds;
-   private long expirationTimeSeconds;   
-   private PassivationExpirationRunner sessionTimeoutRunner;
-   private String name;
-   private boolean stopped = true;
-   
-   /**
     * Create a new SimpleIntegratedObjectStore.
     */
    public SimplePassivatingIntegratedObjectStore(ObjectStore<T> store, 
                                                  CacheConfig config,
                                                  String name)
    {
+      super(config, name);
+      
       assert store != null : "store is null";
-      assert config != null : "config is null";
-      assert name != null : "name is null";
       
       this.store = store;
       this.cache = new HashMap<Object, T>();
       this.passivatedEntries = new HashMap<Object, Long>();
-      this.idleTimeSeconds = config.idleTimeoutSeconds();
-      this.expirationTimeSeconds = config.removalTimeoutSeconds();
-      this.maxSize = config.maxSize();
-      this.name = name;
    }
    
    public boolean isClustered()
@@ -165,92 +147,25 @@
    {
       store.start();
       
-      if (interval > 0)
-      {
-         if (sessionTimeoutRunner == null)
-         {
-            assert name != null : "name has not been set";
-            assert owningCache != null;
-            String timerName = "PassivationExpirationTimer-" + name;
-            sessionTimeoutRunner = new PassivationExpirationRunner(this, timerName, interval);
-         }
-         sessionTimeoutRunner.start();
-      }     
-      
-      stopped = false;
-      
-      log.debug("Started " + name);
+      super.start();
    }
 
    public void stop()
    {      
       store.stop();
       
-      if (sessionTimeoutRunner != null)
-      {
-         sessionTimeoutRunner.stop();
-      }      
-      
-      stopped = true;
-      
-      log.debug("Stopped " + name);
+      super.stop();
    }
 
-   // ---------------------------------------  PassivatingIntegratedObjectStore
+   // -------------------------------  AbstractPassivatingIntegratedObjectStore
 
-
-   public void setPassivatingCache(PassivatingBackingCache<C, T> cache)
+   @Override
+   protected void runExpiration()
    {
-      this.owningCache = cache;      
-   }
-   
-   public int getInterval()
-   {
-      return interval;
-   }
-
-   public void setInterval(int seconds)
-   {
-      this.interval = seconds;      
-   }
-   
-   public void processPassivationExpiration()
-   {
-      if (!stopped)
+      if (getExpirationTimeSeconds() > 0)
       {
-         try
-         {
-            runPassivation();               
-         }
-         catch (Exception e)
-         {
-            log.error("Caught exception processing passivations", e);
-         }
-      }
-      if (!stopped)
-      {
-         try
-         {
-            runExpiration();               
-         }
-         catch (Exception e)
-         {
-            log.error("Caught exception processing expirations", e);
-         }               
-      }
-   }
-   
-   public boolean isPassivationExpirationSelfManaged()
-   {
-      return interval > 0;
-   }
-   
-   private void runExpiration()
-   {
-      if (expirationTimeSeconds > 0)
-      {
          long now = System.currentTimeMillis();
-         long minRemovalUse = now - (expirationTimeSeconds * 1000);                     
+         long minRemovalUse = now - (getExpirationTimeSeconds() * 1000);                     
          for (CacheableTimestamp ts : getPassivatedEntries())
          {
             try
@@ -269,16 +184,17 @@
       }      
    }
 
-   private void runPassivation()
+   @Override
+   protected void runPassivation()
    {
-      if (idleTimeSeconds > 0)
+      if (getIdleTimeSeconds() > 0)
       {
          long now = System.currentTimeMillis();
-         long minPassUse = now - (idleTimeSeconds * 1000);
+         long minPassUse = now - (getIdleTimeSeconds() * 1000);
          
          // Scan the in-memory entries for passivation or removal
          SortedSet<CacheableTimestamp> timestamps = getInMemoryEntries();
-         int overCount = timestamps.size() - maxSize;
+         int overCount = timestamps.size() - getMaxSize();
          for (CacheableTimestamp ts : timestamps)
          {
             try
@@ -292,7 +208,7 @@
                      if (entry == null || entry.isInUse())
                         continue;
                   }
-                  owningCache.passivate(ts.getId());
+                  getPassivatingCache().passivate(ts.getId());
                   overCount--;
                }
             }
@@ -304,33 +220,8 @@
          }
       }
       
-   }   
-   
-   public int getMaxSize()
-   {
-      return maxSize;
    }
-   
-   public long getIdleTimeSeconds()
-   {
-      return idleTimeSeconds;
-   }
 
-   public void setIdleTimeSeconds(long idleTimeSeconds)
-   {
-      this.idleTimeSeconds = idleTimeSeconds;
-   }
-
-   public long getExpirationTimeSeconds()
-   {
-      return expirationTimeSeconds;
-   }
-   
-   public void setExpirationTimeSeconds(long timeout)
-   {
-      this.expirationTimeSeconds = timeout;
-   } 
-
    private SortedSet<CacheableTimestamp> getInMemoryEntries()
    {      
       SortedSet<CacheableTimestamp> set = new TreeSet<CacheableTimestamp>();

Added: projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/spi/impl/AbstractPassivatingIntegratedObjectStore.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/spi/impl/AbstractPassivatingIntegratedObjectStore.java	                        (rev 0)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/main/java/org/jboss/ejb3/cache/spi/impl/AbstractPassivatingIntegratedObjectStore.java	2008-03-11 17:01:59 UTC (rev 70747)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb3.cache.spi.impl;
+
+import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.cache.CacheItem;
+import org.jboss.ejb3.cache.spi.BackingCacheEntry;
+import org.jboss.ejb3.cache.spi.PassivatingBackingCache;
+import org.jboss.ejb3.cache.spi.PassivatingIntegratedObjectStore;
+import org.jboss.logging.Logger;
+
+/**
+ * Abstract superclass for {@link PassivatingIntegratedObjectStore} 
+ * implementations.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public abstract class AbstractPassivatingIntegratedObjectStore<C extends CacheItem, T extends BackingCacheEntry<C>>
+      implements PassivatingIntegratedObjectStore<C, T>
+{
+   private static final Logger log = Logger.getLogger(AbstractPassivatingIntegratedObjectStore.class);
+   
+   /**
+    * Support callbacks when our SessionTimeoutThread decides to
+    * evict an entry.
+    */
+   private PassivatingBackingCache<C, T> owningCache;   
+   private int interval;
+   private int maxSize;
+   private long idleTimeSeconds;
+   private long expirationTimeSeconds;   
+   private PassivationExpirationRunner sessionTimeoutRunner;
+   private final String name;
+   private boolean stopped = true;
+   
+   /**
+    * Create a new AbstractPassivatingIntegratedObjectStore.
+    */
+   protected AbstractPassivatingIntegratedObjectStore(CacheConfig config,
+                                                   String name)
+   {
+      assert config != null : "config is null";
+      assert name != null : "name is null";
+      
+      this.idleTimeSeconds = config.idleTimeoutSeconds();
+      this.expirationTimeSeconds = config.removalTimeoutSeconds();
+      this.maxSize = config.maxSize();
+      this.name = name;
+   }
+
+   // ---------------------------------------------------------------- Abstract
+   
+   protected abstract void runExpiration();
+
+   protected abstract void runPassivation();
+
+   // --------------------------------------------------  IntegratedObjectStore
+
+   public void start()
+   {
+      if (interval > 0)
+      {
+         if (sessionTimeoutRunner == null)
+         {
+            assert name != null : "name has not been set";
+            assert owningCache != null;
+            String timerName = "PassivationExpirationTimer-" + name;
+            sessionTimeoutRunner = new PassivationExpirationRunner(this, timerName, interval);
+         }
+         sessionTimeoutRunner.start();
+      }     
+      
+      stopped = false;
+      
+      log.debug("Started " + name);
+   }
+
+   public void stop()
+   {      
+      if (sessionTimeoutRunner != null)
+      {
+         sessionTimeoutRunner.stop();
+      }      
+      
+      stopped = true;
+      
+      log.debug("Stopped " + name);
+   }
+
+   // ---------------------------------------  PassivatingIntegratedObjectStore
+
+
+   public void setPassivatingCache(PassivatingBackingCache<C, T> cache)
+   {
+      this.owningCache = cache;      
+   }
+   
+   public PassivatingBackingCache<C, T> getPassivatingCache()
+   {
+      return owningCache;
+   }
+   
+   public int getInterval()
+   {
+      return interval;
+   }
+
+   public void setInterval(int seconds)
+   {
+      this.interval = seconds;      
+   }
+   
+   public void processPassivationExpiration()
+   {
+      if (!stopped)
+      {
+         try
+         {
+            runPassivation();               
+         }
+         catch (Exception e)
+         {
+            log.error("Caught exception processing passivations", e);
+         }
+      }
+      
+      if (!stopped)
+      {
+         try
+         {
+            runExpiration();               
+         }
+         catch (Exception e)
+         {
+            log.error("Caught exception processing expirations", e);
+         }               
+      }
+   }
+   
+   public boolean isPassivationExpirationSelfManaged()
+   {
+      return interval > 0;
+   }
+   
+   public int getMaxSize()
+   {
+      return maxSize;
+   }
+   
+   public long getIdleTimeSeconds()
+   {
+      return idleTimeSeconds;
+   }
+
+   public void setIdleTimeSeconds(long idleTimeSeconds)
+   {
+      this.idleTimeSeconds = idleTimeSeconds;
+   }
+
+   public long getExpirationTimeSeconds()
+   {
+      return expirationTimeSeconds;
+   }
+   
+   public void setExpirationTimeSeconds(long timeout)
+   {
+      this.expirationTimeSeconds = timeout;
+   }
+
+}




More information about the jboss-cvs-commits mailing list