[infinispan-commits] Infinispan SVN: r1996 - in branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod: impl and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue Jul 6 12:24:38 EDT 2010
Author: mircea.markus
Date: 2010-07-06 12:24:38 -0400 (Tue, 06 Jul 2010)
New Revision: 1996
Modified:
branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/HotRodMarshaller.java
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/impl/SerializationMarshaller.java
Log:
[ISPN-513] = hotrod client:optimize serialization of key/values
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/HotRodMarshaller.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/HotRodMarshaller.java 2010-07-06 16:16:26 UTC (rev 1995)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/HotRodMarshaller.java 2010-07-06 16:24:38 UTC (rev 1996)
@@ -2,6 +2,8 @@
import net.jcip.annotations.ThreadSafe;
+import java.util.Properties;
+
/**
* Used for un/marshalling objects sent between hotrod client and server (hotrod is a binary protocol).
* A single instance of this class is shared by all threads, so this class needs to be thread safe.
@@ -12,6 +14,8 @@
@ThreadSafe
public interface HotRodMarshaller {
+ void init(Properties config);
+
byte[] marshallObject(Object toMarshall);
Object readObject(byte[] bytes);
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-06 16:16:26 UTC (rev 1995)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-07-06 16:24:38 UTC (rev 1996)
@@ -154,7 +154,7 @@
*/
public RemoteCacheManager(HotRodMarshaller hotRodMarshaller, Properties props, boolean start) {
this(props);
- this.hotRodMarshaller = hotRodMarshaller;
+ setHotRodMarshaller(hotRodMarshaller);
if (log.isTraceEnabled()) {
log.trace("Using explicitly set marshaller: " + hotRodMarshaller);
}
@@ -305,7 +305,7 @@
hotrodMarshallerClass = SerializationMarshaller.class.getName();
log.info("'marshaller' not specified, using " + hotrodMarshallerClass);
}
- hotRodMarshaller = (HotRodMarshaller) VHelper.newInstance(hotrodMarshallerClass);
+ setHotRodMarshaller((HotRodMarshaller)VHelper.newInstance(hotrodMarshallerClass));
}
String asyncExecutorClass = DefaultAsyncExecutorFactory.class.getName();
@@ -396,4 +396,8 @@
return new String[]{t.nextToken(), t.nextToken()};
}
+ private void setHotRodMarshaller(HotRodMarshaller hotRodMarshaller) {
+ this.hotRodMarshaller = hotRodMarshaller;
+ hotRodMarshaller.init(props);
+ }
}
Modified: branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/SerializationMarshaller.java
===================================================================
--- branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/SerializationMarshaller.java 2010-07-06 16:16:26 UTC (rev 1995)
+++ branches/4.1.x/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/SerializationMarshaller.java 2010-07-06 16:24:38 UTC (rev 1996)
@@ -7,11 +7,11 @@
import org.infinispan.util.logging.LogFactory;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
+import java.util.Properties;
/**
* Default marshaller implementation based on object serialization.
@@ -23,9 +23,19 @@
private static Log log = LogFactory.getLog(SerializationMarshaller.class);
+ private volatile int defaultArraySize = 128;
+
@Override
+ public void init(Properties config) {
+ if (config.contains("marshaller.default-array-size")) {
+ defaultArraySize = Integer.parseInt(config.getProperty("marshaller.default-array-size"));
+ }
+ defaultArraySize = 128;
+ }
+
+ @Override
public byte[] marshallObject(Object toMarshall) {
- ExposedByteArrayOutputStream result = new ExposedByteArrayOutputStream(128);
+ ExposedByteArrayOutputStream result = new ExposedByteArrayOutputStream(defaultArraySize);
try {
ObjectOutputStream oos = new ObjectOutputStream(result);
oos.writeObject(toMarshall);
More information about the infinispan-commits
mailing list