[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...
Manik Surtani
msurtani at jboss.com
Thu Oct 12 19:03:57 EDT 2006
User: msurtani
Date: 06/10/12 19:03:57
Modified: src/org/jboss/cache/marshall
RegionNameConflictException.java
RegionNotFoundException.java
VersionAwareMarshaller.java Marshaller.java
MethodDeclarations.java TreeCacheMarshaller200.java
Removed: src/org/jboss/cache/marshall
LegacyTreeCacheMarshaller.java Region.java
TreeCacheMarshaller140.java RegionManager.java
TreeCacheMarshaller.java
Log:
a LOT of changes around Regions, in an attempt to unify eviction and marshalling regions
Revision Changes Path
1.4 +13 -13 JBossCache/src/org/jboss/cache/marshall/RegionNameConflictException.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionNameConflictException.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/RegionNameConflictException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- RegionNameConflictException.java 7 Jun 2006 22:28:08 -0000 1.3
+++ RegionNameConflictException.java 12 Oct 2006 23:03:57 -0000 1.4
@@ -1,7 +1,7 @@
package org.jboss.cache.marshall;
/**
- * Region name conflicts with pre-existing regions. The conflict may come from there is already an
+ * MarshRegion name conflicts with pre-existing regions. The conflict may come from there is already an
* parent region defined.
*
* @author Ben Wang 8-2005
1.4 +13 -13 JBossCache/src/org/jboss/cache/marshall/RegionNotFoundException.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionNotFoundException.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/RegionNotFoundException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- RegionNotFoundException.java 7 Jun 2006 22:28:08 -0000 1.3
+++ RegionNotFoundException.java 12 Oct 2006 23:03:57 -0000 1.4
@@ -1,7 +1,7 @@
package org.jboss.cache.marshall;
/**
- * Region name not found.
+ * MarshRegion name not found.
*
* @author Ben Wang 8-2005
*/
1.10 +14 -96 JBossCache/src/org/jboss/cache/marshall/VersionAwareMarshaller.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: VersionAwareMarshaller.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/VersionAwareMarshaller.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- VersionAwareMarshaller.java 30 Aug 2006 18:31:06 -0000 1.9
+++ VersionAwareMarshaller.java 12 Oct 2006 23:03:57 -0000 1.10
@@ -8,11 +8,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.invocation.MarshalledValueInputStream;
-import org.jboss.invocation.MarshalledValueOutputStream;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.RegionManager;
import org.jgroups.blocks.RpcDispatcher;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -21,7 +20,7 @@
import java.util.StringTokenizer;
/**
- * A facade to various other marshallers like {@link LegacyTreeCacheMarshaller} and {@link TreeCacheMarshaller140}
+ * A facade to various other marshallers like {@link org.jboss.cache.marshall.TreeCacheMarshaller200}
* which is version-aware.
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
@@ -30,13 +29,12 @@
{
private RegionManager manager;
private boolean defaultInactive, useRegionBasedMarshalling;
+ private CacheSPI cache;
private Log log = LogFactory.getLog(VersionAwareMarshaller.class);
Marshaller defaultMarshaller;
Map<Integer, Marshaller> marshallers = new HashMap<Integer, Marshaller>();
- private static final int VERSION_LEGACY = 1;
- private static final int VERSION_140 = 14;
private static final int VERSION_200 = 20;
private int versionInt;
@@ -56,16 +54,10 @@
switch (versionInt)
{
case VERSION_200:
+ default:
defaultMarshaller = new TreeCacheMarshaller200(manager, defaultInactive, useRegionBasedMarshalling);
marshallers.put(VERSION_200, defaultMarshaller);
break;
- case VERSION_140:
- defaultMarshaller = new TreeCacheMarshaller140(manager, defaultInactive, useRegionBasedMarshalling);
- marshallers.put(VERSION_140, defaultMarshaller);
- break;
- default:
- defaultMarshaller = new LegacyTreeCacheMarshaller(manager, defaultInactive, useRegionBasedMarshalling);
- marshallers.put(VERSION_LEGACY, defaultMarshaller);
}
if (log.isDebugEnabled())
@@ -122,15 +114,8 @@
ObjectOutputStream out;
// based on the default marshaller, construct an object output stream based on what's compatible.
- if (defaultMarshaller instanceof LegacyTreeCacheMarshaller)
- {
- out = new MarshalledValueOutputStream(bos);
- }
- else
- {
out = ObjectSerializationFactory.createObjectOutputStream(bos);
out.writeShort(versionInt);
- }
//now marshall the contents of the object
defaultMarshaller.objectToStream(obj, out);
@@ -143,8 +128,8 @@
public Object objectFromByteBuffer(byte[] buf) throws Exception
{
Marshaller marshaller;
- int versionId = VERSION_LEGACY;
- ObjectInputStream in = null;
+ int versionId;
+ ObjectInputStream in;
try
{
// just a peek - does not actually "remove" these bytes from the stream.
@@ -154,46 +139,14 @@
}
catch (Exception e)
{
- log.debug("Unable to read version id from first two bytes of stream. Probably from a version prior to JBC 1.4.0. Reverting to using a LegacyTreeCacheMarshaller for this communication.");
+ log.error("Unable to read version id from first two bytes of stream, barfing.");
+ throw e;
}
marshaller = getMarshaller(versionId);
- if (marshaller instanceof LegacyTreeCacheMarshaller)
- {
- // create a more 'compatible' ObjectInputStream.
- in = new MarshalledValueInputStream(new ByteArrayInputStream(buf));
- }
-
- try
- {
return marshaller.objectFromStream(in);
}
- catch (Exception e)
- {
- if (marshaller instanceof LegacyTreeCacheMarshaller)
- {
- // the default marshaller IS the legacy marshaller!!
- throw e;
- }
- else
- {
- // retry with legacy marshaller - this is probably because the version id was incorrectly read.
- if (log.isInfoEnabled())
- {
- log.info("Caught exception unmarshalling stream with specific versioned marshaller " + marshaller.getClass() + ". Attempting to try again with legacy marshaller " + LegacyTreeCacheMarshaller.class);
- }
-
- if (log.isTraceEnabled())
- {
- log.trace("Detailed exception caught: ", e);
- }
- // create a more 'compatible' ObjectInputStream.
- in = new MarshalledValueInputStream(new ByteArrayInputStream(buf));
- return getMarshaller(VERSION_LEGACY).objectFromStream(in);
- }
- }
- }
/**
* Lazily instantiates and loads the relevant marshaller for a given version.
@@ -207,6 +160,7 @@
switch (versionId)
{
case VERSION_200:
+ default:
marshaller = marshallers.get(VERSION_200);
if (marshaller == null)
{
@@ -214,53 +168,17 @@
marshallers.put(VERSION_200, marshaller);
}
break;
- case VERSION_140:
- marshaller = marshallers.get(VERSION_140);
- if (marshaller == null)
- {
- marshaller = new TreeCacheMarshaller140(manager, defaultInactive, useRegionBasedMarshalling);
- marshallers.put(VERSION_140, marshaller);
- }
- break;
- default:
- marshaller = marshallers.get(VERSION_LEGACY);
- if (marshaller == null)
- {
- marshaller = new LegacyTreeCacheMarshaller(manager, defaultInactive, useRegionBasedMarshalling);
- marshallers.put(VERSION_LEGACY, marshaller);
- }
}
return marshaller;
}
-
- public void registerClassLoader(String fqn, ClassLoader cl) throws RegionNameConflictException
- {
- defaultMarshaller.registerClassLoader(fqn, cl);
- }
-
- public void unregisterClassLoader(String fqn) throws RegionNotFoundException
- {
- defaultMarshaller.unregisterClassLoader(fqn);
- }
-
public boolean isInactive(String s)
{
return defaultMarshaller.isInactive(s);
}
- public ClassLoader getClassLoader(String fqnS) throws RegionNotFoundException
+ public ClassLoader getClassLoader(String fqnS)
{
return defaultMarshaller.getClassLoader(fqnS);
}
-
- public void inactivate(String subtreeFqn) throws RegionNameConflictException
- {
- defaultMarshaller.inactivate(subtreeFqn);
- }
-
- public void activate(String subtreeFqn) throws RegionNameConflictException
- {
- defaultMarshaller.activate(subtreeFqn);
- }
}
1.5 +16 -140 JBossCache/src/org/jboss/cache/marshall/Marshaller.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Marshaller.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/Marshaller.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Marshaller.java 30 Aug 2006 13:40:34 -0000 1.4
+++ Marshaller.java 12 Oct 2006 23:03:57 -0000 1.5
@@ -10,6 +10,8 @@
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.BuddyManager;
import java.io.ObjectInputStream;
@@ -134,7 +136,7 @@
// possible when we have a replication queue.
fqnStr = extractFqn((MethodCall) args[0]);
break;
- default :
+ default:
if (MethodDeclarations.isCrudMethod(methodCall.getMethodId()))
{
Fqn fqn2 = (Fqn) args[1];
@@ -156,6 +158,12 @@
return fqnStr;
}
+ /**
+ * Retrieves the {@link Region} from the {@link RegionManager} after taking into account that this may be a Buddy Backup FQN
+ *
+ * @param fqnString
+ * @return
+ */
protected Region getRegion(String fqnString)
{
Fqn fqn = Fqn.fromString(fqnString);
@@ -165,168 +173,36 @@
// Strip out the buddy group portion
fqn = fqn.getFqnChild(2, fqn.size());
}
- return regionManager.getRegion(fqn);
- }
-
- /**
- * Register the specific classloader under the <code>fqn</code> region.
- *
- * @param fqn
- * @param cl
- * @throws RegionNameConflictException thrown if there is a conflict in region definition.
- */
- public void registerClassLoader(String fqn, ClassLoader cl)
- throws RegionNameConflictException
- {
- if (!useRegionBasedMarshalling) return;
- Region existing = regionManager.getRegion(fqn);
- if (existing == null)
- {
- regionManager.createRegion(fqn, cl, defaultInactive);
- }
- else
- {
- existing.setClassLoader(cl);
- }
- }
-
- /**
- * Un-register the class loader. Caller will need to call this when the application is out of scope.
- * Otherwise, the class loader will not get gc.
- *
- * @param fqn
- */
- public void unregisterClassLoader(String fqn) throws RegionNotFoundException
- {
- if (!useRegionBasedMarshalling) return;
- // Brian -- we no longer remove the region, as regions
- // also have the inactive property
- // TODO how to clear regions from the RegionManager??
- //regionManager.removeRegionToProcess(fqn);
- Region region = regionManager.getRegion(fqn);
- if (region != null)
- {
- region.setClassLoader(null);
- }
+ return regionManager.getRegion(fqn, false);
}
/**
- * Gets the classloader previously registered for <code>fqn</code> by
- * a call to {@link #registerClassLoader(String, ClassLoader)}.
+ * Gets the classloader previously registered for <code>fqn</code>.
*
* @param fqn the fqn
* @return the classloader associated with the cache region rooted by
* <code>fqn</code>, or <code>null</code> if no classloader has
* been associated with the region.
- * @throws RegionNotFoundException
*/
- public ClassLoader getClassLoader(String fqn) throws RegionNotFoundException
+ public ClassLoader getClassLoader(String fqn)
{
- if (!useRegionBasedMarshalling) return null;
ClassLoader result = null;
- Region region = regionManager.getRegion(fqn);
- if (region != null)
- {
- result = region.getClassLoader();
- }
+ Region region = regionManager.getRegion(Fqn.fromString(fqn), false);
+ if (region != null) result = region.getClassLoader();
return result;
}
/**
- * Activates unmarshalling of replication messages for the region
- * rooted in the given Fqn.
- *
- * @param fqn
- */
- public void activate(String fqn) throws RegionNameConflictException
- {
- if (!useRegionBasedMarshalling) return;
- if (regionManager.hasRegion(fqn)) // tests for an exact match
- {
- Region region = regionManager.getRegion(fqn);
- if (!defaultInactive && region.getClassLoader() == null)
- {
- // This region's state will no match that of a non-existent one
- // So, there is no reason to keep this region any more
- regionManager.removeRegion(fqn);
- }
- else
- {
- region.activate();
- }
- }
- else if (defaultInactive)
- {
- // "Active" region is not the default, so create a region
- // May throw RegionNameConflictException
- regionManager.createRegion(fqn, null, false);
- }
- else
- {
- // "Active" is the default, so no need to create a region,
- // but must check if this one conflicts with others
- regionManager.checkConflict(fqn);
- }
- }
-
- /**
- * Disables unmarshalling of replication messages for the region
- * rooted in the given Fqn.
- *
- * @param fqn
- * @throws RegionNameConflictException if there is a conflict in region definition.
- */
- public void inactivate(String fqn) throws RegionNameConflictException
- {
- if (!useRegionBasedMarshalling) return;
- if (regionManager.hasRegion(fqn)) // tests for an exact match
- {
- Region region = regionManager.getRegion(fqn);
- if (defaultInactive && region.getClassLoader() == null)
- {
- // This region's state will no match that of a non-existent one
- // So, there is no reason to keep this region any more
- regionManager.removeRegion(fqn);
- }
- else
- {
- region.inactivate();
- }
- }
- else if (!defaultInactive)
- {
- regionManager.createRegion(fqn, null, true);
- }
- else
- {
- // nodes are by default inactive, so we don't have to create one
- // but, we must check in case fqn is in conflict with another region
- regionManager.checkConflict(fqn);
- }
-
- }
-
- /**
* Gets whether unmarshalling has been disabled for the region
* rooted in the given Fqn.
*
* @param fqn
* @return <code>true</code> if unmarshalling is disabled;
* <code>false</code> otherwise.
- * @see #activate
- * @see #inactivate
*/
public boolean isInactive(String fqn)
{
- if (!useRegionBasedMarshalling) return false;
- boolean result = defaultInactive;
-
- Region region = regionManager.getRegion(fqn);
- if (region != null)
- {
- result = region.isInactive();
- }
-
- return result;
+ Region region = regionManager.getRegion(Fqn.fromString(fqn), false);
+ return region == null ? defaultInactive : !region.isActive();
}
}
1.19 +3 -17 JBossCache/src/org/jboss/cache/marshall/MethodDeclarations.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MethodDeclarations.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/MethodDeclarations.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- MethodDeclarations.java 19 Sep 2006 17:10:50 -0000 1.18
+++ MethodDeclarations.java 12 Oct 2006 23:03:57 -0000 1.19
@@ -30,7 +30,7 @@
* allowing lookup operations both ways.
*
* @author <a href="galder.zamarreno at jboss.com">Galder Zamarreno</a>
- * @version $Revision: 1.18 $
+ * @version $Revision: 1.19 $
*/
public class MethodDeclarations
{
@@ -97,10 +97,6 @@
public static final Method getPartialStateMethod;
- public static final Method enqueueMethodCallMethod;
-
- public static final Method notifyCallOnInactiveMethod;
-
public static final Method clusteredGetMethod;
public static final Method remoteAssignToBuddyGroupMethod;
@@ -154,10 +150,6 @@
public static final int getPartialStateMethod_id = 19;
- public static final int enqueueMethodCallMethod_id = 20;
-
- public static final int notifyCallOnInactiveMethod_id = 21;
-
public static final int clusteredGetMethod_id = 22;
public static final int getChildrenNamesMethodLocal_id = 23;
@@ -226,10 +218,6 @@
clusteredGetMethod = TreeCache.class.getDeclaredMethod("_clusteredGet", MethodCall.class, Boolean.class);
- enqueueMethodCallMethod = TreeCache.class.getDeclaredMethod("_enqueueMethodCall", String.class, MethodCall.class);
-
- notifyCallOnInactiveMethod = TreeCache.class.getDeclaredMethod("notifyCallForInactiveSubtree", String.class);
-
// ------------ buddy replication
remoteAnnounceBuddyPoolNameMethod = TreeCache.class.getDeclaredMethod("_remoteAnnounceBuddyPoolName", IpAddress.class, String.class);
@@ -266,8 +254,6 @@
methods.put(releaseAllLocksMethodLocal_id, releaseAllLocksMethodLocal);
methods.put(optimisticPrepareMethod_id, optimisticPrepareMethod);
methods.put(getPartialStateMethod_id, getPartialStateMethod);
- methods.put(enqueueMethodCallMethod_id, enqueueMethodCallMethod);
- methods.put(notifyCallOnInactiveMethod_id, notifyCallOnInactiveMethod);
methods.put(clusteredGetMethod_id, clusteredGetMethod);
methods.put(getChildrenNamesMethodLocal_id, getChildrenNamesMethodLocal);
methods.put(getDataMapMethodLocal_id, getDataMapMethodLocal);
@@ -327,7 +313,7 @@
{
if (log.isWarnEnabled())
{
- log.warn("Method " + method + " is not registered with " + TreeCacheMarshaller140.class);
+ log.warn("Method " + method + " is not registered with " + TreeCacheMarshaller200.class);
}
}
@@ -343,7 +329,7 @@
{
log.error("Method id " + id + " is not registered");
}
- throw new RuntimeException("Method id " + id + " is not registered with " + TreeCacheMarshaller140.class);
+ throw new RuntimeException("Method id " + id + " is not registered with " + TreeCacheMarshaller200.class);
}
return method;
}
1.6 +5 -20 JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller200.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheMarshaller200.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller200.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- TreeCacheMarshaller200.java 7 Sep 2006 10:43:49 -0000 1.5
+++ TreeCacheMarshaller200.java 12 Oct 2006 23:03:57 -0000 1.6
@@ -11,6 +11,8 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.GlobalTransaction;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.rpc.RpcTreeCache;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
@@ -97,23 +99,10 @@
region = findRegion(fqn);
}
retValue = region == null ? unmarshallObject(in, refMap) : unmarshallObject(in, region.getClassLoader(), refMap);
- if (region != null && region.isQueueing())
- {
- Object originalRetValue = retValue;
- if (log.isDebugEnabled())
- {
- log.debug("Received call on an ququing Fqn region (" + fqn + "). Calling enqueueMethodCallMethod");
- }
- retValue = MethodCallFactory.create(MethodDeclarations.enqueueMethodCallMethod, fqn, originalRetValue);
- }
}
catch (TreeCacheMarshaller200.InactiveRegionException e)
{
- if (log.isDebugEnabled())
- {
- log.debug("Received call on an inactive Fqn region (" + fqn + "). Calling notifyCallOnInactiveMetod");
- }
- retValue = MethodCallFactory.create(MethodDeclarations.notifyCallOnInactiveMethod, fqn);
+ throw new RuntimeException("Invocation called on an inactive region [" + fqn + "]!");
}
}
else
@@ -127,19 +116,15 @@
private Region findRegion(String fqn) throws TreeCacheMarshaller200.InactiveRegionException
{
Region region;
- // obtain a region from RegionManager, if not, will use default.
+ // obtain a region from MarshRegionManager, if not, will use default.
region = fqn == null ? null : getRegion(fqn);
if (region != null)
{
- // If the region has been marked inactive, we still have
- // to return a MethodCall or RpcDispatcher will log an Error.
- // So, return a call to the TreeCache "_notifyCallOnInactive" method
- if (region.getStatus() == Region.STATUS_INACTIVE)
+ if (!region.isActive())
{
throw new TreeCacheMarshaller200.InactiveRegionException();
}
-
}
else if (defaultInactive)
{
More information about the jboss-cvs-commits
mailing list