Tabnine Logo
Serializers
Code IndexAdd Tabnine to your IDE (free)

How to use
Serializers
in
org.apache.flink.api.java.typeutils.runtime.kryo

Best Java code snippets using org.apache.flink.api.java.typeutils.runtime.kryo.Serializers (Showing top 15 results out of 315)

origin: apache/flink

private static void recursivelyRegisterGenericType(Type fieldType, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  if (fieldType instanceof ParameterizedType) {
    // field has generics
    ParameterizedType parameterizedFieldType = (ParameterizedType) fieldType;
    
    for (Type t: parameterizedFieldType.getActualTypeArguments()) {
      if (TypeExtractionUtils.isClassType(t) ) {
        recursivelyRegisterType(TypeExtractionUtils.typeToClass(t), config, alreadySeen);
      }
    }
    recursivelyRegisterGenericType(parameterizedFieldType.getRawType(), config, alreadySeen);
  }
  else if (fieldType instanceof GenericArrayType) {
    GenericArrayType genericArrayType = (GenericArrayType) fieldType;
    recursivelyRegisterGenericType(genericArrayType.getGenericComponentType(), config, alreadySeen);
  }
  else if (fieldType instanceof Class) {
    Class<?> clazz = (Class<?>) fieldType;
    recursivelyRegisterType(clazz, config, alreadySeen);
  }
}
origin: apache/flink

public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  if (typeInfo instanceof GenericTypeInfo) {
    GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
    Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen);
  }
  else if (typeInfo instanceof CompositeType) {
    List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
    getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite);
    for (GenericTypeInfo<?> gt : genericTypesInComposite) {
      Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
    }
  }
  else if (typeInfo instanceof ObjectArrayTypeInfo) {
    ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
    recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
  }
}

origin: apache/flink

assertEquals(GenericTypeInfo.class, te.getClass());
Serializers.recursivelyRegisterType(te.getTypeClass(), ec, new HashSet<>());
origin: apache/flink

/**
 * Returns all GenericTypeInfos contained in a composite type.
 *
 * @param typeInfo {@link CompositeType}
 */
private static void getContainedGenericTypes(CompositeType<?> typeInfo, List<GenericTypeInfo<?>> target) {
  for (int i = 0; i < typeInfo.getArity(); i++) {
    TypeInformation<?> type = typeInfo.getTypeAt(i);
    if (type instanceof CompositeType) {
      getContainedGenericTypes((CompositeType<?>) type, target);
    } else if (type instanceof GenericTypeInfo) {
      if (!target.contains(type)) {
        target.add((GenericTypeInfo<?>) type);
      }
    }
  }
}
origin: apache/flink

@Test
public void testTypeRegistration() {
  ExecutionConfig conf = new ExecutionConfig();
  Serializers.recursivelyRegisterType(ClassWithNested.class, conf, new HashSet<Class<?>>());
  
  KryoSerializer<String> kryo = new KryoSerializer<>(String.class, conf); // we create Kryo from another type.
  Assert.assertTrue(kryo.getKryo().getRegistration(FromNested.class).getId() > 0);
  Assert.assertTrue(kryo.getKryo().getRegistration(ClassWithNested.class).getId() > 0);
  Assert.assertTrue(kryo.getKryo().getRegistration(Path.class).getId() > 0);
  
  // check if the generic type from one field is also registered (its very likely that
  // generic types are also used as fields somewhere.
  Assert.assertTrue(kryo.getKryo().getRegistration(FromGeneric1.class).getId() > 0);
  Assert.assertTrue(kryo.getKryo().getRegistration(FromGeneric2.class).getId() > 0);
  Assert.assertTrue(kryo.getKryo().getRegistration(Node.class).getId() > 0);
  
  
  // register again and make sure classes are still registered
  ExecutionConfig conf2 = new ExecutionConfig();
  Serializers.recursivelyRegisterType(ClassWithNested.class, conf2, new HashSet<Class<?>>());
  KryoSerializer<String> kryo2 = new KryoSerializer<>(String.class, conf);
  assertTrue(kryo2.getKryo().getRegistration(FromNested.class).getId() > 0);
}
origin: org.apache.flink/flink-core

/**
 * Returns all GenericTypeInfos contained in a composite type.
 *
 * @param typeInfo {@link CompositeType}
 */
private static void getContainedGenericTypes(CompositeType<?> typeInfo, List<GenericTypeInfo<?>> target) {
  for (int i = 0; i < typeInfo.getArity(); i++) {
    TypeInformation<?> type = typeInfo.getTypeAt(i);
    if (type instanceof CompositeType) {
      getContainedGenericTypes((CompositeType<?>) type, target);
    } else if (type instanceof GenericTypeInfo) {
      if (!target.contains(type)) {
        target.add((GenericTypeInfo<?>) type);
      }
    }
  }
}
origin: apache/flink

public static void recursivelyRegisterType(Class<?> type, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  // don't register or remember primitives
  if (type == null || type.isPrimitive() || type == Object.class) {
    return;
  }
  
  // prevent infinite recursion for recursive types
  if (!alreadySeen.add(type)) {
    return;
  }
  
  if (type.isArray()) {
    recursivelyRegisterType(type.getComponentType(), config, alreadySeen);
  }
  else {
    config.registerKryoType(type);
    // add serializers for Avro type if necessary
    AvroUtils.getAvroUtils().addAvroSerializersIfRequired(config, type);
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
      if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
        continue;
      }
      Type fieldType = field.getGenericType();
      recursivelyRegisterGenericType(fieldType, config, alreadySeen);
    }
  }
}

origin: org.apache.flink/flink-core

public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  if (typeInfo instanceof GenericTypeInfo) {
    GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
    Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen);
  }
  else if (typeInfo instanceof CompositeType) {
    List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
    getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite);
    for (GenericTypeInfo<?> gt : genericTypesInComposite) {
      Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
    }
  }
  else if (typeInfo instanceof ObjectArrayTypeInfo) {
    ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
    recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
  }
}

origin: apache/flink

  @Test
  public void testTypeRegistrationFromTypeInfo() {
    ExecutionConfig conf = new ExecutionConfig();
    Serializers.recursivelyRegisterType(new GenericTypeInfo<>(ClassWithNested.class), conf, new HashSet<Class<?>>());

    KryoSerializer<String> kryo = new KryoSerializer<>(String.class, conf); // we create Kryo from another type.

    assertTrue(kryo.getKryo().getRegistration(FromNested.class).getId() > 0);
    assertTrue(kryo.getKryo().getRegistration(ClassWithNested.class).getId() > 0);
    assertTrue(kryo.getKryo().getRegistration(Path.class).getId() > 0);

    // check if the generic type from one field is also registered (its very likely that
    // generic types are also used as fields somewhere.
    assertTrue(kryo.getKryo().getRegistration(FromGeneric1.class).getId() > 0);
    assertTrue(kryo.getKryo().getRegistration(FromGeneric2.class).getId() > 0);
    assertTrue(kryo.getKryo().getRegistration(Node.class).getId() > 0);
  }
}
origin: com.alibaba.blink/flink-core

/**
 * Returns all GenericTypeInfos contained in a composite type.
 *
 * @param typeInfo {@link CompositeType}
 */
private static void getContainedGenericTypes(CompositeType<?> typeInfo, List<GenericTypeInfo<?>> target) {
  for (int i = 0; i < typeInfo.getArity(); i++) {
    TypeInformation<?> type = typeInfo.getTypeAt(i);
    if (type instanceof CompositeType) {
      getContainedGenericTypes((CompositeType<?>) type, target);
    } else if (type instanceof GenericTypeInfo) {
      if (!target.contains(type)) {
        target.add((GenericTypeInfo<?>) type);
      }
    }
  }
}
origin: org.apache.flink/flink-core

private static void recursivelyRegisterGenericType(Type fieldType, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  if (fieldType instanceof ParameterizedType) {
    // field has generics
    ParameterizedType parameterizedFieldType = (ParameterizedType) fieldType;
    
    for (Type t: parameterizedFieldType.getActualTypeArguments()) {
      if (TypeExtractionUtils.isClassType(t) ) {
        recursivelyRegisterType(TypeExtractionUtils.typeToClass(t), config, alreadySeen);
      }
    }
    recursivelyRegisterGenericType(parameterizedFieldType.getRawType(), config, alreadySeen);
  }
  else if (fieldType instanceof GenericArrayType) {
    GenericArrayType genericArrayType = (GenericArrayType) fieldType;
    recursivelyRegisterGenericType(genericArrayType.getGenericComponentType(), config, alreadySeen);
  }
  else if (fieldType instanceof Class) {
    Class<?> clazz = (Class<?>) fieldType;
    recursivelyRegisterType(clazz, config, alreadySeen);
  }
}
origin: com.alibaba.blink/flink-core

public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  if (typeInfo instanceof GenericTypeInfo) {
    GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
    Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen);
  }
  else if (typeInfo instanceof CompositeType) {
    List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
    getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite);
    for (GenericTypeInfo<?> gt : genericTypesInComposite) {
      Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
    }
  }
  else if (typeInfo instanceof ObjectArrayTypeInfo) {
    ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
    recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
  }
}

origin: com.alibaba.blink/flink-core

private static void recursivelyRegisterGenericType(Type fieldType, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  if (fieldType instanceof ParameterizedType) {
    // field has generics
    ParameterizedType parameterizedFieldType = (ParameterizedType) fieldType;
    
    for (Type t: parameterizedFieldType.getActualTypeArguments()) {
      if (TypeExtractionUtils.isClassType(t) ) {
        recursivelyRegisterType(TypeExtractionUtils.typeToClass(t), config, alreadySeen);
      }
    }
    recursivelyRegisterGenericType(parameterizedFieldType.getRawType(), config, alreadySeen);
  }
  else if (fieldType instanceof GenericArrayType) {
    GenericArrayType genericArrayType = (GenericArrayType) fieldType;
    recursivelyRegisterGenericType(genericArrayType.getGenericComponentType(), config, alreadySeen);
  }
  else if (fieldType instanceof Class) {
    Class<?> clazz = (Class<?>) fieldType;
    recursivelyRegisterType(clazz, config, alreadySeen);
  }
}
origin: org.apache.flink/flink-core

public static void recursivelyRegisterType(Class<?> type, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  // don't register or remember primitives
  if (type == null || type.isPrimitive() || type == Object.class) {
    return;
  }
  
  // prevent infinite recursion for recursive types
  if (!alreadySeen.add(type)) {
    return;
  }
  
  if (type.isArray()) {
    recursivelyRegisterType(type.getComponentType(), config, alreadySeen);
  }
  else {
    config.registerKryoType(type);
    // add serializers for Avro type if necessary
    AvroUtils.getAvroUtils().addAvroSerializersIfRequired(config, type);
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
      if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
        continue;
      }
      Type fieldType = field.getGenericType();
      recursivelyRegisterGenericType(fieldType, config, alreadySeen);
    }
  }
}

origin: com.alibaba.blink/flink-core

public static void recursivelyRegisterType(Class<?> type, ExecutionConfig config, Set<Class<?>> alreadySeen) {
  // don't register or remember primitives
  if (type == null || type.isPrimitive() || type == Object.class) {
    return;
  }
  
  // prevent infinite recursion for recursive types
  if (!alreadySeen.add(type)) {
    return;
  }
  
  if (type.isArray()) {
    recursivelyRegisterType(type.getComponentType(), config, alreadySeen);
  }
  else {
    config.registerKryoType(type);
    // add serializers for Avro type if necessary
    AvroUtils.getAvroUtils().addAvroSerializersIfRequired(config, type);
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
      if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
        continue;
      }
      Type fieldType = field.getGenericType();
      recursivelyRegisterGenericType(fieldType, config, alreadySeen);
    }
  }
}

org.apache.flink.api.java.typeutils.runtime.kryoSerializers

Javadoc

Class containing utilities for the serializers of the Flink Runtime. Most of the serializers are automatically added to the system. Note that users can also implement the com.esotericsoftware.kryo.KryoSerializable interface to provide custom serialization for their classes. Also, there is a Java Annotation for adding a default serializer (@DefaultSerializer) to classes.

Most used methods

  • recursivelyRegisterType
  • getContainedGenericTypes
    Returns all GenericTypeInfos contained in a composite type.
  • recursivelyRegisterGenericType

Popular in Java

  • Making http post requests using okhttp
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • putExtra (Intent)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • JCheckBox (javax.swing)
  • JComboBox (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now