[infinispan-commits] Infinispan SVN: r414 - in trunk/core/src: main/java/org/infinispan/marshall and 5 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Jun 4 11:52:55 EDT 2009
Author: galder.zamarreno at jboss.com
Date: 2009-06-04 11:52:55 -0400 (Thu, 04 Jun 2009)
New Revision: 414
Modified:
trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java
trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java
trunk/core/src/main/java/org/infinispan/marshall/Marshaller.java
trunk/core/src/main/java/org/infinispan/marshall/MarshallerImpl.java
trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java
trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java
trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
trunk/core/src/main/java/org/infinispan/marshall/jboss/externalizers/MarshalledValueExternalizer.java
trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java
trunk/core/src/test/java/org/infinispan/marshall/MarshallersTest.java
trunk/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java
trunk/core/src/test/java/org/infinispan/marshall/jboss/JBossMarshallerTest.java
Log:
[ISPN-79] (MarshalledValue.serialize/deserialize should be using Marshaller, not JDK classes) Done by enhancing marshallers so that they can handle reentrant calls in a different way.
Modified: trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/interceptors/MarshalledValueInterceptor.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -26,8 +26,10 @@
import org.infinispan.commands.write.PutMapCommand;
import org.infinispan.commands.write.RemoveCommand;
import org.infinispan.context.InvocationContext;
+import org.infinispan.factories.annotations.Inject;
import org.infinispan.interceptors.base.CommandInterceptor;
import org.infinispan.marshall.MarshalledValue;
+import org.infinispan.marshall.Marshaller;
import java.io.IOException;
import java.io.NotSerializableException;
@@ -47,10 +49,18 @@
*
* @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
* @author Mircea.Markus at jboss.com
+ * @author Galder Zamarreño
* @see org.infinispan.marshall.MarshalledValue
* @since 4.0
*/
public class MarshalledValueInterceptor extends CommandInterceptor {
+ private Marshaller marshaller;
+
+ @Inject
+ protected void injectMarshaller(Marshaller marshaller) {
+ this.marshaller = marshaller;
+ }
+
@Override
public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable {
Set<MarshalledValue> marshalledValues = new HashSet<MarshalledValue>();
@@ -144,6 +154,6 @@
}
protected MarshalledValue createMarshalledValue(Object toWrap, InvocationContext ctx) throws NotSerializableException {
- return new MarshalledValue(toWrap, ctx.isOriginLocal());
+ return new MarshalledValue(toWrap, ctx.isOriginLocal(), marshaller);
}
}
Modified: trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/MarshalledValue.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -23,16 +23,12 @@
import org.infinispan.CacheException;
import org.infinispan.commands.ReplicableCommand;
+import org.infinispan.io.ExposedByteArrayOutputStream;
import org.infinispan.remoting.transport.Address;
import org.infinispan.transaction.xa.GlobalTransaction;
-import org.jboss.util.stream.MarshalledValueInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.NotSerializableException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.Arrays;
@@ -45,6 +41,7 @@
*
* @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
* @author Mircea.Markus at jboss.com
+ * @author Galder Zamarreño
* @see org.infinispan.interceptors.MarshalledValueInterceptor
* @since 4.0
*/
@@ -54,8 +51,9 @@
private int cachedHashCode = 0;
// by default equals() will test on the istance rather than the byte array if conversion is required.
private transient boolean equalityPreferenceForInstance = true;
+ private final Marshaller marshaller;
- public MarshalledValue(Object instance, boolean equalityPreferenceForInstance) throws NotSerializableException {
+ public MarshalledValue(Object instance, boolean equalityPreferenceForInstance, Marshaller marshaller) throws NotSerializableException {
if (instance == null) throw new NullPointerException("Null values cannot be wrapped as MarshalledValues!");
if (instance instanceof Serializable)
@@ -63,13 +61,12 @@
else
throw new NotSerializableException("Marshalled values can only wrap Objects that are serializable! Instance of " + instance.getClass() + " won't Serialize.");
this.equalityPreferenceForInstance = equalityPreferenceForInstance;
+ this.marshaller = marshaller;
}
- public MarshalledValue() {
- }
-
- public MarshalledValue(byte[] raw, int cachedHashCode) {
+ public MarshalledValue(byte[] raw, int cachedHashCode, Marshaller marshaller) {
init(raw, cachedHashCode);
+ this.marshaller = marshaller;
}
public void init(byte[] raw, int cachedHashCode) {
@@ -81,17 +78,20 @@
public synchronized void serialize() {
if (raw == null) {
try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(instance);
- oos.close();
- baos.close();
// Do NOT set instance to null over here, since it may be used elsewhere (e.g., in a cache listener).
// this will be compacted by the MarshalledValueInterceptor when the call returns.
- raw = baos.toByteArray();
- }
- catch (Exception e) {
+ ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(128);
+ ObjectOutput out = marshaller.startObjectOutput(baos, true);
+ try {
+ marshaller.objectToObjectStream(instance, out);
+ } finally {
+ marshaller.finishObjectOutput(out);
+ }
+ raw = baos.getRawBuffer();
+ } catch (Exception e) {
throw new CacheException("Unable to marshall value " + instance, e);
+ } finally {
+
}
}
}
@@ -99,12 +99,8 @@
public synchronized void deserialize() {
if (instance == null) {
try {
- ByteArrayInputStream bais = new ByteArrayInputStream(raw);
- // use a MarshalledValueInputStream since it needs to be aware of any context class loaders on the current thread.
- ObjectInputStream ois = new MarshalledValueInputStream(bais);
- instance = ois.readObject();
- ois.close();
- bais.close();
+ // Marshaller underneath deals with making sure the right classloader is set.
+ instance = marshaller.objectFromByteBuffer(raw);
}
catch (Exception e) {
throw new CacheException("Unable to unmarshall value", e);
@@ -159,7 +155,7 @@
*
* @see #nullifyInstance()
*/
- public synchronized Object get() throws IOException, ClassNotFoundException {
+ public synchronized Object get() {
if (instance == null) deserialize();
return instance;
}
Modified: trunk/core/src/main/java/org/infinispan/marshall/Marshaller.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/Marshaller.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/Marshaller.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -61,14 +61,31 @@
public interface Marshaller {
/**
- * Create and open a new ObjectOutput for the given output stream. This method should be used for opening data outpus
- * when multiple objectToObjectStream() calls will be made before the stream is closed
+ * <p>Create and open an ObjectOutput instance for the given output stream. This method should be used for opening data
+ * outputs when multiple objectToObjectStream() calls will be made before the stream is closed by calling finishObjectOutput().</p>
+ *
+ * <p>This method also takes a boolean that represents whether this particular call to startObjectOutput() is reentrant
+ * or not. A call to startObjectOutput() should be marked reentrant whenever a 2nd or more calls to this method are made
+ * without having called finishObjectOutput() first.
+ *
+ * <p>To potentially speed up calling startObjectOutput multiple times in a non-reentrant way, i.e.
+ * startObjectOutput/finishObjectOutput...startObjectOutput/finishObjectOutput...etc, which is is the most common case, the
+ * Marshaller implementation could potentially use some mechanisms to speed up this startObjectOutput call.
+ *
+ * <p>On the other hand, when a call is reentrant, i.e. startObjectOutput/startObjectOutput(reentrant)...finishObjectOutput/finishObjectOutput,
+ * the Marshaller implementation might treat it differently. An example of reentrancy would be marshalling of {@link MarshalledValue}.
+ * When sending or storing a MarshalledValue, a call to startObjectOutput() would occur so that the stream is open and
+ * following, a 2nd call could occur so that MarshalledValue's raw byte array version is calculated and sent accross.
+ * This enables lazy deserialization on the receiver side which is performance gain. The Marshaller implementation could decide
+ * that it needs a separate ObjectOutput or similar for the 2nd call since it's aim is only to get the raw byte array version
+ * and the close finish with it.</p>
*
* @param os output stream
+ * @param isReentrant whether the call is reentrant or not.
* @return ObjectOutput to write to
* @throws IOException
*/
- ObjectOutput startObjectOutput(OutputStream os) throws IOException;
+ ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException;
/**
* Finish using the given ObjectOutput. After opening a ObjectOutput and calling objectToObjectStream() mutliple
@@ -87,14 +104,23 @@
void objectToObjectStream(Object obj, ObjectOutput out) throws IOException;
/**
- * Create and open a new ObjectInput for the given input stream. This method should be used for opening data inputs
- * when multiple objectFromObjectStream() calls will be made before the stream is closed.
- *
+ * <p>Create and open a new ObjectInput for the given input stream. This method should be used for opening data inputs
+ * when multiple objectFromObjectStream() calls will be made before the stream is closed.</p>
+ *
+ * <p>This method also takes a boolean that represents whether this particular call to startObjectInput() is reentrant
+ * or not. A call to startObjectInput() should be marked reentrant whenever a 2nd or more calls to this method are made
+ * without having called finishObjectInput() first.</p>
+ *
+ * <p>To potentially speed up calling startObjectInput multiple times in a non-reentrant way, i.e.
+ * startObjectInput/finishObjectInput...startObjectInput/finishObjectInput...etc, which is is the most common case, the
+ * Marshaller implementation could potentially use some mechanisms to speed up this startObjectInput call.</p>
+ *
* @param is input stream
+ * @param isReentrant whether the call is reentrant or not.
* @return ObjectInput to read from
* @throws IOException
*/
- ObjectInput startObjectInput(InputStream is) throws IOException;
+ ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException;
/**
* Finish using the given ObjectInput. After opening a ObjectInput and calling objectFromObjectStream() mutliple
Modified: trunk/core/src/main/java/org/infinispan/marshall/MarshallerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/MarshallerImpl.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/MarshallerImpl.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -552,7 +552,7 @@
byte[] raw = new byte[sz];
in.readFully(raw);
int hc = in.readInt();
- return new MarshalledValue(raw, hc);
+ return new MarshalledValue(raw, hc, this);
}
private Bucket unmarshallBucket(ObjectInput input, UnmarshalledReferences references) throws IOException, ClassNotFoundException {
@@ -927,7 +927,7 @@
c.equals(Double.class));
}
- public ObjectOutput startObjectOutput(OutputStream os) throws IOException {
+ public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
return new ObjectOutputStream(os);
}
@@ -951,7 +951,7 @@
}
}
- public ObjectInput startObjectInput(InputStream is) throws IOException {
+ public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException {
return new ObjectInputStream(is);
}
Modified: trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -53,14 +53,15 @@
private static final int VERSION_400 = 400;
private static final int CUSTOM_MARSHALLER = 999;
- private JBossMarshaller defaultMarshaller;
+ private final JBossMarshaller defaultMarshaller;
- ClassLoader defaultClassLoader;
+ public VersionAwareMarshaller() {
+ defaultMarshaller = new JBossMarshaller();
+ }
@Inject
public void init(ClassLoader loader, RemoteCommandFactory remoteCommandFactory) {
- defaultMarshaller = new JBossMarshaller();
- defaultMarshaller.init(loader, remoteCommandFactory);
+ defaultMarshaller.init(loader, remoteCommandFactory, this);
}
@Stop
@@ -74,7 +75,7 @@
public ByteBuffer objectToBuffer(Object obj) throws IOException {
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(128);
- ObjectOutput out = startObjectOutput(baos);
+ ObjectOutput out = startObjectOutput(baos, false);
try {
defaultMarshaller.objectToObjectStream(obj, out);
} finally {
@@ -85,7 +86,7 @@
public Object objectFromByteBuffer(byte[] bytes, int offset, int len) throws IOException, ClassNotFoundException {
ByteArrayInputStream is = new ByteArrayInputStream(bytes, offset, len);
- ObjectInput in = startObjectInput(is);
+ ObjectInput in = startObjectInput(is, false);
Object o = null;
try {
o = defaultMarshaller.objectFromObjectStream(in);
@@ -95,8 +96,8 @@
return o;
}
- public ObjectOutput startObjectOutput(OutputStream os) throws IOException {
- ObjectOutput out = defaultMarshaller.startObjectOutput(os);
+ public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
+ ObjectOutput out = defaultMarshaller.startObjectOutput(os, isReentrant);
try {
out.writeShort(VERSION_400);
if (trace) log.trace("Wrote version {0}", VERSION_400);
@@ -123,8 +124,8 @@
defaultMarshaller.objectToObjectStream(obj, out);
}
- public ObjectInput startObjectInput(InputStream is) throws IOException {
- ObjectInput in = defaultMarshaller.startObjectInput(is);
+ public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException {
+ ObjectInput in = defaultMarshaller.startObjectInput(is, isReentrant);
int versionId;
try {
versionId = in.readShort();
Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/ConstantObjectTable.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -21,7 +21,7 @@
*/
package org.infinispan.marshall.jboss;
- import net.jcip.annotations.Immutable;
+import net.jcip.annotations.Immutable;
import org.infinispan.CacheException;
import org.infinispan.atomic.AtomicHashMap;
@@ -50,6 +50,8 @@
import org.infinispan.container.entries.TransientCacheValue;
import org.infinispan.container.entries.TransientMortalCacheEntry;
import org.infinispan.container.entries.TransientMortalCacheValue;
+import org.infinispan.factories.scopes.Scope;
+import org.infinispan.factories.scopes.Scopes;
import org.infinispan.loaders.bucket.Bucket;
import org.infinispan.marshall.MarshalledValue;
import org.infinispan.marshall.jboss.externalizers.ArrayListExternalizer;
@@ -109,6 +111,7 @@
* @author Galder Zamarreño
* @since 4.0
*/
+ at Scope(Scopes.GLOBAL)
public class ConstantObjectTable implements ObjectTable {
private static final int CAPACITY = 50;
private static final Map<String, String> EXTERNALIZERS = new HashMap<String, String>(CAPACITY);
@@ -175,13 +178,7 @@
private byte index;
- private final RemoteCommandFactory cmdFactory;
-
- public ConstantObjectTable(RemoteCommandFactory cmdFactory) {
- this.cmdFactory = cmdFactory;
- }
-
- public void init() {
+ public void init(RemoteCommandFactory cmdFactory, org.infinispan.marshall.Marshaller ispnMarshaller) {
// Init singletons
objects.add(RequestIgnoredResponse.INSTANCE);
writers.put(RequestIgnoredResponse.class, new InstanceWriter(index++));
@@ -195,6 +192,9 @@
if (delegate instanceof ReplicableCommandExternalizer) {
((ReplicableCommandExternalizer) delegate).init(cmdFactory);
}
+ if (delegate instanceof MarshalledValueExternalizer) {
+ ((MarshalledValueExternalizer) delegate).init(ispnMarshaller);
+ }
Externalizer rwrt = new DelegatingReadWriter(index++, delegate);
objects.add(rwrt);
writers.put(typeClazz, rwrt);
Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -23,10 +23,7 @@
import org.infinispan.CacheException;
import org.infinispan.commands.RemoteCommandFactory;
-import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Stop;
-import org.infinispan.factories.scopes.Scope;
-import org.infinispan.factories.scopes.Scopes;
import org.infinispan.io.ByteBuffer;
import org.infinispan.io.ExposedByteArrayOutputStream;
import org.infinispan.marshall.AbstractMarshaller;
@@ -53,7 +50,6 @@
* @author Galder Zamarreño
* @since 4.0
*/
- at Scope(Scopes.GLOBAL)
public class JBossMarshaller extends AbstractMarshaller {
private static final Log log = LogFactory.getLog(JBossMarshaller.class);
private static final String DEFAULT_MARSHALLER_FACTORY = "org.jboss.marshalling.river.RiverMarshallerFactory";
@@ -96,8 +92,7 @@
}
};
- @Inject
- public void init(ClassLoader defaultCl, RemoteCommandFactory cmdFactory) {
+ public void init(ClassLoader defaultCl, RemoteCommandFactory cmdFactory, org.infinispan.marshall.Marshaller ispnMarshaller) {
log.debug("Using JBoss Marshalling based marshaller.");
this.defaultCl = defaultCl;
try {
@@ -107,7 +102,7 @@
throw new CacheException("Unable to load JBoss Marshalling marshaller factory " + DEFAULT_MARSHALLER_FACTORY, e);
}
- objectTable = createCustomObjectTable(cmdFactory);
+ objectTable = createCustomObjectTable(cmdFactory, ispnMarshaller);
configuration = new MarshallingConfiguration();
configuration.setCreator(new SunReflectiveCreator());
configuration.setObjectTable(objectTable);
@@ -132,7 +127,7 @@
public ByteBuffer objectToBuffer(Object o) throws IOException {
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(128);
- ObjectOutput marshaller = startObjectOutput(baos);
+ ObjectOutput marshaller = startObjectOutput(baos, false);
try {
objectToObjectStream(o, marshaller);
} finally {
@@ -141,8 +136,13 @@
return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
}
- public ObjectOutput startObjectOutput(OutputStream os) throws IOException {
- org.jboss.marshalling.Marshaller marshaller = marshallerTL.get();
+ 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;
}
@@ -176,7 +176,7 @@
public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException,
ClassNotFoundException {
ByteArrayInputStream is = new ByteArrayInputStream(buf, offset, length);
- ObjectInput unmarshaller = startObjectInput(is);
+ ObjectInput unmarshaller = startObjectInput(is, false);
Object o = null;
try {
o = objectFromObjectStream(unmarshaller);
@@ -186,8 +186,13 @@
return o;
}
- public ObjectInput startObjectInput(InputStream is) throws IOException {
- Unmarshaller unmarshaller = unmarshallerTL.get();
+ 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;
}
@@ -203,9 +208,9 @@
return in.readObject();
}
- private ConstantObjectTable createCustomObjectTable(RemoteCommandFactory cmdFactory) {
- ConstantObjectTable objectTable = new ConstantObjectTable(cmdFactory);
- objectTable.init();
+ private ConstantObjectTable createCustomObjectTable(RemoteCommandFactory cmdFactory, org.infinispan.marshall.Marshaller ispnMarshaller) {
+ ConstantObjectTable objectTable = new ConstantObjectTable();
+ objectTable.init(cmdFactory, ispnMarshaller);
return objectTable;
}
}
Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/externalizers/MarshalledValueExternalizer.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/externalizers/MarshalledValueExternalizer.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/externalizers/MarshalledValueExternalizer.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -21,7 +21,6 @@
*/
package org.infinispan.marshall.jboss.externalizers;
-import net.jcip.annotations.Immutable;
import org.infinispan.io.UnsignedNumeric;
import org.infinispan.marshall.MarshalledValue;
import org.infinispan.marshall.jboss.Externalizer;
@@ -36,11 +35,13 @@
* @author Galder Zamarreño
* @since 4.0
*/
- at Immutable
public class MarshalledValueExternalizer implements Externalizer {
- /** The serialVersionUID */
- private static final long serialVersionUID = 8473423584918714661L;
-
+ private org.infinispan.marshall.Marshaller ispnMarshaller;
+
+ public void init(org.infinispan.marshall.Marshaller ispnMarshaller) {
+ this.ispnMarshaller = ispnMarshaller;
+ }
+
public void writeObject(Marshaller output, Object subject) throws IOException {
MarshalledValue mv = ((MarshalledValue) subject);
byte[] raw = mv.getRaw();
@@ -50,13 +51,11 @@
}
public Object readObject(Unmarshaller input) throws IOException, ClassNotFoundException {
- MarshalledValue mv = new MarshalledValue();
int length = UnsignedNumeric.readUnsignedInt(input);
- byte[] b = new byte[length];
- input.readFully(b);
+ byte[] raw = new byte[length];
+ input.readFully(raw);
int hc = input.readInt();
- mv.init(b, hc);
- return mv;
+ return new MarshalledValue(raw, hc, ispnMarshaller);
}
}
Modified: trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -142,7 +142,7 @@
boolean canProvideState = (transientState || persistentState)
&& (txLogActivated = transactionLog.activate());
if (log.isDebugEnabled()) log.debug("Generating state. Can provide? {0}", canProvideState);
- oo = marshaller.startObjectOutput(out);
+ oo = marshaller.startObjectOutput(out, false);
marshaller.objectToObjectStream(canProvideState, oo);
if (canProvideState) {
@@ -297,7 +297,7 @@
if (log.isDebugEnabled()) log.debug("Applying state");
ObjectInput oi = null;
try {
- oi = marshaller.startObjectInput(in);
+ oi = marshaller.startObjectInput(in, false);
boolean canProvideState = (Boolean) marshaller.objectFromObjectStream(oi);
if (canProvideState) {
assertDelimited(oi);
Modified: trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -27,9 +27,7 @@
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
-import java.io.ObjectInputStream;
import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
import java.util.Collections;
/**
@@ -44,6 +42,7 @@
private Cache cache1, cache2;
private MarshalledValueListenerInterceptor mvli;
String k = "key", v = "value";
+ private VersionAwareMarshaller marshaller;
protected void createCacheManagers() throws Throwable {
Configuration replSync = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
@@ -69,6 +68,9 @@
chain.removeInterceptor(MarshalledValueListenerInterceptor.class);
mvli = new MarshalledValueListenerInterceptor();
chain.addInterceptorAfter(mvli, MarshalledValueInterceptor.class);
+
+ marshaller = new VersionAwareMarshaller();
+ marshaller.init(Thread.currentThread().getContextClassLoader(), null);
}
@AfterMethod
@@ -197,7 +199,7 @@
public void testEqualsAndHashCode() throws Exception {
Pojo pojo = new Pojo();
- MarshalledValue mv = new MarshalledValue(pojo, true);
+ MarshalledValue mv = new MarshalledValue(pojo, true, marshaller);
assertDeserialized(mv);
int oldHashCode = mv.hashCode();
@@ -205,7 +207,7 @@
assertSerialized(mv);
assert oldHashCode == mv.hashCode();
- MarshalledValue mv2 = new MarshalledValue(pojo, true);
+ MarshalledValue mv2 = new MarshalledValue(pojo, true, marshaller);
assertSerialized(mv);
assertDeserialized(mv2);
@@ -215,7 +217,7 @@
public void assertUseOfMagicNumbers() throws Exception {
Pojo pojo = new Pojo();
- MarshalledValue mv = new MarshalledValue(pojo, true);
+ MarshalledValue mv = new MarshalledValue(pojo, true, marshaller);
VersionAwareMarshaller marshaller = new VersionAwareMarshaller();
@@ -223,14 +225,14 @@
// start the test
ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ObjectOutput oo = marshaller.startObjectOutput(bout);
+ ObjectOutput oo = marshaller.startObjectOutput(bout, false);
marshaller.objectToObjectStream(mv, oo);
marshaller.finishObjectOutput(oo);
bout.close();
// check that the rest just contains a byte stream which a MarshalledValue will be able to deserialize.
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
- ObjectInput oi = marshaller.startObjectInput(bin);
+ ObjectInput oi = marshaller.startObjectInput(bin, false);
MarshalledValue recreated = (MarshalledValue) marshaller.objectFromObjectStream(oi);
// there should be nothing more
Modified: trunk/core/src/test/java/org/infinispan/marshall/MarshallersTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/marshall/MarshallersTest.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/test/java/org/infinispan/marshall/MarshallersTest.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -73,7 +73,7 @@
* @author Galder Zamarreño
* @since 4.0
*/
- at Test(groups = "functional", testName = "marshall.MarshallersTest", enabled = false)
+ at Test(groups = "functional", testName = "marshall.MarshallersTest", enabled = true)
public class MarshallersTest {
private final MarshallerImpl home = new MarshallerImpl();
@@ -83,7 +83,7 @@
@BeforeTest
public void setUp() {
home.init(Thread.currentThread().getContextClassLoader(), new RemoteCommandFactory());
- jboss.init(Thread.currentThread().getContextClassLoader(), null);
+ jboss.init(Thread.currentThread().getContextClassLoader(), new RemoteCommandFactory(), jboss);
}
@AfterTest
@@ -156,8 +156,9 @@
public void testMarshalledValueMarshalling() throws Exception {
GlobalTransaction gtx = new GlobalTransaction(new JGroupsAddress(new IpAddress(12345)), false);
- MarshalledValue mv = new MarshalledValue(gtx, true);
- checkEqualityAndSize(mv);
+ int bytesH = marshallAndAssertEquality(home, new MarshalledValue(gtx, true, home));
+ int bytesJ = marshallAndAssertEquality(jboss, new MarshalledValue(gtx, true, jboss));
+ assert bytesJ < bytesH : "JBoss Marshaller should write less bytes: bytesJBoss=" + bytesJ + ", bytesHome=" + bytesH;
}
public void testSingletonListMarshalling() throws Exception {
Modified: trunk/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/test/java/org/infinispan/marshall/TestObjectStreamMarshaller.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -31,7 +31,7 @@
public TestObjectStreamMarshaller() {
}
- public ObjectOutput startObjectOutput(OutputStream os) throws IOException {
+ public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
return new ObjectOutputStream(os);
}
@@ -51,7 +51,7 @@
return xs.fromXML(xml);
}
- public ObjectInput startObjectInput(InputStream is) throws IOException {
+ public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException {
return new ObjectInputStream(is);
}
Modified: trunk/core/src/test/java/org/infinispan/marshall/jboss/JBossMarshallerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/marshall/jboss/JBossMarshallerTest.java 2009-06-04 15:48:50 UTC (rev 413)
+++ trunk/core/src/test/java/org/infinispan/marshall/jboss/JBossMarshallerTest.java 2009-06-04 15:52:55 UTC (rev 414)
@@ -46,9 +46,13 @@
import org.infinispan.container.entries.TransientCacheValue;
import org.infinispan.container.entries.TransientMortalCacheEntry;
import org.infinispan.container.entries.TransientMortalCacheValue;
+import org.infinispan.io.ExposedByteArrayOutputStream;
import org.infinispan.loaders.bucket.Bucket;
import org.infinispan.marshall.MarshalledValue;
+import org.infinispan.marshall.MarshalledValueTest;
import org.infinispan.marshall.VersionAwareMarshaller;
+import org.infinispan.marshall.MarshalledValueTest.Pojo;
+import org.infinispan.remoting.responses.ExceptionResponse;
import org.infinispan.remoting.responses.ExtendedResponse;
import org.infinispan.remoting.responses.RequestIgnoredResponse;
import org.infinispan.remoting.responses.SuccessfulResponse;
@@ -60,17 +64,21 @@
import org.infinispan.transaction.xa.GlobalTransaction;
import org.infinispan.util.FastCopyHashMap;
import org.infinispan.util.Immutables;
+import org.infinispan.util.concurrent.TimeoutException;
import org.jgroups.stack.IpAddress;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.*;
/**
* JBossMarshallingMarshallerTest.
* <p/>
- * Todo: AtomicHashMap missing.
+ * TODO: AtomicHashMap missing.
*
* @author Galder Zamarreño
* @since 4.0
@@ -154,9 +162,18 @@
public void testMarshalledValueMarshalling() throws Exception {
Person p = new Person();
p.setName("Bob Dylan");
- MarshalledValue mv = new MarshalledValue(p, true);
- marshallAndAssertEquality(mv);
+ MarshalledValue mv = new MarshalledValue(p, true, marshaller);
+ marshallAndAssertEquality(mv);
}
+
+ public void testMarshalledValueGetMarshalling() throws Exception {
+ MarshalledValueTest.Pojo ext = new MarshalledValueTest.Pojo();
+ MarshalledValue mv = new MarshalledValue(ext, true, marshaller);
+ byte[] bytes = marshaller.objectToByteBuffer(mv);
+ MarshalledValue rmv = (MarshalledValue) marshaller.objectFromByteBuffer(bytes);
+ assert rmv.equals(mv) : "Writen[" + mv + "] and read[" + rmv + "] objects should be the same";
+ assert rmv.get() instanceof Pojo;
+ }
public void testSingletonListMarshalling() throws Exception {
GlobalTransaction gtx = new GlobalTransaction(new JGroupsAddress(new IpAddress(12345)), false);
@@ -315,11 +332,17 @@
assert rb.getEntries().equals(b.getEntries()) : "Writen[" + b.getEntries() + "] and read[" + rb.getEntries() + "] objects should be the same";
}
- public void testLongPutKeyValueCommand() throws Exception
- {
+ public void testLongPutKeyValueCommand() throws Exception {
PutKeyValueCommand c = new PutKeyValueCommand("SESSION_173", "@TSXMHVROYNOFCJVEUJQGBCENNQDEWSCYSOHECJOHEICBEIGJVTIBB at TVNCWLTQCGTEJ@NBJLTMVGXCHXTSVE at BCRYGWPRVLXOJXBRJDVNBVXPRTRLBMHPOUYQKDEPDSADUAWPFSIOCINPSSFGABDUXRMTMMJMRTGBGBOAMGVMTKUDUAJGCAHCYW@LAXMDSFYOSXJXLUAJGQKPTHUKDOXRWKEFIVRTH at VIMQBGYPKWMS@HPOESTPIJE at OTOTWUWIOBLYKQQPTNGWVLRRCWHNIMWDQNOO@JHHEVYVQEODMWKFKKKSWURVDLXPTFQYIHLIM at GSBFWMDQGDQIJONNEVHGQTLDBRBML@BEWGHOQHHEBRFUQSLB@@CILXEAVQQBTXSITMBXHMHORHLT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MHPUBETEEIMIBPM at PETR@XD at DOHGRIBVXKLXQWHUFMTWEDYWFWRLPGDS@TANUXGIDTRVXKVCVEXYRKXQCTI at WNSFRAHJJGG@NIPPAAOJXQRTCLBYKDA at FFGHNUIGBFKOQMEDUEFELFLNKPCHA@OXJJRYNPDFSXIFSJYTDMSSBHDPUSQQDAVD at JAAWJDSVTERAJBFEPVRWKMYAPISPWLDPSRE@UMRQLXERTWRDLQVMVCOM at NYPXFLWMWKALMQVNJ@HCTMMIOLRWBJHCYFLMM at IWXPSHRRUNICSSWHOQHUVJE@HKJAADLBTPVLDAKCHRSURJCAXYTMYKHQMWDAWWASUW at HWGBVPTRHJGDWOGHPCNWSXTNKWONQGEKDDWGCKWVSAD!
@YLCCENMCHALHVDYQW at NQGNCY@M at GGV@RIR at OUS@PQIJMCFEIMGPYBXYR at NSIAUEXT@MOC
NWRMLYHUUAFJCCLLRNFGKLPPIIH at BYRME@UJAKIFHOV at ILP@BGXRNJBIBARSOIMTDSHMGPIGRJBGHYRYXPFUHVOOMCQFNLM at CNCBTGO@UKXBOICNVCRGHADYQVAMNSFRONJ at WITET@BSHMQLWYMVGMQJVSJOXOUJDSXYVVBQJSVGREQLIQKWC at BMDNONHXFYPQENSJINQYKHVCTUTG@QQYJKJURDCKJTUQAM at DWNXWRNILYVAAJ@IADBIXKEIHVXLXUVMGQPAQTWJCDMVDVYUDTXQTCYXDPHKBAGMTAMKEM at QNOQJBREXNWFCXNXRPGOGEIR@KQJIGXAWXLTNCX at ID@XNRNYGRF at QPNWEX@XH at XKSXLQTLQPFSHAHXJLHUTNQWFFAJYHBWIFVJELDPSPLRRDPPNXSBYBEREEELIWNVYXOXYJQAIGHALUAWNUSSNMBHBFLRMMTKEKNSINECUGWTDNMROXI@BJJXKSPIIIXOAJBFVSITQDXTODBGKEPJMWK at JOL@SWTCGSHCOPHECTPJFUXIHUOSVMUTNNSLLJDEOMAGIXEAAVILRMOJXVHHPNPUYYODMXYAYGHI at BUB@NLP at KNPCYFRWAFES@WISBACDSPELEVTJEBNRVENSXXEVDVC at RIDIDSBPQIQNNSRPS@HCJ at XPIOFDXHUBCNFQKHMUYLXW@LMFMALHLESSXCOULRWDTJIVKKTLGFE at HKGVKUGMVHWACQOTSVNWBNUUGTMSQEJ@DXJQQYPOWVRQNQKXSLOEAA@@FRDCGCCQWQ at IY@EATGQGQIETPIJHOIQRYWLTGUENQYDNQSBI at IAUDEWDKICHNUGNAIXNICMBK@CJGSASMTFKWOBSI at KULNENWXV@VNFOANM at OJHFVV@IYRMDB at LHSGXIJMMFCGJKTKDXSMY@FHDNY at VSDUORGWVFMVKJXOCCDLSLMHCSXFBTW@RQTFNRDJUIKRD at PWPY", false, null!
, 0, 0);
marshallAndAssertEquality(c);
}
+
+ public void testExceptionResponse() throws Exception {
+ ExceptionResponse er = new ExceptionResponse(new TimeoutException());
+ byte[] bytes = marshaller.objectToByteBuffer(er);
+ ExceptionResponse rer = (ExceptionResponse) marshaller.objectFromByteBuffer(bytes);
+ assert rer.getException().getClass().equals(er.getException().getClass()) : "Writen[" + er.getException().getClass() + "] and read[" + rer.getException().getClass() + "] objects should be the same";
+ }
protected void marshallAndAssertEquality(Object writeObj) throws Exception {
byte[] bytes = marshaller.objectToByteBuffer(writeObj);
More information about the infinispan-commits
mailing list