[infinispan-commits] Infinispan SVN: r2032 - in branches/4.1.x: client/hotrod-client/src/test/java/org/infinispan/client/hotrod and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jul 14 06:28:12 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-07-14 06:28:12 -0400 (Wed, 14 Jul 2010)
New Revision: 2032

Added:
   branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java
Modified:
   branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
   branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java
   branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RoundRobinBalancingIntegrationTest.java
   branches/4.1.x/core/src/main/java/org/infinispan/marshall/Marshaller.java
   branches/4.1.x/core/src/main/java/org/infinispan/marshall/StreamingMarshaller.java
   branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
Log:
[ISPN-532] (HotRodMarshaller needs cleaning up) Fixed regressions

Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java	2010-07-14 10:08:09 UTC (rev 2031)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -12,7 +12,7 @@
 import org.infinispan.executors.ExecutorFactory;
 import org.infinispan.manager.CacheContainer;
 import org.infinispan.marshall.Marshaller;
-import org.infinispan.marshall.jboss.JBossMarshaller;
+import org.infinispan.marshall.jboss.GenericJBossMarshaller;
 import org.infinispan.util.TypedProperties;
 import org.infinispan.util.Util;
 import org.infinispan.util.logging.Log;
@@ -315,7 +315,7 @@
       if (marshaller == null) {
          String marshaller = props.getProperty("marshaller");
          if (marshaller == null) {
-            marshaller = JBossMarshaller.class.getName();
+            marshaller = GenericJBossMarshaller.class.getName();
             log.info("'marshaller' not specified, using " + marshaller);
          }
          setMarshaller((Marshaller) getInstance(marshaller));

Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java	2010-07-14 10:08:09 UTC (rev 2031)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/CSAIntegrationTest.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -8,6 +8,8 @@
 import org.infinispan.distribution.DistributionManager;
 import org.infinispan.lifecycle.ComponentStatus;
 import org.infinispan.manager.CacheContainer;
+import org.infinispan.marshall.Marshaller;
+import org.infinispan.marshall.jboss.GenericJBossMarshaller;
 import org.infinispan.server.hotrod.HotRodServer;
 import org.infinispan.test.TestingUtil;
 import org.infinispan.util.ByteArrayKey;
@@ -15,6 +17,8 @@
 import org.infinispan.util.logging.LogFactory;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
 import java.io.ByteArrayOutputStream;
@@ -45,6 +49,18 @@
 
    private static Log log = LogFactory.getLog(CSAIntegrationTest.class);
 
+   private Marshaller m;
+
+   @BeforeTest
+   public void createMarshaller() {
+      m = new GenericJBossMarshaller();
+   }
+
+   @AfterTest   
+   public void destroyMarshaller() {
+      m = null;
+   }
+
    @AfterMethod
    @Override
    protected void clearContent() throws Throwable {
@@ -140,7 +156,7 @@
          keys.add(key);
          String keyStr = new String(key);
          remoteCache.put(keyStr, "value");
-         byte[] keyBytes = toBytes(keyStr);
+         byte[] keyBytes = m.objectToByteBuffer(keyStr);
          TcpTransport transport = (TcpTransport) tcpConnectionFactory.getTransport(keyBytes);
          assertCacheContainsKey(transport.getServerAddress(), keyBytes);
          tcpConnectionFactory.releaseTransport(transport);
@@ -152,7 +168,7 @@
          resetStats();
          String keyStr = new String(key);
          assert remoteCache.get(keyStr).equals("value");
-         byte[] keyBytes = toBytes(keyStr);
+         byte[] keyBytes = m.objectToByteBuffer(keyStr);
          TcpTransport transport = (TcpTransport) tcpConnectionFactory.getTransport(keyBytes);
          assertOnlyServerHit(transport.getServerAddress());
          tcpConnectionFactory.releaseTransport(transport);
@@ -166,13 +182,6 @@
       assert dataContainer.keySet().contains(new ByteArrayKey(keyBytes));
    }
 
-   private byte[] toBytes(String keyStr) throws IOException {
-      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-      ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream);
-      oos.writeObject(keyStr);
-      return byteArrayOutputStream.toByteArray();
-   }
-
    private byte[] generateKey(int i) {
       Random r = new Random();
       byte[] result = new byte[i];

Modified: branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RoundRobinBalancingIntegrationTest.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RoundRobinBalancingIntegrationTest.java	2010-07-14 10:08:09 UTC (rev 2031)
+++ branches/4.1.x/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RoundRobinBalancingIntegrationTest.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -1,7 +1,6 @@
 package org.infinispan.client.hotrod;
 
 import org.infinispan.Cache;
-import org.infinispan.client.hotrod.exceptions.TransportException;
 import org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy;
 import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
 import org.infinispan.manager.EmbeddedCacheManager;
@@ -75,7 +74,7 @@
       hotRodServer4.stop();
    }
 
-   public void testRoundRubinLoadBalancing() {
+   public void testRoundRobinLoadBalancing() {
       remoteCache.put("k1", "v1");
       remoteCache.put("k2", "v2");
       remoteCache.put("k3", "v3");
@@ -100,7 +99,7 @@
       assertEquals(3, c3.size());
    }
 
-   @Test(dependsOnMethods = "testRoundRubinLoadBalancing")
+   @Test(dependsOnMethods = "testRoundRobinLoadBalancing")
    public void testAddNewHotrodServer() {
       c4 = TestCacheManagerFactory.createLocalCacheManager().getCache();
       hotRodServer4 = TestHelper.startHotRodServer((EmbeddedCacheManager) c4.getCacheManager());

Modified: branches/4.1.x/core/src/main/java/org/infinispan/marshall/Marshaller.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/Marshaller.java	2010-07-14 10:08:09 UTC (rev 2031)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/Marshaller.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -1,6 +1,7 @@
 package org.infinispan.marshall;
 
 import net.jcip.annotations.ThreadSafe;
+import org.infinispan.io.ByteBuffer;
 
 import java.io.IOException;
 
@@ -14,7 +15,7 @@
  * The interface is also used by the {@link org.infinispan.loaders.CacheStore} framework to efficiently serialize data
  * to be persisted, as well as the {@link org.infinispan.statetransfer.StateTransferManager} when serializing the cache
  * for transferring state en-masse.
- * <p />
+ * <p/>
  * A single instance of any implementation is shared by multiple threads, so implementations <i>need</i> to be threadsafe,
  * and preferably immutable.
  *
@@ -29,7 +30,7 @@
     * efficient sizing of the byte array before attempting to marshall the object.  The more accurate this estimate is,
     * the less likely byte[]s will need to be resized to hold the byte stream generated by marshalling the object.
     *
-    * @param obj object to convert to a byte array.  Must not be null.
+    * @param obj           object to convert to a byte array.  Must not be null.
     * @param estimatedSize an estimate of how large the resulting byte array may be
     * @return a byte array
     * @throws IOException
@@ -47,6 +48,7 @@
 
    /**
     * Unmarshalls an object from a byte array.
+    *
     * @param buf byte array containing the binary representation of an object.  Must not be null.
     * @return an object
     * @throws IOException
@@ -56,7 +58,8 @@
 
    /**
     * Unmarshalls an object from a specific portion of a byte array.
-    * @param buf byte array containing the binary representation of an object.  Must not be null.
+    *
+    * @param buf    byte array containing the binary representation of an object.  Must not be null.
     * @param offset point in buffer to start reading
     * @param length number of bytes to consider
     * @return an object
@@ -64,5 +67,15 @@
     * @throws ClassNotFoundException
     */
    Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException;
+
+   /**
+    * A method that returns an instance of {@link org.infinispan.io.ByteBuffer}, which allows direct access to the byte
+    * array with minimal array copying
+    *
+    * @param o object to marshall
+    * @return a ByteBuffer
+    * @throws Exception
+    */
+   ByteBuffer objectToBuffer(Object o) throws IOException;
 }
 

Modified: branches/4.1.x/core/src/main/java/org/infinispan/marshall/StreamingMarshaller.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/StreamingMarshaller.java	2010-07-14 10:08:09 UTC (rev 2031)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/StreamingMarshaller.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -125,15 +125,5 @@
     */
    Object objectFromObjectStream(ObjectInput in) throws IOException, ClassNotFoundException;
 
-   /**
-    * A method that returns an instance of {@link org.infinispan.io.ByteBuffer}, which allows direct access to the byte
-    * array with minimal array copying
-    *
-    * @param o object to marshall
-    * @return a ByteBuffer
-    * @throws Exception
-    */
-   ByteBuffer objectToBuffer(Object o) throws IOException;
-
    Object objectFromInputStream(InputStream is) throws IOException, ClassNotFoundException;
 }
\ No newline at end of file

Copied: branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java (from rev 2031, trunk/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java)
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java	                        (rev 0)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -0,0 +1,255 @@
+package org.infinispan.marshall.jboss;
+
+import org.infinispan.CacheException;
+import org.infinispan.io.ByteBuffer;
+import org.infinispan.io.ExposedByteArrayOutputStream;
+import org.infinispan.marshall.Marshaller;
+import org.infinispan.util.Util;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.jboss.marshalling.ContextClassResolver;
+import org.jboss.marshalling.ExceptionListener;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Marshalling;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.TraceInformation;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.marshalling.reflect.SunReflectiveCreator;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+
+/**
+ * A marshaller that makes use of <a href="http://www.jboss.org/jbossmarshalling">JBoss Marshalling</a> to serialize
+ * and deserialize objects.
+ * <p />
+ * In addition to making use of JBoss Marshalling, this Marshaller 
+ * @author Manik Surtani
+ * @version 4.1
+ * @see http://www.jboss.org/jbossmarshalling
+ */
+public class GenericJBossMarshaller implements Marshaller {
+
+   protected static final int DEFAULT_BUF_SIZE = 512;
+   protected static final Log log = LogFactory.getLog(JBossMarshaller.class);
+   protected static final String DEFAULT_MARSHALLER_FACTORY = "org.jboss.marshalling.river.RiverMarshallerFactory";
+   protected ClassLoader defaultCl = this.getClass().getClassLoader();
+   protected MarshallingConfiguration configuration;
+   protected MarshallerFactory factory;
+
+   public GenericJBossMarshaller() {
+      factory = (MarshallerFactory) Util.getInstance(DEFAULT_MARSHALLER_FACTORY);
+
+      configuration = new MarshallingConfiguration();
+      configuration.setCreator(new SunReflectiveCreator());
+      configuration.setExceptionListener(new DebuggingExceptionListener());
+      // ContextClassResolver provides same functionality as MarshalledValueInputStream
+      configuration.setClassResolver(new ContextClassResolver());
+      configuration.setVersion(2);
+
+   }
+
+   /**
+    * Marshaller thread local. JBossMarshaller is a singleton shared by all caches (global component), so no urgent need
+    * for static here. JBMAR clears pretty much any state during finish(), so no urgent need to clear the thread local
+    * since it shouldn't be leaking.
+    */
+   private ThreadLocal<org.jboss.marshalling.Marshaller> marshallerTL = new ThreadLocal<org.jboss.marshalling.Marshaller>() {
+      @Override
+      protected org.jboss.marshalling.Marshaller initialValue() {
+         try {
+            return factory.createMarshaller(configuration);
+         } catch (IOException e) {
+            throw new CacheException(e);
+         }
+      }
+   };
+
+   /**
+    * Unmarshaller thread local. JBossMarshaller is a singleton shared by all caches (global component), so no urgent
+    * need for static here. JBMAR clears pretty much any state during finish(), so no urgent need to clear the thread
+    * local since it shouldn't be leaking.
+    */
+   private ThreadLocal<Unmarshaller> unmarshallerTL = new ThreadLocal<Unmarshaller>() {
+      @Override
+      protected Unmarshaller initialValue() {
+         try {
+            return factory.createUnmarshaller(configuration);
+         } catch (IOException e) {
+            throw new CacheException(e);
+         }
+      }
+   };
+
+
+   public byte[] objectToByteBuffer(Object obj, int estimatedSize) throws IOException {
+      ByteBuffer b = objectToBuffer(obj, estimatedSize);
+      byte[] bytes = new byte[b.getLength()];
+      System.arraycopy(b.getBuf(), b.getOffset(), bytes, 0, b.getLength());
+      return bytes;
+   }
+
+   public ByteBuffer objectToBuffer(Object o) throws IOException {
+      return objectToBuffer(o, DEFAULT_BUF_SIZE);
+   }
+
+   public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException {
+      ClassLoader toUse = defaultCl;
+      Thread current = Thread.currentThread();
+      ClassLoader old = current.getContextClassLoader();
+      if (old != null) toUse = old;
+
+      try {
+         current.setContextClassLoader(toUse);
+         out.writeObject(obj);
+      }
+      finally {
+         current.setContextClassLoader(old);
+      }
+   }
+
+   private ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException {
+      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(estimatedSize);
+      ObjectOutput marshaller = startObjectOutput(baos, false);
+      try {
+         objectToObjectStream(o, marshaller);
+      } finally {
+         finishObjectOutput(marshaller);
+      }
+      return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
+   }
+
+   public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
+      org.jboss.marshalling.Marshaller marshaller;
+      if (isReentrant) {
+         marshaller = factory.createMarshaller(configuration);
+      } else {
+         marshaller = marshallerTL.get();
+      }
+      marshaller.start(Marshalling.createByteOutput(os));
+      return marshaller;
+   }
+
+   public void finishObjectOutput(ObjectOutput oo) {
+      try {
+         ((org.jboss.marshalling.Marshaller) oo).finish();
+      } catch (IOException ioe) {
+      }
+   }
+
+
+   public Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException {
+      return objectFromByteBuffer(buf, 0, buf.length);
+   }
+
+   public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException,
+           ClassNotFoundException {
+      ByteArrayInputStream is = new ByteArrayInputStream(buf, offset, length);
+      ObjectInput unmarshaller = startObjectInput(is, false);
+      Object o = null;
+      try {
+         o = objectFromObjectStream(unmarshaller);
+      } finally {
+         finishObjectInput(unmarshaller);
+      }
+      return o;
+   }
+
+   public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException {
+      Unmarshaller unmarshaller;
+      if (isReentrant) {
+         unmarshaller = factory.createUnmarshaller(configuration);
+      } else {
+         unmarshaller = unmarshallerTL.get();
+      }
+      unmarshaller.start(Marshalling.createByteInput(is));
+      return unmarshaller;
+   }
+
+   public Object objectFromObjectStream(ObjectInput in) throws IOException, ClassNotFoundException {
+      return in.readObject();
+   }   
+
+   public void finishObjectInput(ObjectInput oi) {
+      try {
+         if (oi != null) ((Unmarshaller) oi).finish();
+      } catch (IOException e) {
+      }
+   }
+
+   public Object objectFromInputStream(InputStream inputStream) throws IOException, ClassNotFoundException {
+      // TODO: available() call commented until https://issues.apache.org/jira/browse/HTTPCORE-199 httpcore-nio issue is fixed.
+      // int len = inputStream.available();
+      ExposedByteArrayOutputStream bytes = new ExposedByteArrayOutputStream(DEFAULT_BUF_SIZE);
+      byte[] buf = new byte[Math.min(DEFAULT_BUF_SIZE, 1024)];
+      int bytesRead;
+      while ((bytesRead = inputStream.read(buf, 0, buf.length)) != -1) bytes.write(buf, 0, bytesRead);
+      return objectFromByteBuffer(bytes.getRawBuffer(), 0, bytes.size());
+   }
+
+   public byte[] objectToByteBuffer(Object o) throws IOException {
+      return objectToByteBuffer(o, DEFAULT_BUF_SIZE);
+   }
+
+   protected static class DebuggingExceptionListener implements ExceptionListener {
+      private static final URL[] EMPTY_URLS = {};
+      private static final Class[] EMPTY_CLASSES = {};
+      private static final Object[] EMPTY_OBJECTS = {};
+
+      public void handleMarshallingException(Throwable problem, Object subject) {
+         if (log.isDebugEnabled()) {
+            TraceInformation.addUserInformation(problem, "toString = " + subject.toString());
+         }
+      }
+
+      public void handleUnmarshallingException(Throwable problem, Class<?> subjectClass) {
+         if (log.isDebugEnabled()) {
+            StringBuilder builder = new StringBuilder();
+            ClassLoader cl = subjectClass.getClassLoader();
+            builder.append("classloader hierarchy:");
+            ClassLoader parent = cl;
+            while (parent != null) {
+               if (parent.equals(cl)) {
+                  builder.append("\n\t\t-> type classloader = ").append(parent);
+               } else {
+                  builder.append("\n\t\t-> parent classloader = ").append(parent);
+               }
+               URL[] urls = getClassLoaderURLs(parent);
+
+               if (urls != null) {
+                  for (URL u : urls) builder.append("\n\t\t->...").append(u);
+               }
+
+               parent = parent.getParent();
+            }
+            TraceInformation.addUserInformation(problem, builder.toString());
+         }
+      }
+
+      public void handleUnmarshallingException(Throwable problem) {
+         // no-op
+      }
+
+      private static URL[] getClassLoaderURLs(ClassLoader cl) {
+         URL[] urls = EMPTY_URLS;
+         try {
+            Class returnType = urls.getClass();
+            Class[] parameterTypes = EMPTY_CLASSES;
+            Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
+            if (returnType.isAssignableFrom(getURLs.getReturnType())) {
+               Object[] args = EMPTY_OBJECTS;
+               urls = (URL[]) getURLs.invoke(cl, args);
+            }
+         } catch (Exception ignore) {
+         }
+         return urls;
+      }
+
+   }   
+}

Modified: branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java	2010-07-14 10:08:09 UTC (rev 2031)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java	2010-07-14 10:28:12 UTC (rev 2032)
@@ -49,6 +49,9 @@
 import java.net.URL;
 
 /**
+ * A specialized form of the {@link GenericJBossMarshaller}, making use of a custom object table for types internal to
+ * Infinispan.
+ * <p />
  * The reason why this is implemented specially in Infinispan rather than resorting to Java serialization or even the
  * more efficient JBoss serialization is that a lot of efficiency can be gained when a majority of the serialization
  * that occurs has to do with a small set of known types such as {@link org.infinispan.transaction.GlobalTransaction} or
@@ -60,59 +63,14 @@
  * @author Galder Zamarreño
  * @since 4.0
  */
-public class JBossMarshaller extends AbstractStreamingMarshaller {
-   private static final Log log = LogFactory.getLog(JBossMarshaller.class);
-   private static final String DEFAULT_MARSHALLER_FACTORY = "org.jboss.marshalling.river.RiverMarshallerFactory";
-   private ClassLoader defaultCl;
-   private MarshallingConfiguration configuration;
-   private MarshallerFactory factory;
+public class JBossMarshaller extends GenericJBossMarshaller implements StreamingMarshaller {   
    private ConstantObjectTable objectTable;
 
-   /**
-    * StreamingMarshaller thread local. JBossMarshaller is a singleton shared by all caches (global component), so no urgent need
-    * for static here. JBMAR clears pretty much any state during finish(), so no urgent need to clear the thread local
-    * since it shouldn't be leaking.
-    */
-   private ThreadLocal<org.jboss.marshalling.Marshaller> marshallerTL = new ThreadLocal<org.jboss.marshalling.Marshaller>() {
-      @Override
-      protected org.jboss.marshalling.Marshaller initialValue() {
-         try {
-            return factory.createMarshaller(configuration);
-         } catch (IOException e) {
-            throw new CacheException(e);
-         }
-      }
-   };
-
-   /**
-    * Unmarshaller thread local. JBossMarshaller is a singleton shared by all caches (global component), so no urgent
-    * need for static here. JBMAR clears pretty much any state during finish(), so no urgent need to clear the thread
-    * local since it shouldn't be leaking.
-    */
-   private ThreadLocal<Unmarshaller> unmarshallerTL = new ThreadLocal<Unmarshaller>() {
-      @Override
-      protected Unmarshaller initialValue() {
-         try {
-            return factory.createUnmarshaller(configuration);
-         } catch (IOException e) {
-            throw new CacheException(e);
-         }
-      }
-   };
-
    public void start(ClassLoader defaultCl, RemoteCommandsFactory cmdFactory, StreamingMarshaller ispnMarshaller) {
       if (log.isDebugEnabled()) log.debug("Using JBoss Marshalling");
       this.defaultCl = defaultCl;
-      factory = (MarshallerFactory) Util.getInstance(DEFAULT_MARSHALLER_FACTORY);
-
       objectTable = createCustomObjectTable(cmdFactory, ispnMarshaller);
-      configuration = new MarshallingConfiguration();
-      configuration.setCreator(new SunReflectiveCreator());
       configuration.setObjectTable(objectTable);
-      configuration.setExceptionListener(new DebuggingExceptionListener());
-      // ContextClassResolver provides same functionality as MarshalledValueInputStream
-      configuration.setClassResolver(new ContextClassResolver());
-      configuration.setVersion(2);
    }
 
    public void stop() {
@@ -121,159 +79,9 @@
       if (objectTable != null) objectTable.stop();
    }
 
-   public byte[] objectToByteBuffer(Object obj, int estimatedSize) throws IOException {
-      ByteBuffer b = objectToBuffer(obj, estimatedSize);
-      byte[] bytes = new byte[b.getLength()];
-      System.arraycopy(b.getBuf(), b.getOffset(), bytes, 0, b.getLength());
-      return bytes;
-   }
-
-   public ByteBuffer objectToBuffer(Object o) throws IOException {
-      return objectToBuffer(o, DEFAULT_BUF_SIZE);
-   }
-
-   private ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException {
-      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(estimatedSize);
-      ObjectOutput marshaller = startObjectOutput(baos, false);
-      try {
-         objectToObjectStream(o, marshaller);
-      } finally {
-         finishObjectOutput(marshaller);
-      }
-      return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
-   }
-
-   public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
-      org.jboss.marshalling.Marshaller marshaller;
-      if (isReentrant) {
-         marshaller = factory.createMarshaller(configuration);
-      } else {
-         marshaller = marshallerTL.get();
-      }
-      marshaller.start(Marshalling.createByteOutput(os));
-      return marshaller;
-   }
-
-   public void finishObjectOutput(ObjectOutput oo) {
-      try {
-         ((org.jboss.marshalling.Marshaller) oo).finish();
-      } catch (IOException ioe) {
-      }
-   }
-
-   public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException {
-      ClassLoader toUse = defaultCl;
-      Thread current = Thread.currentThread();
-      ClassLoader old = current.getContextClassLoader();
-      if (old != null) toUse = old;
-
-      try {
-         current.setContextClassLoader(toUse);
-         out.writeObject(obj);
-      }
-      finally {
-         current.setContextClassLoader(old);
-      }
-   }
-
-   public Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException {
-      return objectFromByteBuffer(buf, 0, buf.length);
-   }
-
-   public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException,
-           ClassNotFoundException {
-      ByteArrayInputStream is = new ByteArrayInputStream(buf, offset, length);
-      ObjectInput unmarshaller = startObjectInput(is, false);
-      Object o = null;
-      try {
-         o = objectFromObjectStream(unmarshaller);
-      } finally {
-         finishObjectInput(unmarshaller);
-      }
-      return o;
-   }
-
-   public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException {
-      Unmarshaller unmarshaller;
-      if (isReentrant) {
-         unmarshaller = factory.createUnmarshaller(configuration);
-      } else {
-         unmarshaller = unmarshallerTL.get();
-      }
-      unmarshaller.start(Marshalling.createByteInput(is));
-      return unmarshaller;
-   }
-
-   public void finishObjectInput(ObjectInput oi) {
-      try {
-         if (oi != null) ((Unmarshaller) oi).finish();
-      } catch (IOException e) {
-      }
-   }
-
-   public Object objectFromObjectStream(ObjectInput in) throws IOException, ClassNotFoundException {
-      return in.readObject();
-   }
-
    private ConstantObjectTable createCustomObjectTable(RemoteCommandsFactory cmdFactory, StreamingMarshaller ispnMarshaller) {
       ConstantObjectTable objectTable = new ConstantObjectTable();
       objectTable.start(cmdFactory, ispnMarshaller);
       return objectTable;
    }
-
-   private static class DebuggingExceptionListener implements ExceptionListener {
-      private static final URL[] EMPTY_URLS = {};
-      private static final Class[] EMPTY_CLASSES = {};
-      private static final Object[] EMPTY_OBJECTS = {};
-
-      public void handleMarshallingException(Throwable problem, Object subject) {
-         if (log.isDebugEnabled()) {
-            TraceInformation.addUserInformation(problem, "toString = " + subject.toString());
-         }
-      }
-
-      public void handleUnmarshallingException(Throwable problem, Class<?> subjectClass) {
-         if (log.isDebugEnabled()) {
-            StringBuilder builder = new StringBuilder();
-            ClassLoader cl = subjectClass.getClassLoader();
-            builder.append("classloader hierarchy:");
-            ClassLoader parent = cl;
-            while (parent != null) {
-               if (parent.equals(cl)) {
-                  builder.append("\n\t\t-> type classloader = ").append(parent);
-               } else {
-                  builder.append("\n\t\t-> parent classloader = ").append(parent);
-               }
-               URL[] urls = getClassLoaderURLs(parent);
-
-               if (urls != null) {
-                  for (URL u : urls) builder.append("\n\t\t->...").append(u);
-               }
-
-               parent = parent.getParent();
-            }
-            TraceInformation.addUserInformation(problem, builder.toString());
-         }
-      }
-
-      public void handleUnmarshallingException(Throwable problem) {
-         // no-op
-      }
-
-      private static URL[] getClassLoaderURLs(ClassLoader cl) {
-         URL[] urls = EMPTY_URLS;
-         try {
-            Class returnType = urls.getClass();
-            Class[] parameterTypes = EMPTY_CLASSES;
-            Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
-            if (returnType.isAssignableFrom(getURLs.getReturnType())) {
-               Object[] args = EMPTY_OBJECTS;
-               urls = (URL[]) getURLs.invoke(cl, args);
-            }
-         } catch (Exception ignore) {
-         }
-         return urls;
-      }
-
-   }
 }



More information about the infinispan-commits mailing list