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

Manik Surtani msurtani at jboss.com
Fri Jan 19 11:00:31 EST 2007


  User: msurtani
  Date: 07/01/19 11:00:31

  Modified:    src/org/jboss/cache   CacheImpl.java RegionManager.java
  Log:
  Improved Javadocs
  
  Revision  Changes    Path
  1.35      +0 -30     JBossCache/src/org/jboss/cache/CacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -b -r1.34 -r1.35
  --- CacheImpl.java	19 Jan 2007 14:58:43 -0000	1.34
  +++ CacheImpl.java	19 Jan 2007 16:00:31 -0000	1.35
  @@ -33,8 +33,6 @@
   import org.jboss.cache.marshall.MethodCallFactory;
   import org.jboss.cache.marshall.MethodDeclarations;
   import org.jboss.cache.marshall.NodeData;
  -import org.jboss.cache.marshall.RegionNameConflictException;
  -import org.jboss.cache.marshall.RegionNotFoundException;
   import org.jboss.cache.marshall.VersionAwareMarshaller;
   import org.jboss.cache.notifications.Notifier;
   import org.jboss.cache.optimistic.DataVersion;
  @@ -960,34 +958,6 @@
      // -----------  Marshalling and State Transfer -----------------------
   
      /**
  -    * Registers a specific classloader for a region defined by a fully
  -    * qualified name.
  -    * A instance of {@link org.jboss.cache.marshall.Marshaller} is used for marshalling.
  -    *
  -    * @param fqn The fqn region. Children of this fqn will use this classloader for (un)marshalling.
  -    * @param cl  The class loader to use
  -    * @throws RegionNameConflictException If there is a conflict in existing registering for the fqn.
  -    * @throws IllegalStateException       if marshalling is not being used
  -    * @see #getMarshaller
  -    */
  -   public void registerClassLoader(String fqn, ClassLoader cl) throws RegionNameConflictException
  -   {
  -      regionManager.registerClassLoader(Fqn.fromString(fqn), cl);
  -   }
  -
  -   /**
  -    * Unregisters a class loader for a region.
  -    *
  -    * @param fqn The fqn region.
  -    * @throws RegionNotFoundException If there is a conflict in fqn specification.
  -    * @throws IllegalStateException   if marshalling is not being used
  -    */
  -   public void unregisterClassLoader(String fqn) throws RegionNotFoundException
  -   {
  -      regionManager.unregisterClassLoader(Fqn.fromString(fqn));
  -   }
  -
  -   /**
       * Creates a subtree in the local cache.
       * Returns the DataNode created.
       */
  
  
  
  1.27      +74 -163   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.26
  retrieving revision 1.27
  diff -u -b -r1.26 -r1.27
  --- RegionManager.java	19 Jan 2007 12:05:41 -0000	1.26
  +++ RegionManager.java	19 Jan 2007 16:00:31 -0000	1.27
  @@ -119,17 +119,6 @@
      }
   
      /**
  -    * Overloaded form of {@link #setContextClassLoaderAsCurrent(Fqn)}
  -    *
  -    * @param fqn
  -    * @see #setContextClassLoaderAsCurrent(Fqn)
  -    */
  -   public void setContextClassLoaderAsCurrent(String fqn)
  -   {
  -      setContextClassLoaderAsCurrent(Fqn.fromString(fqn));
  -   }
  -
  -   /**
       * Returns a region by {@link Fqn}, creating it optionally if absent.  If the region does not exist and <tt>createIfAbsent</tt>
       * is <tt>false</tt>, a parent region which may apply to the {@link Fqn} is sought.
       */
  @@ -214,59 +203,21 @@
      }
   
      /**
  -    * Registers a classloader under an FQN.
  -    */
  -   public void registerClassLoader(Fqn fqn, ClassLoader cl)
  -   {
  -      Region existing = getRegion(fqn, false);
  -      if (existing == null)
  -      {
  -         existing = getRegion(fqn, true);
  -      }
  -      existing.registerContextClassLoader(cl);
  -   }
  -
  -   /**
  -    * Overloaded form of {@link #registerClassLoader(Fqn,ClassLoader)}
  -    *
  -    * @param fqn
  -    * @see #registerClassLoader(Fqn,ClassLoader)
  -    */
  -   public void registerClassLoader(String fqn, ClassLoader cl)
  -   {
  -      registerClassLoader(Fqn.fromString(fqn), cl);
  -   }
  -
  -   /**
  -    * Overloaded form of {@link #unregisterClassLoader(Fqn)}
  +    * Removes a {@link org.jboss.cache.Region} identified by the given fqn.
       *
  -    * @param fqn
  -    * @see #unregisterClassLoader(Fqn)
  -    */
  -   public void unregisterClassLoader(Fqn fqn)
  -   {
  -      Region region = getRegion(fqn, false);
  -      if (region != null) region.unregisterContextClassLoader();
  -   }
  -
  -   /**
  -    * Unregisters a classloader by FQN.
  -    */
  -   public void unregisterClassLoader(String fqn)
  -   {
  -      unregisterClassLoader(Fqn.fromString(fqn));
  -   }
  -
  -   /**
  -    * Removes a region by FQN.
  +    * @param fqn fqn of the region to remove
  +    * @return true if such a region existed and was removed.
       */
  -   public void removeRegion(Fqn fqn)
  +   public boolean removeRegion(Fqn fqn)
      {
         Region r = regionsRegistry.remove(fqn);
  +      if (r == null) return false;
  +
         if (isUsingEvictions() && r.getEvictionPolicy() != null)
         {
            evictionTimerTask.removeRegionToProcess(r);
         }
  +      return true;
      }
   
      /**
  @@ -278,22 +229,10 @@
      }
   
      /**
  -    * Removes a region by FQN.
  -    * Overloaded form of {@link #removeRegion(Fqn)}
  -    *
  -    * @param fqn
  -    * @see #removeRegion(Fqn)
  -    */
  -   public void removeRegion(String fqn)
  -   {
  -      removeRegion(Fqn.fromString(fqn));
  -   }
  -
  -   /**
       * Activates unmarshalling of replication messages for the region
       * rooted in the given Fqn.
       *
  -    * @param fqn
  +    * @param fqn representing the region to be activated.
       */
      public void activate(Fqn fqn)
      {
  @@ -319,7 +258,7 @@
                  // FIXME - persistent state transfer counts too!
                  if (cache.getConfiguration().isFetchInMemoryState())
                  {
  -                  activateRegion(r.getFqn().toString());
  +                  activateRegion(r.getFqn());
                  }
               }
            }
  @@ -331,7 +270,7 @@
               // FIXME - persistent state transfer counts too!
               if (cache.getConfiguration().isFetchInMemoryState())
               {
  -               activateRegion(r.getFqn().toString());
  +               activateRegion(r.getFqn());
               }
            }
         }
  @@ -351,16 +290,19 @@
       * node exists anywhere else in the cluster.  If the node does not exist
       * elsewhere, the local node will be empty.  The creation of this node will
       * not be replicated.
  +    * <p/>
  +    * <p/>
  +    * This is legacy code and should not be called directly.  This is a private method for now and will be refactored out.
  +    * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
  +    * <p/>
       *
  -    * @param subtreeFqn Fqn string indicating the uppermost node in the
  +    * @param fqn Fqn string indicating the uppermost node in the
       *                   portion of the cache that should be activated.
       * @throws RegionNotEmptyException if the node <code>subtreeFqn</code>
       *                                 exists and has either data or children
       */
  -   public void activateRegion(String subtreeFqn) throws CacheException
  +   private void activateRegion(Fqn fqn) throws CacheException
      {
  -      Fqn fqn = Fqn.fromString(subtreeFqn);
  -
         // Check whether the node already exists and has data
         Node subtreeRoot = cache.findNode(fqn);
   
  @@ -447,16 +389,16 @@
         }
         catch (Throwable t)
         {
  -         log.error("failed to activate " + subtreeFqn, t);
  +         log.error("failed to activate " + fqn, t);
   
            // "Re-deactivate" the region
            try
            {
  -            inactivateRegion(subtreeFqn);
  +            inactivateRegion(fqn);
            }
            catch (Exception e)
            {
  -            log.error("failed inactivating " + subtreeFqn, e);
  +            log.error("failed inactivating " + fqn, e);
               // just swallow this one and throw the first one
            }
   
  @@ -482,14 +424,15 @@
      }
   
      /**
  -    * Convenienve method.  If the region defined by fqn does not exist, {@link #isDefaultInactive()} is returned.
  +    * Convenienve method.  If the region defined by fqn does not exist, {@link #isDefaultInactive()} is returned, otherwise
  +    * !{@link Region#isActive()} is returned.
       *
       * @param fqn fqn to test
       * @return true if inactive
       */
  -   public boolean isInactive(String fqn)
  +   public boolean isInactive(Fqn fqn)
      {
  -      Region region = getRegion(Fqn.fromString(fqn), false);
  +      Region region = getRegion(fqn, false);
         return region == null ? defaultInactive : !region.isActive();
      }
   
  @@ -497,8 +440,12 @@
      /**
       * Causes the cache to stop accepting replication events for the subtree
       * rooted at <code>subtreeFqn</code> and evict all nodes in that subtree.
  +    * <p/>
  +    * This is legacy code and should not be called directly.  This is a private method for now and will be refactored out.
  +    * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
  +    * <p/>
       *
  -    * @param subtreeFqn Fqn string indicating the uppermost node in the
  +    * @param fqn Fqn string indicating the uppermost node in the
       *                   portion of the cache that should be activated.
       * @throws RegionNameConflictException if <code>subtreeFqn</code> indicates
       *                                     a node that is part of another
  @@ -508,12 +455,11 @@
       * @throws CacheException              if there is a problem evicting nodes
       * @throws IllegalStateException       if {@link org.jboss.cache.config.Configuration#isUseRegionBasedMarshalling()} is <code>false</code>
       */
  -   public void inactivateRegion(String subtreeFqn) throws CacheException
  +   private void inactivateRegion(Fqn fqn) throws CacheException
      {
  -      Fqn fqn = Fqn.fromString(subtreeFqn);
         if (isActivatingDeactivating(fqn))
         {
  -         throw new CacheException("Region " + subtreeFqn + " is already being activated/deactivated");
  +         throw new CacheException("Region " + fqn + " is already being activated/deactivated");
         }
   
         NodeSPI parent = null;
  @@ -528,9 +474,9 @@
            // Record that this fqn is in status change, so can't provide state
            activationChangeNodes.add(fqn);
   
  -         if (!isInactive(subtreeFqn))
  +         if (!isInactive(fqn))
            {
  -            deactivate(subtreeFqn);
  +            deactivate(fqn);
            }
   
            // Create a list with the Fqn in the main cache and any buddy backup trees
  @@ -633,42 +579,42 @@
         }
      }
   
  -   public boolean isActivatingDeactivating(Fqn fqn)
  -   {
  -      return activationChangeNodes.contains(fqn);
  -   }
  -
      /**
  -    * Overloaded form of {@link #activate(Fqn)}
  +    * <p/>
  +    * This is legacy code and should not be called directly.  This is a private method for now and will be refactored out.
  +    * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
  +    * <p/>
       *
  -    * @param fqn
  -    * @see #activate(Fqn)
  +    * @param fqn fqn of the region
  +    * @return true if the region defined by the fqn is in the process of activating/deactivating
       */
  -   public void activate(String fqn)
  +   private boolean isActivatingDeactivating(Fqn fqn)
      {
  -      activate(Fqn.fromString(fqn));
  +      return activationChangeNodes.contains(fqn);
      }
   
      /**
       * Returns true if the region exists
       *
       * @param fqn FQN of the region
  +    * @param type type of region to search for
       * @return true if the region exists
       */
  -   public boolean hasRegion(Fqn fqn)
  +   public boolean hasRegion(Fqn fqn, Region.Type type)
      {
  -      return regionsRegistry.containsKey(fqn);
  +      Region r = regionsRegistry.get(fqn);
  +      if (r == null) return false;
  +      switch (type)
  +      {
  +         case ANY:
  +            return true;
  +         case EVICTION:
  +            return r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r);
  +         case MARSHALLING:
  +            return r.isActive() && r.getClassLoader() != null;
      }
  -
  -   /**
  -    * Overloaded form of {@link #hasRegion(Fqn)}
  -    *
  -    * @param fqn
  -    * @see #hasRegion(Fqn)
  -    */
  -   public boolean hasRegion(String fqn)
  -   {
  -      return hasRegion(Fqn.fromString(fqn));
  +      // should never reach here?
  +      return false;
      }
   
      /**
  @@ -702,7 +648,7 @@
                  // is in memory!
                  if (cache.getConfiguration().isFetchInMemoryState())
                  {
  -                  inactivateRegion(fqn.toString());
  +                  inactivateRegion(fqn);
                  }
               }
            }
  @@ -714,7 +660,7 @@
               // is in memory!
               if (cache.getConfiguration().isFetchInMemoryState())
               {
  -               inactivateRegion(fqn.toString());
  +               inactivateRegion(fqn);
               }
            }
         }
  @@ -725,17 +671,6 @@
      }
   
      /**
  -    * Overloaded form of {@link #deactivate(Fqn)}
  -    *
  -    * @param fqn
  -    * @see #deactivate(Fqn)
  -    */
  -   public void deactivate(String fqn)
  -   {
  -      deactivate(Fqn.fromString(fqn));
  -   }
  -
  -   /**
       * Resets the region manager's regions registry
       */
      public void reset()
  @@ -744,51 +679,27 @@
      }
   
      /**
  +    * Returns an ordered list of all 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 active regions with registered context class loaders.
  +    * @param type Type of region to return
  +    * @return an ordered list of all regions, based on the type requested.
       */
  -   public List<Region> getAllMarshallingRegions()
  +   public List<Region> getAllRegions(Region.Type type)
      {
  -      List<Region> regions = new ArrayList<Region>();
  -
  -      for (Region r : regionsRegistry.values()) if (r.isActive() && r.getClassLoader() != null) regions.add(r);
  -
  -      Collections.sort(regions);
  -
  -      return regions;
  -   }
  +      List<Region> regions = new ArrayList<Region>(regionsRegistry.values());
   
  -   /**
  -    * Returns an ordered list of all active regions which have defined eviction policies.
  -    * 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()
  +      if (type != Region.Type.ANY)
      {
  -      List<Region> regions = new ArrayList<Region>();
  -
  +         // we need to loop thru the regions and weed out the unwanted types.
         for (Region r : regionsRegistry.values())
         {
  -         if (r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) regions.add(r);
  +            if ((type == Region.Type.EVICTION && r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
  +                    (type == Region.Type.MARSHALLING && r.isActive() && r.getClassLoader() != null))
  +               regions.add(r);
         }
  -
  -      Collections.sort(regions);
  -
  -      return regions;
      }
   
  -   /**
  -    * Returns an ordered list of all 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()
  -   {
  -      List<Region> regions = new ArrayList<Region>(regionsRegistry.values());
  -
         Collections.sort(regions);
   
         return regions;
  
  
  



More information about the jboss-cvs-commits mailing list