[jboss-cvs] JBossCache/src/org/jboss/cache ...

Elias Ross genman at noderunner.net
Fri Dec 8 13:49:17 EST 2006


  User: genman  
  Date: 06/12/08 13:49:17

  Modified:    src/org/jboss/cache     TransactionTable.java
                        RegionImpl.java Region.java TreeCache.java
  Log:
  JBCACHE-892 Use JDK1.5 concurrent classes
  
  Revision  Changes    Path
  1.11      +2 -4      JBossCache/src/org/jboss/cache/TransactionTable.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TransactionTable.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TransactionTable.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- TransactionTable.java	20 Nov 2006 03:53:54 -0000	1.10
  +++ TransactionTable.java	8 Dec 2006 18:49:17 -0000	1.11
  @@ -7,10 +7,8 @@
   package org.jboss.cache;
   
   
  -import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.jboss.cache.lock.IdentityLock;
   import org.jboss.cache.lock.NodeLock;
   import org.jboss.cache.marshall.MethodCall;
   
  @@ -18,7 +16,7 @@
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.Map;
  -
  +import java.util.concurrent.ConcurrentHashMap;
   
   /**
    * Maintains the mapping between local (Transaction) and global transactions
  @@ -26,7 +24,7 @@
    * given TX.
    *
    * @author <a href="mailto:bela at jboss.org">Bela Ban</a> Apr 14, 2003
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class TransactionTable {
   
  
  
  
  1.15      +35 -61    JBossCache/src/org/jboss/cache/RegionImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RegionImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- RegionImpl.java	16 Nov 2006 18:15:26 -0000	1.14
  +++ RegionImpl.java	8 Dec 2006 18:49:17 -0000	1.15
  @@ -6,7 +6,10 @@
    */
   package org.jboss.cache;
   
  -import EDU.oswego.cs.dl.util.concurrent.BoundedLinkedQueue;
  +import java.util.concurrent.BlockingQueue;
  +import java.util.concurrent.LinkedBlockingQueue;
  +import java.util.concurrent.TimeUnit;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.config.EvictionRegionConfig;
  @@ -25,20 +28,17 @@
   {
      private static final Log log = LogFactory.getLog(RegionImpl.class);
   
  -   RegionManager regionManager;
  -   Fqn fqn;
  -   boolean active;
  -   ClassLoader classLoader;
  -   BoundedLinkedQueue nodeEventQueue_;
  -   int checkCapacityCount = 0;
  -   int capacityWarnThreshold = 0;
  -   EvictionRegionConfig configuration = new EvictionRegionConfig();
  -   EvictionPolicy policy;
  +   private RegionManager regionManager;
  +   private Fqn fqn;
  +   private boolean active;
  +   private ClassLoader classLoader;
  +   private BlockingQueue<EvictedEventNode> nodeEventQueue = null;
  +   private int capacityWarnThreshold = 0;
  +   private EvictionRegionConfig configuration = new EvictionRegionConfig();
  +   private EvictionPolicy policy;
   
      /**
  -    * Creates a MarshRegion from an fqn and registers the region in the region registry.
  -    *
  -    * @param fqn
  +    * Constructs a marshalling region from an fqn and region manager.
       */
      public RegionImpl(Fqn fqn, RegionManager regionManager)
      {
  @@ -48,17 +48,13 @@
      }
   
      /**
  -    * Constructor that creates an eviction region
  -    *
  -    * @param policy
  -    * @param config
  +    * Constructs an eviction region from a policy and configuration, defined by an fqn and region manager.
       */
      public RegionImpl(EvictionPolicy policy, EvictionRegionConfig config, Fqn fqn, RegionManager regionManager)
      {
         this(fqn, regionManager);
         this.configuration = config;
         this.policy = policy;
  -
         createQueue();
      }
   
  @@ -129,33 +125,23 @@
                 '}';
      }
   
  -   public int compareTo(Object o)
  -   {
  -      if (o instanceof Region)
  +   public int compareTo(Region other)
         {
  -         Region other = (Region) o;
            return getFqn().compareTo(other.getFqn());
         }
  -      return 1;
  -   }
   
      public void putNodeEvent(EvictedEventNode event)
      {
  -      if (nodeEventQueue_ == null) createQueue();
         try
         {
  -         // Don't check capacity every time as this is an expensive operation for
  -         // bounded buffer type objects in this situation
  -         if (++checkCapacityCount > 100)
  -         {
  -            checkCapacityCount = 0;
  -            if (nodeEventQueue_.size() > capacityWarnThreshold)
  +         if (nodeEventQueue.size() > capacityWarnThreshold)
               {
  -               log.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " + configuration.getEventQueueSize() + " You will need to reduce the wakeUpIntervalSeconds parameter.");
  -            }
  +            log.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " + configuration.getEventQueueSize() +
  +                  " Region: " + fqn +
  +                  " You will need to reduce the wakeUpIntervalSeconds parameter.");
            }
   
  -         nodeEventQueue_.put(event);
  +         nodeEventQueue.put(event);
         }
         catch (InterruptedException e)
         {
  @@ -164,16 +150,14 @@
      }
   
      /**
  -    * Take the last node from node queue. It will also
  -    * remove it from the queue.
  -    *
  -    * @return The EvictedEventNode
  +    * Returns and removes the last event from event queue.
  +    * If no more events exists, returns null. May also return null if interrupted.
       */
      public EvictedEventNode takeLastEventNode()
      {
         try
         {
  -         return (EvictedEventNode) nodeEventQueue_.poll(0);
  +         return nodeEventQueue.poll(0, TimeUnit.SECONDS);
         }
         catch (InterruptedException e)
         {
  @@ -184,37 +168,25 @@
   
      public int nodeEventQueueSize()
      {
  -      return nodeEventQueue_.size();
  +      return nodeEventQueue.size();
      }
   
      public void resetEvictionQueues()
      {
  -      BoundedLinkedQueue q1 = nodeEventQueue_;
  -      log.info("reseteEvictionQueues(): node queue size: " + q1.size() +
  -              " region name: " + getFqn());
  -      createQueue();
  -      // Help to recycle
  -      for (int i = 0; i < q1.size(); i++)
  -      {
  -         try
  -         {
  -            q1.take();
  -         }
  -         catch (InterruptedException e)
  -         {
  -            e.printStackTrace();
  -         }
  -      }
  +      nodeEventQueue.clear();
      }
   
      private void createQueue()
      {
  -      capacityWarnThreshold = (98 * configuration.getEventQueueSize()) / 100 - 100;
  +      if (configuration == null)
  +         throw new IllegalArgumentException("null eviction configuration");
  +      int size = configuration.getEventQueueSize();
  +      capacityWarnThreshold = (98 * size) / 100 - 100;
         if (capacityWarnThreshold <= 0)
         {
            throw new RuntimeException("Capacity warn threshold used in eviction is smaller than 1.");
         }
  -      nodeEventQueue_ = new BoundedLinkedQueue(configuration.getEventQueueSize());
  +      nodeEventQueue = new LinkedBlockingQueue<EvictedEventNode>(size);
      }
   
      public EvictionRegionConfig getEvictionRegionConfig()
  @@ -237,11 +209,13 @@
         configuration.setEvictionPolicyConfig(evictionPolicyConfig);
         policy = createPolicy(evictionPolicyConfig.getEvictionPolicyClass());
         regionManager.getEvictionTimerTask().addRegionToProcess(this);
  -      if (nodeEventQueue_ == null) createQueue();
  +      if (nodeEventQueue == null) createQueue();
      }
   
      private EvictionPolicy createPolicy(String className)
      {
  +      if (className == null)
  +         throw new IllegalArgumentException("null className");
         try
         {
            if (log.isTraceEnabled()) log.trace("Instantiating " + className);
  
  
  
  1.9       +1 -1      JBossCache/src/org/jboss/cache/Region.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Region.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Region.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- Region.java	15 Nov 2006 23:48:31 -0000	1.8
  +++ Region.java	8 Dec 2006 18:49:17 -0000	1.9
  @@ -17,7 +17,7 @@
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
  -public interface Region extends Comparable
  +public interface Region extends Comparable<Region>
   {
      /**
       * Registers a specific {@link ClassLoader} (rather than the default) for a region, represented by a {@link Fqn}.
  
  
  
  1.291     +46 -38    JBossCache/src/org/jboss/cache/TreeCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
  retrieving revision 1.290
  retrieving revision 1.291
  diff -u -b -r1.290 -r1.291
  --- TreeCache.java	7 Dec 2006 22:20:23 -0000	1.290
  +++ TreeCache.java	8 Dec 2006 18:49:17 -0000	1.291
  @@ -94,7 +94,7 @@
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @author Brian Stansberry
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Id: TreeCache.java,v 1.290 2006/12/07 22:20:23 vblagojevic Exp $
  + * @version $Id: TreeCache.java,v 1.291 2006/12/08 18:49:17 genman Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -145,7 +145,7 @@
      /**
       * JGroups message listener.
       */
  -   protected MessageListener ml = new MessageListenerAdaptor(log);
  +   protected MessageListenerAdaptor ml = new MessageListenerAdaptor(log);
   
      /**
       * Maintains mapping of transactions (keys) and Modifications/Undo-Operations
  @@ -168,12 +168,6 @@
       */
      protected boolean isStateSet = false;
   
  -   /**
  -    * An exception occuring upon fetch state.
  -    */
  -   protected Exception setStateException;
  -   private final Object stateLock = new Object();
  -
      protected String evictionInterceptorClass = "org.jboss.cache.interceptors.EvictionInterceptor";
   
      /**
  @@ -193,31 +187,24 @@
       */
      protected TransactionManagerLookup tm_lookup = null;
   
  -
      /**
       * Used to get the Transaction associated with the current thread
       */
      protected TransactionManager tm = null;
   
  -
      protected CacheLoaderManager cacheLoaderManager;
  +
      /**
       * for legacy use *
       */
      protected CacheLoaderConfig cloaderConfig;
   
  -
      /**
       * Queue used to replicate updates when mode is repl-async
       */
      protected ReplicationQueue repl_queue = null;
   
      /**
  -    * Determines whether to use optimistic locking or not.  Disabled by default.
  -    */
  -   protected boolean nodeLockingOptimistic = false;
  -
  -   /**
       * create was called.
       */
      protected boolean useCreateService = false;
  @@ -1208,24 +1195,7 @@
         boolean rc = channel.getState(null, stateFetchTimeout);
         if (rc)
         {
  -         synchronized (stateLock)
  -         {
  -            while (!isStateSet)
  -            {
  -               if (setStateException != null)
  -               {
  -                  throw setStateException;
  -               }
  -
  -               try
  -               {
  -                  stateLock.wait();
  -               }
  -               catch (InterruptedException iex)
  -               {
  -               }
  -            }
  -         }
  +         ml.waitForState();
            stop = System.currentTimeMillis();
            if (log.isDebugEnabled())
            {
  @@ -3000,7 +2970,7 @@
               log.error("releaseAllLocks(): node " + fqn + " not found");
               return;
            }
  -         n.releaseAllForce();
  +         releaseAll(n);
         }
         catch (Throwable t)
         {
  @@ -3008,6 +2978,16 @@
         }
      }
   
  +   private void releaseAll(Node n)
  +   {
  +      for (Node child : n.getChildren())
  +      {
  +         releaseAll(child);
  +      }
  +      n.getNodeSPI().getLock().releaseAll();
  +   }
  +
  +   
      /**
       * Finds and returns the {@link org.jboss.cache.DataNode#toString()} value for the Fqn.
       * Returns null if not found or upon error.
  @@ -3211,12 +3191,40 @@
         final Log my_log;   // Need this to run under jdk1.3
         final boolean trace;
   
  +      /**
  +       * An exception occuring upon fetch state.
  +       */
  +      protected Exception setStateException;
  +      private final Object stateLock = new Object();
  +
         MessageListenerAdaptor(Log log)
         {
            this.my_log = log;
            this.trace = my_log.isTraceEnabled();
         }
   
  +      public void waitForState() throws Exception
  +      {
  +         synchronized (stateLock)
  +         {
  +            while (!isStateSet)
  +            {
  +               if (setStateException != null)
  +               {
  +                  throw setStateException;
  +               }
  +
  +               try
  +               {
  +                  stateLock.wait();
  +               }
  +               catch (InterruptedException iex)
  +               {
  +               }
  +            }
  +         }
  +      }
  +
         /**
          * Callback, does nothing.
          */
  
  
  



More information about the jboss-cvs-commits mailing list