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

Manik Surtani msurtani at jboss.com
Thu Nov 16 13:15:26 EST 2006


  User: msurtani
  Date: 06/11/16 13:15:26

  Modified:    src/org/jboss/cache    RegionImpl.java TreeCache.java
                        RegionManager.java
  Log:
  some eviction stuff
  
  Revision  Changes    Path
  1.14      +19 -17    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.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- RegionImpl.java	15 Nov 2006 23:48:31 -0000	1.13
  +++ RegionImpl.java	16 Nov 2006 18:15:26 -0000	1.14
  @@ -49,6 +49,7 @@
   
      /**
       * Constructor that creates an eviction region
  +    *
       * @param policy
       * @param config
       */
  @@ -103,7 +104,6 @@
         active = b;
      }
   
  -
      // -------- eviction stuff -----
   
      public void markNodeCurrentlyInUse(Fqn fqn, long timeout)
  @@ -141,6 +141,7 @@
   
      public void putNodeEvent(EvictedEventNode event)
      {
  +      if (nodeEventQueue_ == null) createQueue();
         try
         {
            // Don't check capacity every time as this is an expensive operation for
  @@ -153,6 +154,7 @@
                  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.");
               }
            }
  +
            nodeEventQueue_.put(event);
         }
         catch (InterruptedException e)
  
  
  
  1.277     +2 -1      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.276
  retrieving revision 1.277
  diff -u -b -r1.276 -r1.277
  --- TreeCache.java	16 Nov 2006 17:21:11 -0000	1.276
  +++ TreeCache.java	16 Nov 2006 18:15:26 -0000	1.277
  @@ -95,7 +95,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.276 2006/11/16 17:21:11 msurtani Exp $
  + * @version $Id: TreeCache.java,v 1.277 2006/11/16 18:15:26 msurtani Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -856,6 +856,7 @@
         {
            notifier.notifyCacheStopped(getCacheSPI());
            notifier.removeAllCacheListeners();
  +         notifier.setEvictionPolicyListener(null);
         }
   
         useCreateService = false;
  
  
  
  1.12      +205 -232  JBossCache/src/org/jboss/cache/RegionManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RegionManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -b -r1.11 -r1.12
  --- RegionManager.java	16 Nov 2006 15:40:19 -0000	1.11
  +++ RegionManager.java	16 Nov 2006 18:15:26 -0000	1.12
  @@ -3,11 +3,11 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.buddyreplication.BuddyManager;
  +import org.jboss.cache.config.ConfigurationException;
   import org.jboss.cache.config.EvictionConfig;
   import org.jboss.cache.config.EvictionRegionConfig;
  -import org.jboss.cache.config.ConfigurationException;
  -import org.jboss.cache.eviction.RegionNameConflictException;
   import org.jboss.cache.eviction.EvictionTimerTask;
  +import org.jboss.cache.eviction.RegionNameConflictException;
   import org.jboss.cache.marshall.VersionAwareMarshaller;
   import org.jgroups.Address;
   
  @@ -74,7 +74,6 @@
      }
   
   
  -
      /**
       * Helper utility that checks for a classloader registered for the
       * given Fqn, and if found sets it as the TCCL. If the given Fqn is
  @@ -312,7 +311,7 @@
            throw new RegionNotEmptyException("Node " + subtreeRoot.getFqn() + " already exists and is not empty");
         }*/
   
  -      if(isActivatingDeactivating(fqn))
  +      if (isActivatingDeactivating(fqn))
         {
            throw new CacheException("Region " + subtreeRoot.getFqn() + " is already being activated/deactivated");
         }
  @@ -346,7 +345,7 @@
                  subtreeRoot = treeCache.createSubtreeRootNode(fqn);
               }
   
  -            Address [] groupMembers = null;
  +            Address[] groupMembers = null;
               Vector<Address> members = treeCache.getMembers();
               synchronized (members)
               {
  @@ -441,7 +440,7 @@
         boolean parentLocked = false;
         boolean subtreeLocked = false;
         
  -      if(isActivatingDeactivating(fqn))
  +      if (isActivatingDeactivating(fqn))
         {
            throw new CacheException("Region " + subtreeRoot.getFqn() + " is already being activated/deactivated");
         }
  @@ -676,6 +675,23 @@
      /**
       * Note that the ordered list returned is sorted according to the natural order defined in the {@link Comparable} interface, which {@link org.jboss.cache.Region} extends.
       *
  +    * @return an ordered list of all active regions which have defined eviction policies.
  +    */
  +   public List<Region> getAllEvictionRegions()
  +   {
  +      List<Region> regions = new ArrayList<Region>();
  +
  +      for (Region r : regionsRegistry.values())
  +         if (r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) regions.add(r);
  +
  +      Collections.sort(regions);
  +
  +      return regions;
  +   }
  +
  +   /**
  +    * Note that the ordered list returned is sorted according to the natural order defined in the {@link Comparable} interface, which {@link org.jboss.cache.Region} extends.
  +    *
       * @return an ordered list of all regions, regardless of whether they are active, have eviction policies defined or have class loaders set.
       */
      public List<Region> getAllRegions()
  @@ -704,7 +720,8 @@
   
            if (fqn.equals(DEFAULT_REGION))
            {
  -            if (setDefault) throw new ConfigurationException("A default region for evictions has already been set for this cache");
  +            if (setDefault)
  +               throw new ConfigurationException("A default region for evictions has already been set for this cache");
               if (log.isTraceEnabled()) log.trace("Applying settings for " + DEFAULT_REGION + " to Fqn.ROOT");
               fqn = Fqn.ROOT;
               setDefault = true;
  @@ -734,7 +751,6 @@
      }
   }
   
  -
   /*
   
   FROM THE ERegionManager:
  @@ -749,7 +765,7 @@
    * @author Ben Wang 02-2004
    * @author Daniel Huang (dhuang at jboss.org)
    * @author Brian Stansberry
  - * @version $Id: RegionManager.java,v 1.11 2006/11/16 15:40:19 msurtani Exp $
  + * @version $Id: RegionManager.java,v 1.12 2006/11/16 18:15:26 msurtani Exp $
    */
   /*public class ERegionManager
   {
  @@ -859,7 +875,7 @@
         return region;
      }*/
   
  -   /**
  +/**
       * Supports programatic instantiation of a region from an Fqn and a policy config.
       *
       * @param fqn
  @@ -867,17 +883,17 @@
       * @return
       * @throws RegionNameConflictException
       */
  - /*  public ERegion createRegion(Fqn fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
  -   {
  +/*  public ERegion createRegion(Fqn fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
  +{
         EvictionRegionConfig erc = new EvictionRegionConfig();
         erc.setRegionFqn(fqn);
         erc.setEvictionPolicyConfig(epc);
         erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : config_.getDefaultEventQueueSize());
   
         return createRegion(erc);
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Supports programatic instantiation of a region from an Fqn and a policy config.
       *
       * @param fqn
  @@ -885,12 +901,12 @@
       * @return
       * @throws RegionNameConflictException
       */
  - /*  public ERegion createRegion(String fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
  -   {
  +/*  public ERegion createRegion(String fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
  +{
         return createRegion(Fqn.fromString(fqn), epc);
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Supports programatic instantiation of a region from an Fqn, EvictionPolicy
       * and a policy config.  Should only be used in a case where the caller needs
       * to manipulate the EvictionPolicy; otherwise use the other overloaded versions
  @@ -915,7 +931,7 @@
         return region;
      }*/
   
  -   /**
  +/**
       * Supports programatic instantiation of a region from an Fqn, EvictionPolicy
       * and a policy config.  Should only be used in a case where the caller needs
       * to manipulate the EvictionPolicy; otherwise use the other overloaded versions
  @@ -986,7 +1002,7 @@
         return config_;
      }*/
   
  -   /**
  +/**
       * Removes a region by string.
       */
   /*   public void removeRegion(String fqn)
  @@ -994,11 +1010,11 @@
         removeRegion(Fqn.fromString(fqn));
      }*/
   
  -   /**
  +/**
       * Removes a region by Fqn, returns true if the region was found.
       */
  - /*  public boolean removeRegion(Fqn fqn)
  -   {
  +/*  public boolean removeRegion(Fqn fqn)
  +{
         ERegion region = (ERegion) regionMap_.remove(fqn);
         evictionTimerTask_.removeRegionToProcess(region);
   
  @@ -1022,25 +1038,25 @@
         }
   
         return region != null;
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Returns true if the region exists.
       */
  - /*  public boolean hasRegion(String myFqn)
  -   {
  +/*  public boolean hasRegion(String myFqn)
  +{
         return hasRegion(Fqn.fromString(myFqn));
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Returns true if the region exists.
       */
  - /*  public boolean hasRegion(Fqn fqn)
  -   {
  +/*  public boolean hasRegion(Fqn fqn)
  +{
         return regionMap_.containsKey(fqn);
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Returns the MarshRegion belonging to a String FQN.
       */
   /*   public ERegion getRegion(String myFqn)
  @@ -1048,11 +1064,11 @@
         return getRegion(Fqn.fromString(myFqn));
      }*/
   
  -   /**
  +/**
       * Returns the MarshRegion corresponding to this Fqn.
       */
  -  /* public ERegion getRegion(Fqn fqn)
  -   {
  +/* public ERegion getRegion(Fqn fqn)
  +{
         // Truncate Fqn as an optimization
         if (fqn.size() > longestFqn)
            fqn = fqn.getFqnChild(0, longestFqn);
  @@ -1079,38 +1095,38 @@
                            " You will need to define it in your EvictionPolicyConfig.");
         }
         return region;
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Returns an ordered list of regions.
       * Orders (by reverse) Fqn.
       */
  -  /* public ERegion[] getRegions()
  -   {
  +/* public ERegion[] getRegions()
  +{
         Collection c = regionMap_.values();
         ERegion r[] = new ERegion[c.size()];
         r = (ERegion[]) regionMap_.values().toArray(r);
         Arrays.sort(r, new RegionComparator());
         return r;
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Check for conflict in the current regions. There is a conflict
       * if fqn is any parent fqn of the current regions.
       *
       * @param myFqn Current fqn for potential new region.
       * @throws RegionNameConflictException to indicate a region name conflict has ocurred.
       */
  -  /* public void checkConflict(String myFqn) throws RegionNameConflictException
  -   {
  +/* public void checkConflict(String myFqn) throws RegionNameConflictException
  +{
         checkConflict(Fqn.fromString(myFqn));
  -   }*/
  +}*/
   
  -   /**
  +/**
       * Check for conflict in the current regions. There is a conflict
       * if fqn is any parent fqn of the current regions.
       */
  - /*  public void checkConflict(Fqn fqn) throws RegionNameConflictException
  +/*  public void checkConflict(Fqn fqn) throws RegionNameConflictException
      {
         for (int i = 0; i < fqn.size(); i++)
         {
  @@ -1122,21 +1138,7 @@
            }
         }
         // We are clear then.
  -   }*/
  -
  -   /**
  -    * This method is here to aid unit testing.
  -    */
  - /*  final void setTreeCache(TreeCache cache)
  -   {
  -      this.cache_ = cache;
      }
  -
  -   public String toString()
  -   {
  -      return super.toString() + " regions=" + regionMap_;
  -   }
  -
      class EvictionTreeCacheListener extends AbstractCacheListener
      {
         public void cacheStarted(CacheSPI cache)
  @@ -1156,34 +1158,5 @@
         }
      }
   
  -   static class RegionComparator implements Comparator
  -   {
  -      public int compare(Object o1, Object o2)
  -      {
  -         ERegion r1 = (ERegion) o1;
  -         ERegion r2 = (ERegion) o2;
  -         Fqn f1 = r1.getFqnObject();
  -         Fqn f2 = r2.getFqnObject();
  -         if (f1.equals(DEFAULT_REGION)) return -1;
  -         if (f2.equals(DEFAULT_REGION)) return 1;
  -         return -FqnComparator.INSTANCE.compare(f1, f2);
  -      }
  -   }
   
  -   private static EvictionPolicy instantiatePolicy(EvictionPolicyConfig config)
  -   {
  -      try
  -      {
  -         return (EvictionPolicy) Util.loadClass(config.getEvictionPolicyClass()).newInstance();
  -      }
  -      catch (RuntimeException e)
  -      {
  -         throw e;
  -      }
  -      catch (Exception e)
  -      {
  -         throw new RuntimeException("Failed to create EvictionPolicy " +
  -                 config.getEvictionPolicyClass(), e);
  -      }
  -   }
   }*/
  
  
  



More information about the jboss-cvs-commits mailing list