Author: manik.surtani(a)jboss.com
Date: 2008-06-30 09:29:46 -0400 (Mon, 30 Jun 2008)
New Revision: 6122
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
Log:
Propertransformation of Fqns when looking up regions
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-06-30 12:34:18 UTC
(rev 6121)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-06-30 13:29:46 UTC
(rev 6122)
@@ -12,7 +12,6 @@
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.Destroy;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.NonVolatile;
@@ -63,6 +62,7 @@
protected RPCManager rpcManager;
private LockManager lockManager;
private BuddyFqnTransformer buddyFqnTransformer;
+ private boolean isUsingBR;
@Inject
void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager
rpcManager, LockManager lockManager,
@@ -79,6 +79,7 @@
protected void start()
{
log.trace("Starting region manager");
+ isUsingBR = configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
if (configuration.getEvictionConfig() != null
&& configuration.getEvictionConfig().isValidConfig())
{
@@ -176,6 +177,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)
{
@@ -183,13 +187,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/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-06-30
12:34:18 UTC (rev 6121)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-06-30
13:29:46 UTC (rev 6122)
@@ -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;
@@ -51,7 +56,6 @@
*/
protected Map<Object, List<Modification>> transactions = new
ConcurrentHashMap<Object, List<Modification>>();
-
public void put(Fqn fqn, Map<Object, Object> attributes, boolean erase) throws
Exception
{
if (erase)
@@ -78,8 +82,6 @@
boolean moveToBuddy = subtree.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN)
&& subtree.size() > 1;
// store new state
- Fqn fqn;
- //NodeData nd = null;
Object objectFromStream = cache.getMarshaller().objectFromObjectStream(in);
if (objectFromStream instanceof NodeDataMarker)
{
@@ -167,7 +169,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 +195,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/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-06-30
12:34:18 UTC (rev 6121)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-06-30
13:29:46 UTC (rev 6122)
@@ -9,9 +9,7 @@
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.WriteCommand;
@@ -57,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
@@ -68,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
@@ -191,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/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-06-30
12:34:18 UTC (rev 6121)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-06-30
13:29:46 UTC (rev 6122)
@@ -24,7 +24,16 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
/**
* An enhanced marshaller for RPC calls between CacheImpl instances.
@@ -212,7 +221,7 @@
private Region findRegion(Fqn fqn) throws InactiveRegionException
{
- Region region = getRegion(fqn);
+ Region region = regionManager.getValidMarshallingRegion(fqn);
if (region != null)
{
@@ -250,7 +259,7 @@
{
Fqn fqn = extractFqn(cmd);
- Region r = getRegion(fqn);
+ Region r = regionManager.getValidMarshallingRegion(fqn);
return r == null ? null : r.getFqn();
}