[jbosscache-commits] JBoss Cache SVN: r6115 - in core/branches/2.2.X/src: main/java/org/jboss/cache/loader and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Jun 27 21:08:32 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-06-27 21:08:31 -0400 (Fri, 27 Jun 2008)
New Revision: 6115

Modified:
   core/branches/2.2.X/src/main/java/org/jboss/cache/RegionManager.java
   core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
   core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
   core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
   core/branches/2.2.X/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
Log:
Proper translation of buddy fqns when determining regions

Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/RegionManager.java	2008-06-27 23:06:37 UTC (rev 6114)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/RegionManager.java	2008-06-28 01:08:31 UTC (rev 6115)
@@ -6,15 +6,28 @@
 import static org.jboss.cache.Region.Type.*;
 import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.config.*;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.eviction.EvictionTimerTask;
 import org.jboss.cache.eviction.RegionNameConflictException;
-import org.jboss.cache.factories.annotations.*;
+import org.jboss.cache.factories.annotations.Destroy;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
 import org.jboss.cache.lock.LockManager;
 import static org.jboss.cache.lock.LockType.WRITE;
 import org.jgroups.Address;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -50,6 +63,7 @@
    protected RPCManager rpcManager;
    private LockManager lockManager;
    private BuddyFqnTransformer buddyFqnTransformer;
+   private boolean isUsingBR;
 
    @Inject
    void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager rpcManager, LockManager lockManager,
@@ -66,6 +80,7 @@
    protected void start()
    {
       log.trace("Starting region manager");
+      isUsingBR = configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
       if (configuration.getEvictionConfig() != null
             && configuration.getEvictionConfig().isValidConfig())
       {
@@ -163,6 +178,9 @@
    /**
     * 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.
+    * <p/>
+    * Note that this takes into account the fact that this may be a Buddy Backup Fqn.  If it is, the actual Fqn is calculated
+    * and used instead.
     */
    public Region getRegion(Fqn fqn, boolean createIfAbsent)
    {
@@ -170,13 +188,34 @@
    }
 
    /**
+    * Retrieves a valid marshalling {@link Region} after taking into account that this may be a Buddy Backup Fqn.
+    * If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.
+    *
+    * @param fqn of the region to locate
+    * @return a region
+    */
+   public Region getValidMarshallingRegion(Fqn fqn)
+   {
+      if (fqn == null) return null;
+      return getRegion(fqn, Region.Type.MARSHALLING, false);
+   }
+
+   /**
     * An overloaded form of {@link #getRegion(Fqn,boolean)} that takes an additional {@link org.jboss.cache.Region.Type}
     * parameter to force regions of a specific type.
+    * <p/>
+    * Note that this takes into account the fact that this may be a Buddy Backup Fqn.  If it is, the actual Fqn is calculated
+    * and used instead.
     *
     * @see org.jboss.cache.Region.Type
     */
    public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
    {
+      if (isUsingBR && fqn != null && buddyFqnTransformer.isBackupFqn(fqn))
+      {
+         fqn = buddyFqnTransformer.getActualFqn(fqn);
+      }
+
       if (log.isTraceEnabled()) log.trace("Contents of RegionsRegistry: " + regionsRegistry);
       Fqn fqnToUse = fqn;
       if (DEFAULT_REGION.equals(fqnToUse)) fqnToUse = Fqn.ROOT;

Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java	2008-06-27 23:06:37 UTC (rev 6114)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java	2008-06-28 01:08:31 UTC (rev 6115)
@@ -8,7 +8,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.*;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
 import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.marshall.Marshaller;
@@ -167,7 +172,7 @@
 
    protected void regionAwareMarshall(Fqn fqn, Object toMarshall) throws Exception
    {
-      Region r = regionManager == null ? null : regionManager.getRegion(fqn, Region.Type.MARSHALLING, false);
+      Region r = regionManager == null ? null : regionManager.getValidMarshallingRegion(fqn);
       ClassLoader originalClassLoader = null;
       boolean needToResetLoader = false;
       Thread current = null;
@@ -193,7 +198,7 @@
 
    protected Object regionAwareUnmarshall(Fqn fqn, Object toUnmarshall) throws Exception
    {
-      Region r = regionManager == null ? null : regionManager.getRegion(fqn, Region.Type.MARSHALLING, false);
+      Region r = regionManager == null ? null : regionManager.getValidMarshallingRegion(fqn);
       ClassLoader originalClassLoader = null;
       boolean needToResetLoader = false;
       Thread current = null;

Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java	2008-06-27 23:06:37 UTC (rev 6114)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java	2008-06-28 01:08:31 UTC (rev 6115)
@@ -9,15 +9,27 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.commands.DataCommand;
 import org.jboss.cache.commands.ReplicableCommand;
 import org.jboss.cache.commands.ReversibleCommand;
-import org.jboss.cache.commands.read.*;
-import org.jboss.cache.commands.remote.*;
-import org.jboss.cache.commands.tx.*;
+import org.jboss.cache.commands.read.ExistsCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
+import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
+import org.jboss.cache.commands.remote.ClusteredGetCommand;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
+import org.jboss.cache.commands.remote.ReplicateCommand;
+import org.jboss.cache.commands.tx.AbstractTransactionCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
 import org.jboss.cache.commands.write.EvictCommand;
 import org.jboss.cache.commands.write.InvalidateCommand;
 import org.jboss.cache.config.Configuration;
@@ -43,7 +55,6 @@
    protected boolean defaultInactive;
    protected Log log;
    protected boolean trace;
-   private BuddyFqnTransformer buddyFqnTransformer;
 
    /**
     * Map<GlobalTransaction, Fqn> for prepared tx that have not committed
@@ -54,12 +65,11 @@
    protected boolean useRefs = false;
 
    @Inject
-   void injectDependencies(RegionManager regionManager, Configuration configuration, ClassLoader defaultClassLoader, BuddyFqnTransformer transformer)
+   void injectDependencies(RegionManager regionManager, Configuration configuration, ClassLoader defaultClassLoader)
    {
       this.defaultClassLoader = defaultClassLoader;
       this.regionManager = regionManager;
       this.configuration = configuration;
-      this.buddyFqnTransformer = transformer;
    }
 
    @Start
@@ -177,22 +187,4 @@
 
       return fqn;
    }
-
-   /**
-    * Retrieves the {@link Region} from the {@link RegionManager} after taking into account that this may be a Buddy Backup Fqn.
-    * If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.
-    *
-    * @param fqn of the region to locate
-    * @return a region
-    */
-   protected Region getRegion(Fqn fqn)
-   {
-      if (fqn == null) return null;
-      if (buddyFqnTransformer.isBackupFqn(fqn))
-      {
-         // Strip out the buddy group portion
-         fqn = buddyFqnTransformer.getActualFqn(fqn);
-      }
-      return regionManager.getRegion(fqn, Region.Type.MARSHALLING, false);
-   }
 }

Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java	2008-06-27 23:06:37 UTC (rev 6114)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java	2008-06-28 01:08:31 UTC (rev 6115)
@@ -212,7 +212,7 @@
 
    private Region findRegion(Fqn fqn) throws InactiveRegionException
    {
-      Region region = getRegion(fqn);
+      Region region = regionManager.getValidMarshallingRegion(fqn);
 
       if (region != null)
       {
@@ -250,7 +250,7 @@
    {
       Fqn fqn = extractFqn(cmd);
 
-      Region r = getRegion(fqn);
+      Region r = regionManager.getValidMarshallingRegion(fqn);
       return r == null ? null : r.getFqn();
    }
 

Modified: core/branches/2.2.X/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/branches/2.2.X/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2008-06-27 23:06:37 UTC (rev 6114)
+++ core/branches/2.2.X/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2008-06-28 01:08:31 UTC (rev 6115)
@@ -9,7 +9,6 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.commands.remote.ClusteredGetCommand;
 import org.testng.annotations.Test;
 
@@ -38,7 +37,7 @@
       // need to test what's going on with 
       CacheMarshaller200 cm200 = new CacheMarshaller200();
       c.setUseRegionBasedMarshalling(true);
-      cm200.injectDependencies(new RegionManager(), c, getClass().getClassLoader(), new BuddyFqnTransformer());
+      cm200.injectDependencies(new RegionManager(), c, getClass().getClassLoader());
       cm200.init();
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(baos);




More information about the jbosscache-commits mailing list