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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Apr 17 10:35:16 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-17 10:35:16 -0400 (Thu, 17 Apr 2008)
New Revision: 5582

Removed:
   core/trunk/src/main/java/org/jboss/cache/marshall/io/
   core/trunk/src/test/java/org/jboss/cache/marshall/io/
Modified:
   core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
   core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
   core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
   core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java
   core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
   core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
Log:
JBCACHE-1325 - Removed use of reusable object streams

Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2008-04-16 17:39:19 UTC (rev 5581)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2008-04-17 14:35:16 UTC (rev 5582)
@@ -1,18 +1,17 @@
 package org.jboss.cache.factories;
 
 import org.jboss.cache.RegionManager;
-import org.jboss.cache.lock.LockManager;
 import org.jboss.cache.commands.CommandsFactory;
 import org.jboss.cache.config.ConfigurationException;
 import org.jboss.cache.factories.annotations.DefaultFactoryFor;
-import org.jboss.cache.invocation.InvocationContextContainer;
-import org.jboss.cache.invocation.CacheInvocationDelegate;
 import org.jboss.cache.invocation.CacheData;
+import org.jboss.cache.invocation.CacheInvocationDelegate;
 import org.jboss.cache.invocation.CacheTransactionHelper;
+import org.jboss.cache.invocation.InvocationContextContainer;
 import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.lock.LockManager;
 import org.jboss.cache.marshall.Marshaller;
 import org.jboss.cache.marshall.VersionAwareMarshaller;
-import org.jboss.cache.marshall.io.ObjectStreamPool;
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.remoting.jgroups.CacheMessageListener;
 import org.jboss.cache.statetransfer.StateTransferManager;
@@ -26,7 +25,7 @@
  */
 @DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class,
       CacheMessageListener.class, CacheLoaderManager.class, Marshaller.class,
-      InvocationContextContainer.class, ObjectStreamPool.class, CacheInvocationDelegate.class,
+      InvocationContextContainer.class, CacheInvocationDelegate.class,
       CacheTransactionHelper.class, CacheData.class, CommandsFactory.class, LockManager.class})
 public class EmptyConstructorFactory extends ComponentFactory
 {

Modified: core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java	2008-04-16 17:39:19 UTC (rev 5581)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java	2008-04-17 14:35:16 UTC (rev 5582)
@@ -705,7 +705,7 @@
 
    protected byte[] marshall(Object obj) throws Exception
    {
-      return getMarshaller().objectToByteBuffer(obj, true);
+      return getMarshaller().objectToByteBuffer(obj);
    }
 
    private static String toUpperCase(String s)

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java	2008-04-16 17:39:19 UTC (rev 5581)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java	2008-04-17 14:35:16 UTC (rev 5582)
@@ -12,14 +12,20 @@
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.commands.remote.RemoteExistsNodeCommand;
-import org.jboss.cache.commands.cachedata.*;
+import org.jboss.cache.commands.cachedata.CacheDataCommand;
+import org.jboss.cache.commands.cachedata.EvictNodeCommand;
+import org.jboss.cache.commands.cachedata.GetChildrenNamesCommand;
+import org.jboss.cache.commands.cachedata.GetDataMapCommand;
+import org.jboss.cache.commands.cachedata.GetKeyValueCommand;
+import org.jboss.cache.commands.cachedata.GetKeysCommand;
+import org.jboss.cache.commands.cachedata.InvalidateCommand;
 import org.jboss.cache.commands.functional.MarshallableCommand;
 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.GravitateDataCommand;
+import org.jboss.cache.commands.remote.RemoteExistsNodeCommand;
 import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
 import org.jboss.cache.commands.remote.ReplicateCommand;
 import org.jboss.cache.commands.state.GlobalTransactionCommand;
@@ -84,11 +90,6 @@
    // implement the basic contract set in RPcDispatcher.AbstractMarshaller
    public byte[] objectToByteBuffer(Object obj) throws Exception
    {
-      return objectToByteBuffer(obj, false);
-   }
-
-   public byte[] objectToByteBuffer(Object obj, boolean b) throws Exception
-   {
       throw new RuntimeException("Needs to be overridden!");
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java	2008-04-16 17:39:19 UTC (rev 5581)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java	2008-04-17 14:35:16 UTC (rev 5582)
@@ -70,16 +70,6 @@
    void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn region) throws Exception;
 
    /**
-    * Same as {@link #objectToByteBuffer(Object)} except that you can optionally specify to write object stream headers.
-    * Useful if you intend to deserialize the stream with non-pooled input streams.
-    *
-    * @param o
-    * @param writeStreamHeaders
-    * @return
-    */
-   byte[] objectToByteBuffer(Object o, boolean writeStreamHeaders) throws Exception;
-
-   /**
     * Returns a RegionalizedMethodCall from a byte buffer.  Only use if you <i>know</i> that the byte buffer contains a
     * MethodCall and that you are using region-based marshalling, otherwise use {@link #objectFromByteBuffer(byte[])}
     *

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java	2008-04-16 17:39:19 UTC (rev 5581)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java	2008-04-17 14:35:16 UTC (rev 5582)
@@ -12,8 +12,6 @@
 import org.jboss.cache.factories.ComponentRegistry;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.marshall.io.ObjectStreamPool;
-import org.jboss.cache.marshall.io.ReusableObjectOutputStream;
 import org.jboss.cache.util.Util;
 import org.jboss.util.stream.MarshalledValueInputStream;
 
@@ -48,13 +46,11 @@
    Marshaller defaultMarshaller;
    Map<Integer, Marshaller> marshallers = new HashMap<Integer, Marshaller>();
    private int versionInt;
-   ObjectStreamPool pool;
 
    @Inject
-   void injectComponents(ComponentRegistry componentRegistry, ObjectStreamPool pool)
+   void injectComponents(ComponentRegistry componentRegistry)
    {
       this.componentRegistry = componentRegistry;
-      this.pool = pool;
    }
 
    @Start
@@ -153,7 +149,8 @@
       }
    }
 
-   private byte[] useNonPooledStream(Object obj) throws Exception
+   @Override
+   public byte[] objectToByteBuffer(Object obj) throws Exception
    {
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutputStream out = new ObjectOutputStream(baos);
@@ -170,57 +167,26 @@
    }
 
    @Override
-   public byte[] objectToByteBuffer(Object obj, boolean writeHeader) throws Exception
-   {
-      if (writeHeader) return useNonPooledStream(obj);
-
-      ReusableObjectOutputStream out = pool.getOutputStream();
-
-      try
-      {
-         out.writeShort(versionInt);
-         if (trace) log.trace("Wrote version " + versionInt);
-
-         //now marshall the contents of the object
-         defaultMarshaller.objectToObjectStream(obj, out);
-
-         // and return bytes.
-         return out.getBytes();
-      }
-      finally
-      {
-         pool.returnStreamToPool(out);
-      }
-   }
-
-   @Override
    public Object objectFromByteBuffer(byte[] buf) throws Exception
    {
       Marshaller marshaller;
       int versionId;
-      ObjectInputStream in = pool.getInputStream(buf);
+      ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(buf));
 
       try
       {
-         try
-         {
-            versionId = in.readShort();
-            if (trace) log.trace("Read version " + versionId);
-         }
-         catch (Exception e)
-         {
-            log.error("Unable to read version id from first two bytes of stream, barfing.");
-            throw e;
-         }
-
-         marshaller = getMarshaller(versionId);
-
-         return marshaller.objectFromObjectStream(in);
+         versionId = in.readShort();
+         if (trace) log.trace("Read version " + versionId);
       }
-      finally
+      catch (Exception e)
       {
-         pool.returnStreamToPool(in);
+         log.error("Unable to read version id from first two bytes of stream, barfing.");
+         throw e;
       }
+
+      marshaller = getMarshaller(versionId);
+
+      return marshaller.objectFromObjectStream(in);
    }
 
    @Override
@@ -228,29 +194,22 @@
    {
       Marshaller marshaller;
       int versionId;
-      ObjectInputStream in = pool.getInputStream(buf);
+      ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(buf));
 
       try
       {
-         try
-         {
-            versionId = in.readShort();
-            if (trace) log.trace("Read version " + versionId);
-         }
-         catch (Exception e)
-         {
-            log.error("Unable to read version id from first two bytes of stream, barfing.");
-            throw e;
-         }
-
-         marshaller = getMarshaller(versionId);
-
-         return marshaller.regionalizedMethodCallFromObjectStream(in);
+         versionId = in.readShort();
+         if (trace) log.trace("Read version " + versionId);
       }
-      finally
+      catch (Exception e)
       {
-         pool.returnStreamToPool(in);
+         log.error("Unable to read version id from first two bytes of stream, barfing.");
+         throw e;
       }
+
+      marshaller = getMarshaller(versionId);
+
+      return marshaller.regionalizedMethodCallFromObjectStream(in);
    }
 
    @Override

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java	2008-04-16 17:39:19 UTC (rev 5581)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java	2008-04-17 14:35:16 UTC (rev 5582)
@@ -9,13 +9,13 @@
 import org.jboss.cache.Version;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.ComponentRegistry;
-import org.jboss.cache.marshall.io.ObjectStreamPool;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.util.stream.MarshalledValueInputStream;
 import static org.testng.AssertJUnit.assertEquals;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import java.io.ByteArrayInputStream;
 import java.io.ObjectInputStream;
 
 /**
@@ -76,8 +76,7 @@
       VersionAwareMarshaller marshaller = createVAMandRestartCache(Version.getVersionString(Version.getVersionShort()));
 
       byte[] bytes = marshaller.objectToByteBuffer("Hello");
-      ObjectStreamPool pool = (ObjectStreamPool) TestingUtil.extractField(marshaller, "pool");
-      ObjectInputStream in = pool.getInputStream(bytes);
+      ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(bytes));
       assertEquals("Version header short should be '22'", 22, in.readShort());
    }
 
@@ -86,8 +85,7 @@
       VersionAwareMarshaller marshaller = createVAMandRestartCache("2.1.0.GA");
 
       byte[] bytes = marshaller.objectToByteBuffer("Hello");
-      ObjectStreamPool pool = (ObjectStreamPool) TestingUtil.extractField(marshaller, "pool");
-      ObjectInputStream in = pool.getInputStream(bytes);
+      ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(bytes));
       assertEquals("Version header short should be '21'", 21, in.readShort());
    }
 
@@ -96,8 +94,7 @@
       VersionAwareMarshaller marshaller = createVAMandRestartCache("2.0.0.GA");
 
       byte[] bytes = marshaller.objectToByteBuffer("Hello");
-      ObjectStreamPool pool = (ObjectStreamPool) TestingUtil.extractField(marshaller, "pool");
-      ObjectInputStream in = pool.getInputStream(bytes);
+      ObjectInputStream in = new MarshalledValueInputStream(new ByteArrayInputStream(bytes));
       assertEquals("Version header short should be '20'", 20, in.readShort());
    }
 }




More information about the jbosscache-commits mailing list