[infinispan-commits] Infinispan SVN: r2113 - in branches/4.1.x: core/src/main/java/org/infinispan/marshall/jboss and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Jul 28 02:50:41 EDT 2010
Author: galder.zamarreno at jboss.com
Date: 2010-07-28 02:50:40 -0400 (Wed, 28 Jul 2010)
New Revision: 2113
Added:
branches/4.1.x/core/src/test/java/org/infinispan/marshall/MarshalledValueSingleNodeTest.java
branches/4.1.x/tree/src/test/java/org/infinispan/api/tree/LazyDeserializationTreeCacheTest.java
Modified:
branches/4.1.x/core/src/main/java/org/infinispan/marshall/MarshalledValue.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/VersionAwareMarshaller.java
branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java
branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
branches/4.1.x/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java
branches/4.1.x/tree/
Log:
[ISPN-552] (Tree facade caches cannot be configured with lazy deserialization) Replaced MarshalledValue serializable check with a more flexible Marshaller.isMarshallable() call.
Modified: branches/4.1.x/core/src/main/java/org/infinispan/marshall/MarshalledValue.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/MarshalledValue.java 2010-07-28 06:23:30 UTC (rev 2112)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/MarshalledValue.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -61,10 +61,11 @@
public MarshalledValue(Object instance, boolean equalityPreferenceForInstance, StreamingMarshaller marshaller) throws NotSerializableException {
if (instance == null) throw new NullPointerException("Null values cannot be wrapped as MarshalledValues!");
- if (instance instanceof Serializable)
+ if (marshaller.isMarshallable(instance))
this.instance = instance;
else
- throw new NotSerializableException("Marshalled values can only wrap Objects that are serializable! Instance of " + instance.getClass() + " won't Serialize.");
+ throw new NotSerializableException("Marshalled values can only wrap Objects that can be serialized or marshalled! Instance of "
+ + instance.getClass() + " won't serialize or marshall.");
this.equalityPreferenceForInstance = equalityPreferenceForInstance;
this.marshaller = marshaller;
}
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-28 06:23:30 UTC (rev 2112)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/Marshaller.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -77,5 +77,13 @@
* @throws Exception
*/
ByteBuffer objectToBuffer(Object o) throws IOException;
+
+ /**
+ * A method that checks whether the given object is marshallable as per the rules of this marshaller.
+ *
+ * @param o object to verify whether it's marshallable or not
+ * @return true if the object is marshallable, otherwise false
+ */
+ boolean isMarshallable(Object o);
}
Modified: branches/4.1.x/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java 2010-07-28 06:23:30 UTC (rev 2112)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -187,4 +187,9 @@
public Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException {
return objectFromByteBuffer(buf, 0, buf.length);
}
+
+ @Override
+ public boolean isMarshallable(Object o) {
+ return defaultMarshaller.isMarshallable(o);
+ }
}
\ No newline at end of file
Modified: branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java 2010-07-28 06:23:30 UTC (rev 2112)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/GenericJBossMarshaller.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -17,11 +17,13 @@
import org.jboss.marshalling.reflect.SunReflectiveCreator;
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.OutputStream;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.net.URL;
@@ -197,6 +199,11 @@
return objectToByteBuffer(o, DEFAULT_BUF_SIZE);
}
+ @Override
+ public boolean isMarshallable(Object o) {
+ return (o instanceof Serializable || o instanceof Externalizable);
+ }
+
protected static class DebuggingExceptionListener implements ExceptionListener {
private static final URL[] EMPTY_URLS = {};
private static final Class[] EMPTY_CLASSES = {};
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-28 06:23:30 UTC (rev 2112)
+++ branches/4.1.x/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -26,7 +26,9 @@
import org.infinispan.io.ByteBuffer;
import org.infinispan.io.ExposedByteArrayOutputStream;
import org.infinispan.marshall.AbstractStreamingMarshaller;
+import org.infinispan.marshall.Marshallable;
import org.infinispan.marshall.StreamingMarshaller;
+import org.infinispan.util.ReflectionUtil;
import org.infinispan.util.Util;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
@@ -54,7 +56,7 @@
* <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
+ * that occurs has to do with a small set of known types such as {@link org.infinispan.transaction.xa.GlobalTransaction} or
* {@link org.infinispan.commands.ReplicableCommand}, and class type information can be replaced with simple magic
* numbers.
* <p/>
@@ -79,6 +81,11 @@
if (objectTable != null) objectTable.stop();
}
+ @Override
+ public boolean isMarshallable(Object o) {
+ return super.isMarshallable(o) || ReflectionUtil.isAnnotationPresent(o.getClass(), Marshallable.class);
+ }
+
private ConstantObjectTable createCustomObjectTable(RemoteCommandsFactory cmdFactory, StreamingMarshaller ispnMarshaller) {
ConstantObjectTable objectTable = new ConstantObjectTable();
objectTable.start(cmdFactory, ispnMarshaller);
Added: branches/4.1.x/core/src/test/java/org/infinispan/marshall/MarshalledValueSingleNodeTest.java
===================================================================
--- branches/4.1.x/core/src/test/java/org/infinispan/marshall/MarshalledValueSingleNodeTest.java (rev 0)
+++ branches/4.1.x/core/src/test/java/org/infinispan/marshall/MarshalledValueSingleNodeTest.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -0,0 +1,48 @@
+package org.infinispan.marshall;
+
+import org.infinispan.CacheException;
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Galder Zamarreño
+ * @since 4.1
+ */
+ at Test(groups = "functional", testName = "marshall.MarshalledValueSingleNodeTest")
+public class MarshalledValueSingleNodeTest extends SingleCacheManagerTest {
+
+ @Override
+ protected EmbeddedCacheManager createCacheManager() throws Exception {
+ // start a single cache instance
+ Configuration c = getDefaultStandaloneConfig(true);
+ c.setInvocationBatchingEnabled(true);
+ c.setUseLazyDeserialization(true);
+ EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(c, true);
+ cache = cm.getCache();
+ return cm;
+ }
+
+ public void testNonSerializable() {
+ try {
+ cache.put("Hello", new Object());
+ assert false : "Should have failed";
+ }
+ catch (CacheException expected) {
+ System.out.println("");
+ }
+
+ try {
+ cache.put(new Object(), "Hello");
+ assert false : "Should have failed";
+ }
+ catch (CacheException expected) {
+
+ }
+ }
+
+}
Modified: branches/4.1.x/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java
===================================================================
--- branches/4.1.x/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java 2010-07-28 06:23:30 UTC (rev 2112)
+++ branches/4.1.x/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -5,15 +5,7 @@
import org.infinispan.io.ExposedByteArrayOutputStream;
import org.infinispan.util.Util;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
+import java.io.*;
/**
* A dummy marshaller impl that uses object streams converted via XStream as current JBoss Marshalling implementation
@@ -90,6 +82,11 @@
return objectFromObjectStream(new ObjectInputStream(new ByteArrayInputStream(buf)));
}
+ @Override
+ public boolean isMarshallable(Object o) {
+ return (o instanceof Serializable || o instanceof Externalizable);
+ }
+
private void debug(String s) {
if (debugXml) {
System.out.println("TestObjectStreamMarshaller: " + s);
Property changes on: branches/4.1.x/tree
___________________________________________________________________
Name: svn:ignore
- target
.settings
eclipse-output
test-output
output
.classpath
.project
temp-testng-customsuite.xml
+ target
.settings
eclipse-output
test-output
output
.classpath
.project
temp-testng-customsuite.xml
*.iml
*.log
Added: branches/4.1.x/tree/src/test/java/org/infinispan/api/tree/LazyDeserializationTreeCacheTest.java
===================================================================
--- branches/4.1.x/tree/src/test/java/org/infinispan/api/tree/LazyDeserializationTreeCacheTest.java (rev 0)
+++ branches/4.1.x/tree/src/test/java/org/infinispan/api/tree/LazyDeserializationTreeCacheTest.java 2010-07-28 06:50:40 UTC (rev 2113)
@@ -0,0 +1,36 @@
+package org.infinispan.api.tree;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.tree.TreeCache;
+import org.infinispan.tree.TreeCacheImpl;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Galder Zamarreño
+ * @since 4.1
+ */
+ at Test(groups = "functional", testName = "api.tree.LazyDeserializationTreeCacheTest")
+public class LazyDeserializationTreeCacheTest extends SingleCacheManagerTest {
+
+ TreeCache cache;
+
+ @Override
+ protected EmbeddedCacheManager createCacheManager() throws Exception {
+ // start a single cache instance
+ Configuration c = getDefaultStandaloneConfig(true);
+ c.setInvocationBatchingEnabled(true);
+ c.setUseLazyDeserialization(true);
+ return TestCacheManagerFactory.createCacheManager(c, true);
+ }
+
+ public void testStartTreeCache() {
+ cache = new TreeCacheImpl(cacheManager.getCache());
+ }
+
+}
More information about the infinispan-commits
mailing list