Permalink
Browse files

add optimized serializers to avoid reflection on object construction

  • Loading branch information...
nathanmarz committed May 26, 2012
1 parent b1e41b9 commit 51ea80091ffb599694e78fc16b5eac8d3c3b7b65
@@ -3,6 +3,9 @@
import backtype.storm.Config;
import backtype.storm.generated.ComponentCommon;
import backtype.storm.generated.StormTopology;
+import backtype.storm.serialization.types.ArrayListSerializer;
+import backtype.storm.serialization.types.HashMapSerializer;
+import backtype.storm.serialization.types.HashSetSerializer;
import backtype.storm.transactional.TransactionAttempt;
import backtype.storm.tuple.Values;
import backtype.storm.utils.ListDelegate;
@@ -48,9 +51,9 @@ public static Kryo getKryo(Map conf) {
k.setReferences(false);
k.register(byte[].class);
k.register(ListDelegate.class);
- k.register(ArrayList.class);
- k.register(HashMap.class);
- k.register(HashSet.class);
+ k.register(ArrayList.class, new ArrayListSerializer(k));
+ k.register(HashMap.class, new HashMapSerializer(k));
+ k.register(HashSet.class, new HashSetSerializer(k));
k.register(BigInteger.class, new BigIntegerSerializer());
k.register(TransactionAttempt.class);
k.register(Values.class);
@@ -0,0 +1,19 @@
+package backtype.storm.serialization.types;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.serializers.CollectionSerializer;
+import java.util.ArrayList;
+import java.util.Collection;
+
+
+public class ArrayListSerializer extends CollectionSerializer {
+ public ArrayListSerializer(Kryo kryo) {
+ super(kryo);
+ }
+
+ @Override
+ public Collection create(Kryo kryo, Input input, Class<Collection> type) {
+ return new ArrayList();
+ }
+}
@@ -0,0 +1,19 @@
+package backtype.storm.serialization.types;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.serializers.MapSerializer;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class HashMapSerializer extends MapSerializer {
+ public HashMapSerializer(Kryo kryo) {
+ super(kryo);
+ }
+
+ @Override
+ public Map create(Kryo kryo, Input input, Class<Map> type) {
+ return new HashMap();
+ }
+}
@@ -0,0 +1,19 @@
+package backtype.storm.serialization.types;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.serializers.CollectionSerializer;
+import java.util.Collection;
+import java.util.HashSet;
+
+
+public class HashSetSerializer extends CollectionSerializer {
+ public HashSetSerializer(Kryo kryo) {
+ super(kryo);
+ }
+
+ @Override
+ public Collection create(Kryo kryo, Input input, Class<Collection> type) {
+ return new HashSet();
+ }
+}

0 comments on commit 51ea800

Please sign in to comment.