Search in sources :

Example 1 with SpecificInstanceCollectionSerializerForArrayList

use of org.apache.flink.api.java.typeutils.runtime.kryo.Serializers.SpecificInstanceCollectionSerializerForArrayList in project flink by apache.

the class KryoSerializer method checkKryoInitialized.

private void checkKryoInitialized() {
    if (this.kryo == null) {
        this.kryo = getKryoInstance();
        // Enable reference tracking. 
        kryo.setReferences(true);
        // Throwable and all subclasses should be serialized via java serialization
        // Note: the registered JavaSerializer is Flink's own implementation, and not Kryo's.
        //       This is due to a know issue with Kryo's JavaSerializer. See FLINK-6025 for details.
        kryo.addDefaultSerializer(Throwable.class, new JavaSerializer());
        // are registered with a default serializer
        for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> entry : defaultSerializers.entrySet()) {
            kryo.addDefaultSerializer(entry.getKey(), entry.getValue().getSerializer());
        }
        for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> entry : defaultSerializerClasses.entrySet()) {
            kryo.addDefaultSerializer(entry.getKey(), entry.getValue());
        }
        // register the type of our class
        kryo.register(type);
        // more specific serializer overrides this
        for (Class<?> type : registeredTypes) {
            kryo.register(type);
        }
        // register given serializer classes
        for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> e : registeredTypesWithSerializerClasses.entrySet()) {
            Class<?> typeClass = e.getKey();
            Class<? extends Serializer<?>> serializerClass = e.getValue();
            Serializer<?> serializer = ReflectionSerializerFactory.makeSerializer(kryo, serializerClass, typeClass);
            kryo.register(typeClass, serializer);
        }
        // register given serializers
        for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> e : registeredTypesWithSerializers.entrySet()) {
            kryo.register(e.getKey(), e.getValue().getSerializer());
        }
        // this is needed for Avro but can not be added on demand.
        kryo.register(GenericData.Array.class, new SpecificInstanceCollectionSerializerForArrayList());
        kryo.setRegistrationRequired(false);
        kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GenericData(org.apache.avro.generic.GenericData) Serializer(com.esotericsoftware.kryo.Serializer) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) SpecificInstanceCollectionSerializerForArrayList(org.apache.flink.api.java.typeutils.runtime.kryo.Serializers.SpecificInstanceCollectionSerializerForArrayList)

Aggregations

Serializer (com.esotericsoftware.kryo.Serializer)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 GenericData (org.apache.avro.generic.GenericData)1 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)1 SpecificInstanceCollectionSerializerForArrayList (org.apache.flink.api.java.typeutils.runtime.kryo.Serializers.SpecificInstanceCollectionSerializerForArrayList)1