congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
Serializers.recursivelyRegisterType
Code IndexAdd Tabnine to your IDE (free)

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

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

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

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(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: apache/flink

assertEquals(GenericTypeInfo.class, te.getClass());
Serializers.recursivelyRegisterType(te.getTypeClass(), ec, new HashSet<>());
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: 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: 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: 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: 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

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.kryoSerializersrecursivelyRegisterType

Popular methods of Serializers

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

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • addToBackStack (FragmentTransaction)
  • runOnUiThread (Activity)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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