org.apache.flink.api.java.typeutils.AvroUtils Java Examples

The following examples show how to use org.apache.flink.api.java.typeutils.AvroUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KryoSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method that takes lists of registered types and their serializers, and resolve
 * them into a single list such that the result will resemble the final registration
 * result in Kryo.
 */
private static LinkedHashMap<String, KryoRegistration> buildKryoRegistrations(
		Class<?> serializedType,
		LinkedHashSet<Class<?>> registeredTypes,
		LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> registeredTypesWithSerializerClasses,
		LinkedHashMap<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypesWithSerializers) {

	final LinkedHashMap<String, KryoRegistration> kryoRegistrations = new LinkedHashMap<>();

	kryoRegistrations.put(serializedType.getName(), new KryoRegistration(serializedType));

	for (Class<?> registeredType : checkNotNull(registeredTypes)) {
		kryoRegistrations.put(registeredType.getName(), new KryoRegistration(registeredType));
	}

	for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> registeredTypeWithSerializerClassEntry :
			checkNotNull(registeredTypesWithSerializerClasses).entrySet()) {

		kryoRegistrations.put(
				registeredTypeWithSerializerClassEntry.getKey().getName(),
				new KryoRegistration(
						registeredTypeWithSerializerClassEntry.getKey(),
						registeredTypeWithSerializerClassEntry.getValue()));
	}

	for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypeWithSerializerEntry :
			checkNotNull(registeredTypesWithSerializers).entrySet()) {

		kryoRegistrations.put(
				registeredTypeWithSerializerEntry.getKey().getName(),
				new KryoRegistration(
						registeredTypeWithSerializerEntry.getKey(),
						registeredTypeWithSerializerEntry.getValue()));
	}

	// add Avro support if flink-avro is available; a dummy otherwise
	AvroUtils.getAvroUtils().addAvroGenericDataArrayRegistration(kryoRegistrations);

	return kryoRegistrations;
}
 
Example #2
Source File: Serializers.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example #3
Source File: KryoSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method that takes lists of registered types and their serializers, and resolve
 * them into a single list such that the result will resemble the final registration
 * result in Kryo.
 */
private static LinkedHashMap<String, KryoRegistration> buildKryoRegistrations(
		Class<?> serializedType,
		LinkedHashSet<Class<?>> registeredTypes,
		LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> registeredTypesWithSerializerClasses,
		LinkedHashMap<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypesWithSerializers) {

	final LinkedHashMap<String, KryoRegistration> kryoRegistrations = new LinkedHashMap<>();

	kryoRegistrations.put(serializedType.getName(), new KryoRegistration(serializedType));

	for (Class<?> registeredType : checkNotNull(registeredTypes)) {
		kryoRegistrations.put(registeredType.getName(), new KryoRegistration(registeredType));
	}

	for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> registeredTypeWithSerializerClassEntry :
			checkNotNull(registeredTypesWithSerializerClasses).entrySet()) {

		kryoRegistrations.put(
				registeredTypeWithSerializerClassEntry.getKey().getName(),
				new KryoRegistration(
						registeredTypeWithSerializerClassEntry.getKey(),
						registeredTypeWithSerializerClassEntry.getValue()));
	}

	for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypeWithSerializerEntry :
			checkNotNull(registeredTypesWithSerializers).entrySet()) {

		kryoRegistrations.put(
				registeredTypeWithSerializerEntry.getKey().getName(),
				new KryoRegistration(
						registeredTypeWithSerializerEntry.getKey(),
						registeredTypeWithSerializerEntry.getValue()));
	}

	// add Avro support if flink-avro is available; a dummy otherwise
	AvroUtils.getAvroUtils().addAvroGenericDataArrayRegistration(kryoRegistrations);

	return kryoRegistrations;
}
 
Example #4
Source File: Serializers.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example #5
Source File: KryoSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method that takes lists of registered types and their serializers, and resolve
 * them into a single list such that the result will resemble the final registration
 * result in Kryo.
 */
private static LinkedHashMap<String, KryoRegistration> buildKryoRegistrations(
		Class<?> serializedType,
		LinkedHashSet<Class<?>> registeredTypes,
		LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> registeredTypesWithSerializerClasses,
		LinkedHashMap<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypesWithSerializers) {

	final LinkedHashMap<String, KryoRegistration> kryoRegistrations = new LinkedHashMap<>();

	kryoRegistrations.put(serializedType.getName(), new KryoRegistration(serializedType));

	for (Class<?> registeredType : checkNotNull(registeredTypes)) {
		kryoRegistrations.put(registeredType.getName(), new KryoRegistration(registeredType));
	}

	for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> registeredTypeWithSerializerClassEntry :
			checkNotNull(registeredTypesWithSerializerClasses).entrySet()) {

		kryoRegistrations.put(
				registeredTypeWithSerializerClassEntry.getKey().getName(),
				new KryoRegistration(
						registeredTypeWithSerializerClassEntry.getKey(),
						registeredTypeWithSerializerClassEntry.getValue()));
	}

	for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypeWithSerializerEntry :
			checkNotNull(registeredTypesWithSerializers).entrySet()) {

		kryoRegistrations.put(
				registeredTypeWithSerializerEntry.getKey().getName(),
				new KryoRegistration(
						registeredTypeWithSerializerEntry.getKey(),
						registeredTypeWithSerializerEntry.getValue()));
	}

	// add Avro support if flink-avro is available; a dummy otherwise
	AvroUtils.getAvroUtils().addAvroGenericDataArrayRegistration(kryoRegistrations);

	return kryoRegistrations;
}
 
Example #6
Source File: Serializers.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}