[jbosscache-commits] JBoss Cache SVN: r4921 - in core/trunk/src: main/java/org/jboss/cache/factories and 5 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Dec 27 20:45:02 EST 2007


Author: manik.surtani at jboss.com
Date: 2007-12-27 20:45:01 -0500 (Thu, 27 Dec 2007)
New Revision: 4921

Removed:
   core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
   core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
   core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
   core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
   core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java
   core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
   core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
   core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
   core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
   core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java
Log:
Fixed marshalling-related issues

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -2798,7 +2798,7 @@
          // use a get() call into the cache to make sure cache loading takes place.
          // no need to cache the original skipDataGravitation setting here - it will always be false of we got here!!
          ctx.getOptionOverrides().setSkipDataGravitation(true);
-         Node actualNode = get(fqn);
+         Node actualNode = spi.getNode(fqn);
          ctx.getOptionOverrides().setSkipDataGravitation(false);
 
          if (log.isTraceEnabled()) log.trace("In local tree, this is " + actualNode);
@@ -2839,7 +2839,7 @@
          else
          {
             // make sure we LOAD data for this node!!
-            getData(actualNode.getFqn());
+            actualNode.getData();
          }
 
          if (backupNodeFqn == null && searchSubtrees)
@@ -2897,24 +2897,28 @@
 
    public void _dataGravitationCleanup(GlobalTransaction gtx, Fqn primary, Fqn backup) throws Exception
    {
-      MethodCall primaryDataCleanup, backupDataCleanup;
+//      MethodCall primaryDataCleanup, backupDataCleanup;
       if (buddyManager.isDataGravitationRemoveOnFind())
       {
          if (log.isTraceEnabled())
             log.trace("DataGravitationCleanup: Removing primary (" + primary + ") and backup (" + backup + ")");
-         primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, primary, false);
-         backupDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, backup, false);
+         //primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, primary, false);
+         spi.removeNode(primary);
+         //backupDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, backup, false);
+         spi.removeNode(backup);
       }
       else
       {
          if (log.isTraceEnabled())
             log.trace("DataGravitationCleanup: Evicting primary (" + primary + ") and backup (" + backup + ")");
-         primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, primary);
-         backupDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, backup);
+         //primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, primary);
+         spi.evict(primary, true);
+         //backupDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, backup);
+         spi.evict(backup, true);
       }
 
-      invokeMethod(primaryDataCleanup, true);
-      invokeMethod(backupDataCleanup, true);
+//      invokeMethod(primaryDataCleanup, true);
+//      invokeMethod(backupDataCleanup, true);
    }
 
    // ------------- end: buddy replication specific 'lifecycle' method calls

Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,52 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.annotations.DefaultFactoryFor;
-import org.jboss.cache.marshall.CacheMarshaller210;
-import org.jboss.cache.marshall.Marshaller;
-import org.jboss.cache.marshall.VersionAwareMarshaller;
-import org.jboss.cache.util.Util;
-
-/**
- * Factory for creating marshallers
- *
- * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
- * @since 2.1.0
- */
- at DefaultFactoryFor(classes = {Marshaller.class})
-public class CacheMarshallerFactory extends ComponentFactory
-{
-   @Override
-   @SuppressWarnings("unchecked")
-   protected <T> T construct(String componentName, Class<T> componentType)
-   {
-      assertTypeConstructable(componentType, Marshaller.class);
-
-      Marshaller m;
-
-      String marshallerClass = configuration.getMarshallerClass();
-
-      if (marshallerClass == null)
-      {
-         marshallerClass = CacheMarshaller210.class.getName();
-         log.trace("Cache marshaller implementation not specified; using default " + marshallerClass);
-      }
-
-      try
-      {
-         m = (Marshaller) Util.loadClass(marshallerClass).newInstance();
-      }
-      catch (Exception e)
-      {
-         throw new ConfigurationException("Unable to instantiate marshaller of type " + marshallerClass, e);
-      }
-
-      //componentRegistry.wireDependencies(m);
-
-      if (log.isDebugEnabled()) log.debug("Instantiated " + marshallerClass + "; wrapping in a VersionAwareMarshaller");
-
-      VersionAwareMarshaller vam = new VersionAwareMarshaller(componentRegistry.getOrCreateComponent(null, RegionManager.class), configuration, m);
-      return (T) vam;
-   }
-}

Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -136,9 +136,12 @@
       c.changeState(stateToMoveTo);
 
       // make sure any other omponents that have inadvertently been stopped are now restarted.
-      for (Component comp : componentLookup.values())
+      if (old != null)
       {
-         if (comp.state != stateToMoveTo) comp.changeState(stateToMoveTo);
+         for (Component comp : componentLookup.values())
+         {
+            if (comp.state != stateToMoveTo) comp.changeState(stateToMoveTo);
+         }
       }
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -5,6 +5,8 @@
 import org.jboss.cache.factories.annotations.DefaultFactoryFor;
 import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
 import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.cache.marshall.VersionAwareMarshaller;
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.remoting.jgroups.CacheMessageListener;
 import org.jboss.cache.statetransfer.StateTransferManager;
@@ -16,7 +18,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.1.0
  */
- at DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class})
+ at DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class, Marshaller.class})
 public class EmptyConstructorFactory extends ComponentFactory
 {
    @Override
@@ -27,8 +29,17 @@
       {
          if (componentType.isInterface())
          {
-            // add an "Impl" to the end of the class name and try again
-            Class componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+            Class componentImpl;
+            if (componentType.equals(Marshaller.class))
+            {
+               componentImpl = VersionAwareMarshaller.class;
+            }
+            else
+            {
+               // add an "Impl" to the end of the class name and try again
+               componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+            }
+
             return (T) componentImpl.newInstance();
          }
          else

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -5,6 +5,7 @@
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodCallFactory;
 import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.transaction.GlobalTransaction;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -27,31 +28,37 @@
 
    public Object _replicate(MethodCall methodCall) throws Throwable
    {
-      try
+      if (methodCall.getMethodId() == MethodDeclarations.clusteredGetMethod_id)
+         return invokeClusteredGet(methodCall);
+      else if (MethodDeclarations.isDataGravitationMethod(methodCall.getMethodId()))
+         return invokeDataGravitationCall(methodCall);
+      else
       {
-         Object retVal = invoke(methodCall);
-         // we only need to return values for a set of remote calls; not every call.
-         if (MethodDeclarations.returnValueForRemoteCall(methodCall.getMethodId()))
+         try
          {
-            return retVal;
+            Object retVal = invoke(methodCall);
+            // we only need to return values for a set of remote calls; not every call.
+            if (MethodDeclarations.returnValueForRemoteCall(methodCall.getMethodId()))
+            {
+               return retVal;
+            }
+            else
+            {
+               return null;
+            }
          }
-         else
+         catch (Throwable ex)
          {
-            return null;
+            if (methodCall.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id
+                  || methodCall.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
+            {
+               if (!MethodDeclarations.isBuddyGroupOrganisationMethod(methodCall.getMethodId()) && log.isWarnEnabled())
+                  log.warn("replication failure with methodCall " + methodCall + " exception", ex);
+               throw ex;
+            }
+            else return null;
          }
       }
-      catch (Throwable ex)
-      {
-         if (methodCall.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id
-               || methodCall.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
-         {
-            if (!MethodDeclarations.isBuddyGroupOrganisationMethod(methodCall.getMethodId()) && log.isWarnEnabled())
-               log.warn("replication failure with methodCall " + methodCall + " exception", ex);
-            throw ex;
-         }
-         else return null;
-
-      }
    }
 
    /**
@@ -62,6 +69,31 @@
       for (MethodCall methodCall : methodCalls) _replicate(methodCall);
    }
 
+   public Object invokeClusteredGet(MethodCall call)
+   {
+      Object[] args = call.getArgs();
+      return clusteredGet((MethodCall) args[0], (Boolean) args[1]);
+   }
+
+   public Object invokeDataGravitationCall(MethodCall call) throws Exception
+   {
+      Object[] args = call.getArgs();
+      if (call.getMethodId() == MethodDeclarations.dataGravitationMethod_id)
+      {
+         return cache.gravitateData((Fqn) args[0], (Boolean) args[1]);
+      }
+      else if (call.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
+      {
+         cache._dataGravitationCleanup((GlobalTransaction) args[0], (Fqn) args[1], (Fqn) args[2]);
+         return null;
+      }
+      else
+      {
+         throw new UnsupportedOperationException(call + " is not a data gravitation call!");
+      }
+   }
+
+
    public void block()
    {
       MethodCall m = MethodCallFactory.create(MethodDeclarations.blockChannelLocal);

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -14,6 +14,7 @@
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
 import org.jboss.cache.transaction.GlobalTransaction;
 
 import java.io.ByteArrayOutputStream;
@@ -40,18 +41,20 @@
     * Map<GlobalTransaction, Fqn> for prepared tx that have not committed
     */
    private Map<GlobalTransaction, Fqn> transactions = new ConcurrentHashMap<GlobalTransaction, Fqn>(16);
+   protected Configuration configuration;
 
    @Inject
-   private void injectDependencies(RegionManager regionManager, Configuration configuration)
+   void injectDependencies(RegionManager regionManager, Configuration configuration)
    {
-      init(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling());
+      this.regionManager = regionManager;
+      this.configuration = configuration;
    }
 
-   protected void init(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
+   @Start
+   protected void init()
    {
-      this.useRegionBasedMarshalling = useRegionBasedMarshalling;
-      this.defaultInactive = defaultInactive;
-      this.regionManager = manager;
+      this.useRegionBasedMarshalling = configuration.isUseRegionBasedMarshalling();
+      this.defaultInactive = configuration.isInactiveOnStartup();
    }
 
    // implement the basic contract set in RPcDispatcher.AbstractMarshaller

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -10,7 +10,6 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import static org.jboss.cache.Region.Status;
-import org.jboss.cache.RegionManager;
 import org.jboss.cache.buddyreplication.GravitateResult;
 import org.jboss.cache.optimistic.DefaultDataVersion;
 import org.jboss.cache.transaction.GlobalTransaction;
@@ -68,16 +67,6 @@
       log = LogFactory.getLog(CacheMarshaller200.class);
    }
 
-   public CacheMarshaller200(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
-   {
-      log = LogFactory.getLog(CacheMarshaller200.class);
-      init(manager, defaultInactive, useRegionBasedMarshalling);
-      if (useRegionBasedMarshalling)
-      {
-         log.debug("Using region based marshalling logic : marshalling Fqn first for every call.");
-      }
-   }
-
    /**
     * Tests if the type of object being marshalled is a method call or a return value
     *

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,7 +1,6 @@
 package org.jboss.cache.marshall;
 
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.RegionManager;
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -24,12 +23,6 @@
       log = LogFactory.getLog(CacheMarshaller210.class);
    }
 
-   public CacheMarshaller210(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
-   {
-      super(manager, defaultInactive, useRegionBasedMarshalling);
-      log = LogFactory.getLog(CacheMarshaller210.class);
-   }
-
    /**
     * This version of writeReference is written to solve JBCACHE-1211, where references are encoded as ints rather than shorts.
     *

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -9,8 +9,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.util.Util;
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
@@ -35,59 +35,66 @@
    private static final Log log = LogFactory.getLog(VersionAwareMarshaller.class);
    private static final int VERSION_200 = 20;
    private static final int VERSION_210 = 21;
+   private static final int CUSTOM_MARSHALLER = 999;
 
-   private RegionManager manager;
-   private boolean defaultInactive, useRegionBasedMarshalling;
    Marshaller defaultMarshaller;
    Map<Integer, Marshaller> marshallers = new HashMap<Integer, Marshaller>();
    private int versionInt;
 
-   public VersionAwareMarshaller(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling, String version)
+   @Start
+   protected void initReplicationVersions()
    {
-      this(manager, defaultInactive, useRegionBasedMarshalling, version, null);
-   }
+      String replVersionString = configuration.getReplVersionString();
 
-   public VersionAwareMarshaller(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling, String version, Marshaller defaultMarshaller)
-   {
-      this.manager = manager;
-      this.defaultInactive = defaultInactive;
-      this.useRegionBasedMarshalling = useRegionBasedMarshalling;
-
-      // "Rounds down" the replication version passed in to the MINOR version.
-      // E.g., 1.4.1.SP3 -> 1.4.0
-
-      versionInt = toMinorVersionInt(version);
-
       // this will cause the correct marshaller to be created and put in the map of marshallers
+      defaultMarshaller = configuration.getMarshaller();
       if (defaultMarshaller == null)
       {
+         String marshallerClass = configuration.getMarshallerClass();
+         if (marshallerClass != null)
+         {
+            log.trace("Cache marshaller implementation specified as " + marshallerClass + ".  Overriding any version strings passed in. ");
+            try
+            {
+               defaultMarshaller = (Marshaller) Util.loadClass(marshallerClass).newInstance();
+            }
+            catch (Exception e)
+            {
+               log.warn("Unable to instantiate marshaller of class " + marshallerClass, e);
+               log.warn("Falling back to using the default marshaller for version string " + replVersionString);
+            }
+         }
+      }
+
+      if (defaultMarshaller == null)
+      {
+         // "Rounds down" the replication version passed in to the MINOR version.
+         // E.g., 1.4.1.SP3 -> 1.4.0
+         versionInt = toMinorVersionInt(replVersionString);
          this.defaultMarshaller = getMarshaller(versionInt);
       }
       else
       {
          log.debug("Using the marshaller passed in - " + defaultMarshaller);
-         this.defaultMarshaller = defaultMarshaller;
+         versionInt = getCustomMarshallerVersionInt();
          marshallers.put(versionInt, defaultMarshaller);
       }
 
 
       if (log.isDebugEnabled())
       {
-         log.debug("Initialised with version " + version + " and versionInt " + versionInt);
+         log.debug("Started with version " + replVersionString + " and versionInt " + versionInt);
          log.debug("Using default marshaller class " + this.defaultMarshaller.getClass());
       }
    }
 
-   public VersionAwareMarshaller(RegionManager regionManager, Configuration configuration)
+   protected int getCustomMarshallerVersionInt()
    {
-      this(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling(), configuration.getReplVersionString());
+      if (defaultMarshaller.getClass().equals(CacheMarshaller210.class)) return VERSION_210;
+      if (defaultMarshaller.getClass().equals(CacheMarshaller200.class)) return VERSION_200;
+      return CUSTOM_MARSHALLER;
    }
 
-   public VersionAwareMarshaller(RegionManager regionManager, Configuration configuration, Marshaller defaultMarshaller)
-   {
-      this(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling(), configuration.getReplVersionString(), defaultMarshaller);
-   }
-
    /**
     * Converts versions to known compatible version ids.
     * <p/>
@@ -207,6 +214,7 @@
    Marshaller getMarshaller(int versionId)
    {
       Marshaller marshaller;
+      AbstractMarshaller am;
       boolean knownVersion = false;
       switch (versionId)
       {
@@ -214,7 +222,10 @@
             marshaller = marshallers.get(VERSION_200);
             if (marshaller == null)
             {
-               marshaller = new CacheMarshaller200(manager, defaultInactive, useRegionBasedMarshalling);
+               am = new CacheMarshaller200();
+               marshaller = am;
+               am.injectDependencies(regionManager, configuration);
+               am.init();
                marshallers.put(VERSION_200, marshaller);
             }
             break;
@@ -222,11 +233,14 @@
             knownVersion = true;
          default:
             if (!knownVersion)
-               log.warn("Unknown replication version String.  Falling back to the default marshaller, which is Version 2.1.0.");
+               log.warn("Unknown replication version String.  Falling back to the default marshaller installed.");
             marshaller = marshallers.get(VERSION_210);
             if (marshaller == null)
             {
-               marshaller = new CacheMarshaller210(manager, defaultInactive, useRegionBasedMarshalling);
+               am = new CacheMarshaller210();
+               marshaller = am;
+               am.injectDependencies(regionManager, configuration);
+               am.init();
                marshallers.put(VERSION_210, marshaller);
             }
             break;

Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -48,7 +48,7 @@
 
       // at very least, expecting a Marshaller factory and a DefaultCacheFactory.
       assert cr.defaultFactories.containsKey(Marshaller.class);
-      assert cr.defaultFactories.get(Marshaller.class).equals(CacheMarshallerFactory.class);
+      assert cr.defaultFactories.get(Marshaller.class).equals(EmptyConstructorFactory.class);
       assert cr.defaultFactories.containsKey(Notifier.class);
       assert cr.defaultFactories.get(Notifier.class).equals(EmptyConstructorFactory.class);
 
@@ -107,7 +107,7 @@
    {
       Class<Marshaller> componentToTest = Marshaller.class;
       configuration.setMarshallerClass(CacheMarshaller200.class.getName());
-      Marshaller instance = new CacheMarshaller210(null, false, false);
+      Marshaller instance = new CacheMarshaller210();
       configuration.setCacheMarshaller(instance);
 
       // the setup() would have wired the default marshaller.  Need to update deps.
@@ -125,7 +125,7 @@
    public void testConstructionOrder3()
    {
       Class<Marshaller> componentToTest = Marshaller.class;
-      Marshaller instance = new CacheMarshaller210(null, false, false);
+      Marshaller instance = new CacheMarshaller210();
       configuration.setCacheMarshaller(instance);
 
       // the setup() would have wired the default marshaller.  Need to update deps.

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -12,7 +12,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
-import org.jboss.cache.Version;
+import org.jboss.cache.config.Configuration;
 import org.jboss.cache.misc.TestingUtil;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
@@ -163,7 +163,14 @@
       Region region_A = rman.getRegion(A, true);
       region_A.registerContextClassLoader(this.getClass().getClassLoader());
       assertFalse("New regions created should be inactive by default", region_A.isActive());
-      VersionAwareMarshaller testee = new VersionAwareMarshaller(rman, true, true, Version.getVersionString(Version.getVersionShort()));
+      Configuration c = new Configuration();
+      c.setUseRegionBasedMarshalling(true);
+      c.setInactiveOnStartup(true);
+      VersionAwareMarshaller testee = new VersionAwareMarshaller();
+      testee.injectDependencies(rman, c);
+      testee.init();
+      testee.initReplicationVersions();
+
       byte[] callBytes = testee.objectToByteBuffer(replicate);
 
       try

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -35,7 +35,10 @@
    public void testRegionalisedStream() throws Exception
    {
       // need to test what's going on with 
-      CacheMarshaller200 cm200 = new CacheMarshaller200(new RegionManager(), false, true);
+      CacheMarshaller200 cm200 = new CacheMarshaller200();
+      c.setUseRegionBasedMarshalling(true);
+      cm200.injectDependencies(new RegionManager(), c);
+      cm200.init();
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(baos);
       cm200.objectToObjectStream("Hello World", oos, Fqn.fromString("/hello"));
@@ -80,7 +83,10 @@
 
       // first create a stream to unmarshall.
       RegionManager rm = new RegionManager();
-      final CacheMarshaller200 cm200 = new CacheMarshaller200(rm, false, true);
+      final CacheMarshaller200 cm200 = new CacheMarshaller200();
+      c.setUseRegionBasedMarshalling(true);
+      cm200.injectDependencies(new RegionManager(), c);
+      cm200.init();
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(baos);
       final Fqn region = Fqn.fromString("/hello");

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -8,6 +8,7 @@
 
 import org.jboss.cache.Fqn;
 import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -21,13 +22,23 @@
 {
    protected String currentVersion;
    protected int currentVersionShort;
-   protected Class expectedMarshallerClass;
+   protected Class expectedMarshallerClass, latestMarshallerClass = CacheMarshaller210.class;
    protected VersionAwareMarshaller marshaller;
+   protected RegionManager regionManager;
+   protected Configuration c;
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, currentVersion);
+      regionManager = new RegionManager();
+      c = new Configuration();
+      c.setUseRegionBasedMarshalling(false);
+      c.setInactiveOnStartup(false);
+      c.setReplVersionString(currentVersion);
+      marshaller = new VersionAwareMarshaller();
+      marshaller.injectDependencies(regionManager, c);
+      marshaller.init();
+      marshaller.initReplicationVersions();
    }
 
    @AfterMethod(alwaysRun = true)
@@ -88,13 +99,17 @@
       assertEquals("Only one marshaller should be in the map by this stage", 1, marshaller.marshallers.size());
 
       assertEquals(expectedMarshallerClass, marshaller.getMarshaller(currentVersionShort).getClass());
-      assertEquals(expectedMarshallerClass, marshaller.getMarshaller(15).getClass());
-      assertEquals(expectedMarshallerClass, marshaller.getMarshaller(1).getClass());
-      assertEquals(expectedMarshallerClass, marshaller.getMarshaller(-1).getClass());
-      assertEquals(expectedMarshallerClass, marshaller.getMarshaller(0).getClass());
+
+      // defaultMarshaller is used for outgoing streams
+      assert marshaller.defaultMarshaller.getClass().equals(expectedMarshallerClass);
+
+      assertEquals(latestMarshallerClass, marshaller.getMarshaller(15).getClass());
+      assertEquals(latestMarshallerClass, marshaller.getMarshaller(1).getClass());
+      assertEquals(latestMarshallerClass, marshaller.getMarshaller(-1).getClass());
+      assertEquals(latestMarshallerClass, marshaller.getMarshaller(0).getClass());
       assertEquals(CacheMarshaller200.class, marshaller.getMarshaller(20).getClass());
 
-      assertEquals("One marshaller should be in the map by this stage", 1, marshaller.marshallers.size());
+      assert marshaller.marshallers.size() == 2 : "Should have 2 marshallers now";
    }
 
    public void testStringBasedFqn() throws Exception
@@ -207,7 +222,8 @@
 
    public void testReplicationQueueWithRegionBasedMarshalling() throws Exception
    {
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, true, currentVersion);
+      c.setUseRegionBasedMarshalling(true);
+      marshaller.init();
       doReplicationQueueTest();
    }
 
@@ -219,12 +235,12 @@
       Fqn f = new Fqn<Object>("BlahBlah", 3, false);
       String k = "key", v = "value";
 
-      MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, f, k, v, true);
+      MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, f, k, v, true);
       MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, actualCall);
 
       calls.add(replicateCall);
 
-      actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, f, k, v, true);
+      actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, f, k, v, true);
       replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, actualCall);
 
       calls.add(replicateCall);

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -19,7 +19,7 @@
 @Test(groups = {"functional"})
 public class MethodIdPreservationTest
 {
-   private Marshaller m = new CacheMarshaller200(null, false, false);
+   private Marshaller m = new CacheMarshaller210();
    private ObjectOutputStream stream;
    private ByteArrayOutputStream byteStream;
    private MethodCall call1;
@@ -37,7 +37,7 @@
       list.clear();
       list.add(call1);
       list.add(call2);
-      prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, list, null, true);
+      prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, null, list, null, true);
    }
 
    public void testSingleMethodCall() throws Exception

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,8 +1,12 @@
 package org.jboss.cache.marshall;
 
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -21,17 +25,20 @@
 {
    private final Fqn DEFAULT_REGION = Fqn.ROOT;
    private RegionManager r;
+   private Configuration c;
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
-      r = new RegionManager();
+      CacheSPI cache = (CacheSPI) new DefaultCacheFactory().createCache();
+      r = cache.getRegionManager();
+      c = cache.getConfiguration();
    }
 
    @AfterMethod(alwaysRun = false)
    public void tearDown() throws Exception
    {
-      r.getCache().stop();
+      TestingUtil.killCaches(r.getCache());
       r = null;
    }
 
@@ -75,7 +82,7 @@
       assertFalse("Should not be expecting any more regions", expectedRegions.hasNext());
    }
 
-   public void testNoDefaultRegion()
+   public void testDefaultRegion()
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/");
@@ -83,17 +90,10 @@
       r.getRegion(fqn1, true);
       r.getRegion(fqn2, true);
 
-      Region region = null;
-      try
-      {
-         region = r.getRegion("/a", false);
-      }
-      catch (Exception e)
-      {
-         fail("If we don't setCache the default region, it still should be ok!");
-      }
+      Region region = r.getRegion("/a", false);
 
-      assertNull("Default region is not null!", region);
+      assertNotNull("Default region is not null!", region);
+      assert region.getFqn().equals(Fqn.ROOT) : "Should be the default region";
    }
 
 
@@ -120,28 +120,28 @@
       Region r2 = r.getRegion(fqn2, true);
       Region r3 = r.getRegion(fqn3, true);
 
-      assertEquals("Expecting 3 regions", 3, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 4 regions", 4, r.getAllRegions(Region.Type.ANY).size());
 
       // test that removal doesn't affect parent traversal.
       assertEquals(r3, r.getRegion(fqn3, false));
 
       r.removeRegion(Fqn.fromString(fqn3));
 
-      assertEquals("Expecting 2 regions", 2, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 3 regions", 3, r.getAllRegions(Region.Type.ANY).size());
 
       // test that removal doesn't affect parent traversal.
       assertEquals("Should have retrieved parent region", r2, r.getRegion(fqn3, false));
 
       r.removeRegion(Fqn.fromString(fqn2));
 
-      assertEquals("Expecting 1 region", 1, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 2 region", 2, r.getAllRegions(Region.Type.ANY).size());
 
       // test that removal doesn't affect parent traversal.
       assertEquals("Should have retrieved parent region", r1, r.getRegion(fqn3, false));
 
       r.removeRegion(Fqn.fromString(fqn1));
 
-      assertEquals("Expecting 0 regions", 0, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 1 regions (default region)", 1, r.getAllRegions(Region.Type.ANY).size());
    }
 
    public void testGetRegionsMethods()
@@ -153,7 +153,7 @@
       @SuppressWarnings("unused")
       Region r1 = r.getRegion(f1, true), r2 = r.getRegion(f2, true), r3 = r.getRegion(f3, true), r4 = r.getRegion(f4, true);
 
-      assertEquals("4 regions should exist", 4, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("5 regions should exist", 5, r.getAllRegions(Region.Type.ANY).size());
 
       assertEquals("None of the regions should marshalling or active", 0, r.getAllRegions(Region.Type.MARSHALLING).size());
 
@@ -186,40 +186,4 @@
       assertSame("r3 should be marshalling and active", r3, r.getAllRegions(Region.Type.MARSHALLING).get(1));
       assertSame("r4 should be marshalling and active", r4, r.getAllRegions(Region.Type.MARSHALLING).get(2));
    }
-/*
-   public void testUnspecifiedRegionType()
-   {
-      Fqn fqn = Fqn.fromString("/a/b/c");
-      Region region = r.getRegion(fqn, true);
-
-      assertNotNull(region);
-      assertEquals(fqn, region.getFqn());
-
-      region = r.getRegion(fqn, Region.Type.MARSHALLING, false);
-
-      assertNotNull(region);
-      assertEquals(fqn, region.getFqn());
-   }
-
-   public void testPreferenceForMarshallingRegion()
-   {
-      Fqn fqn = Fqn.fromString("/a/b/c");
-
-      Region region = r.getRegion(fqn, Region.Type.MARSHALLING, false);
-
-      assertNotNull(region);
-      assertEquals(Fqn.ROOT, region.getFqn());
-
-      region = r.getRegion(fqn, true);
-
-      assertNotNull(region);
-      assertEquals(fqn, region.getFqn());
-
-      region = r.getRegion(fqn, Region.Type.MARSHALLING, false);
-
-      assertNotNull(region);
-      assertEquals(fqn, region.getFqn());
-   }*/
-
-
 }

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -6,6 +6,7 @@
 import org.jboss.cache.Region;
 import org.jboss.cache.buddyreplication.GravitateResult;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -62,8 +63,7 @@
    @AfterMethod(alwaysRun = true)
    public void tearDown()
    {
-      cache1.stop();
-      cache2.stop();
+      TestingUtil.killCaches(cache1, cache2);
    }
 
    private ClassLoader getClassLoader()

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -8,10 +8,12 @@
 
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.Version;
+import org.jboss.cache.config.Configuration;
 import static org.testng.AssertJUnit.assertEquals;
 import org.testng.annotations.Test;
 
 import java.io.ObjectInputStream;
+
 /**
  * Tests the enhanced treecache marshaller
  *
@@ -22,37 +24,48 @@
 {
    public void testMarshallerSelection()
    {
-      VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.1.0.GA");
+      VersionAwareMarshaller marshaller = createAndConfigure("2.1.0.GA");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
+      marshaller = createAndConfigure("2.0.0.GA");
       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.4.0.GA");
+      marshaller = createAndConfigure("1.4.0.GA");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.5.0.GA");
+      marshaller = createAndConfigure("1.5.0.GA");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.0.GA");
+      marshaller = createAndConfigure("1.3.0.GA");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.0.SP2");
+      marshaller = createAndConfigure("1.3.0.SP2");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.1.GA");
+      marshaller = createAndConfigure("1.3.1.GA");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.2.4.SP2");
+      marshaller = createAndConfigure("1.2.4.SP2");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
 
-      marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.2.3");
+      marshaller = createAndConfigure("1.2.3");
       assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
    }
 
+   private VersionAwareMarshaller createAndConfigure(String replVersion)
+   {
+      Configuration c = new Configuration();
+      c.setReplVersionString(replVersion);
+      VersionAwareMarshaller vam = new VersionAwareMarshaller();
+      vam.injectDependencies(new RegionManager(), c);
+      vam.init();
+      vam.initReplicationVersions();
+      return vam;
+   }
+
    public void testVersionHeaderDefaultCurrent() throws Exception
    {
-      VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
+      VersionAwareMarshaller marshaller = createAndConfigure(Version.getVersionString(Version.getVersionShort()));
       byte[] bytes = marshaller.objectToByteBuffer("Hello");
 
       // expect that this has been serialized using JBoss Serialization so use this to get an OIS.
@@ -62,7 +75,7 @@
 
    public void testVersionHeader200() throws Exception
    {
-      VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
+      VersionAwareMarshaller marshaller = createAndConfigure("2.0.0.GA");
       byte[] bytes = marshaller.objectToByteBuffer("Hello");
 
       // expect that this has been serialized using JBoss Serialization so use this to get an OIS.

Modified: core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java	2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java	2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,7 +1,7 @@
 package org.jboss.cache.util.reflect;
 
-import org.jboss.cache.factories.CacheMarshallerFactory;
 import org.jboss.cache.factories.ComponentFactory;
+import org.jboss.cache.factories.EmptyConstructorFactory;
 import org.jboss.cache.factories.TransactionManagerFactory;
 import org.jboss.cache.factories.annotations.DefaultFactoryFor;
 import org.testng.annotations.Test;
@@ -22,6 +22,6 @@
 
       // should at least contain these 2.
       assert sc.contains(TransactionManagerFactory.class);
-      assert sc.contains(CacheMarshallerFactory.class);
+      assert sc.contains(EmptyConstructorFactory.class);
    }
 }




More information about the jbosscache-commits mailing list