nwangtw commented on a change in pull request #3256: Add kryo serializer in 
Heron API
URL: https://github.com/apache/incubator-heron/pull/3256#discussion_r284480714
 
 

 ##########
 File path: 
heron/api/src/java/org/apache/heron/streamlet/impl/KryoSerializer.java
 ##########
 @@ -17,95 +17,12 @@
  * under the License.
  */
 
-
 package org.apache.heron.streamlet.impl;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
-import com.esotericsoftware.kryo.serializers.CollectionSerializer;
-import com.esotericsoftware.kryo.serializers.DefaultSerializers;
-import com.esotericsoftware.kryo.serializers.MapSerializer;
-
-import org.apache.heron.api.serializer.IPluggableSerializer;
-
 /**
- * KryoSerializer is a wrapper around Heron's IPluggableSerializer.
- * Streamlet based topologies turning on kryo serialization are based off of 
it.
+ * KryoSerializer has been moved to heron.api.serializer package so that it 
can be used
+ * by Heron topologies written in low level API. This is just an alias for 
backward compatible
+ * purpose in case some users use this class directly. The class should NOT be 
used in Heron code.
  */
-public class KryoSerializer implements IPluggableSerializer {
-  private Kryo kryo;
-  private Output kryoOut;
-  private Input kryoIn;
-
-  /**
-   * A quick utility function that determines whether kryo has been linked
-   * with the streamlet binary
-   */
-  public static void checkForKryo() {
-    Kryo k = new Kryo();
-  }
-
-  @Override
-  public void initialize(Map<String, Object> config) {
-    kryo = getKryo();
-    kryoOut = new Output(2000, 2000000000);
-    kryoIn = new Input(1);
-  }
-
-  @Override
-  public byte[] serialize(Object object) {
-    kryoOut.clear();
-    kryo.writeClassAndObject(kryoOut, object);
-    return kryoOut.toBytes();
-  }
-
-  @Override
-  public Object deserialize(byte[] input) {
-    kryoIn.setBuffer(input);
-    return kryo.readClassAndObject(kryoIn);
-  }
-
-  private Kryo getKryo() {
-    Kryo k = new Kryo();
-    k.setRegistrationRequired(false);
-    k.setReferences(false);
-    k.register(byte[].class);
-    k.register(ArrayList.class, new ArrayListSerializer());
-    k.register(HashMap.class, new HashMapSerializer());
-    k.register(HashSet.class, new HashSetSerializer());
-    k.register(BigInteger.class, new 
DefaultSerializers.BigIntegerSerializer());
-    return k;
-  }
-
-  private class ArrayListSerializer extends CollectionSerializer {
-    @Override
-    @SuppressWarnings("rawtypes") // extending Kryo class that uses raw types
-    public Collection create(Kryo k, Input input, Class<Collection> type) {
-      return new ArrayList();
-    }
-  }
-
-  private class HashMapSerializer extends MapSerializer {
-    @Override
-    @SuppressWarnings("rawtypes") // extending kryo class signature that takes 
Map
-    public Map<String, Object> create(Kryo k, Input input, Class<Map> type) {
-      return new HashMap<>();
-    }
-  }
-
-  private class HashSetSerializer extends CollectionSerializer {
-    @Override
-    @SuppressWarnings("rawtypes") // extending Kryo class that uses raw types
-    public Collection create(Kryo k, Input input, Class<Collection> type) {
-      return new HashSet();
-    }
-  }
+public class KryoSerializer extends 
org.apache.heron.api.serializer.KryoSerializer {
 
 Review comment:
   This class can be used by Streamlet config currently. So I am leaving it 
available just in case someone is using it in their project.
   
   Let me clarify it in comment.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to