org.apache.flink.api.common.ExecutionConfig.SerializableSerializer Java Examples

The following examples show how to use org.apache.flink.api.common.ExecutionConfig.SerializableSerializer. 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: KryoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
	MergeResult<Class<?>, SerializableSerializer<?>> reconfiguredDefaultKryoSerializers,
	MergeResult<Class<?>, Class<? extends Serializer<?>>> reconfiguredDefaultKryoSerializerClasses,
	MergeResult<String, KryoRegistration> reconfiguredRegistrations) {

	if (reconfiguredDefaultKryoSerializers.isOrderedSubset() &&
		reconfiguredDefaultKryoSerializerClasses.isOrderedSubset() &&
		reconfiguredRegistrations.isOrderedSubset()) {

		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	// reconfigure a new KryoSerializer
	KryoSerializer<T> reconfiguredSerializer = new KryoSerializer<>(
		snapshotData.getTypeClass(),
		reconfiguredDefaultKryoSerializers.getMerged(),
		reconfiguredDefaultKryoSerializerClasses.getMerged(),
		reconfiguredRegistrations.getMerged());

	return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(reconfiguredSerializer);
}
 
Example #2
Source File: KryoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
private TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
	MergeResult<Class<?>, SerializableSerializer<?>> reconfiguredDefaultKryoSerializers,
	MergeResult<Class<?>, Class<? extends Serializer<?>>> reconfiguredDefaultKryoSerializerClasses,
	MergeResult<String, KryoRegistration> reconfiguredRegistrations) {

	if (reconfiguredDefaultKryoSerializers.isOrderedSubset() &&
		reconfiguredDefaultKryoSerializerClasses.isOrderedSubset() &&
		reconfiguredRegistrations.isOrderedSubset()) {

		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	// reconfigure a new KryoSerializer
	KryoSerializer<T> reconfiguredSerializer = new KryoSerializer<>(
		snapshotData.getTypeClass(),
		reconfiguredDefaultKryoSerializers.getMerged(),
		reconfiguredDefaultKryoSerializerClasses.getMerged(),
		reconfiguredRegistrations.getMerged());

	return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(reconfiguredSerializer);
}
 
Example #3
Source File: KryoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
private TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(
	MergeResult<Class<?>, SerializableSerializer<?>> reconfiguredDefaultKryoSerializers,
	MergeResult<Class<?>, Class<? extends Serializer<?>>> reconfiguredDefaultKryoSerializerClasses,
	MergeResult<String, KryoRegistration> reconfiguredRegistrations) {

	if (reconfiguredDefaultKryoSerializers.isOrderedSubset() &&
		reconfiguredDefaultKryoSerializerClasses.isOrderedSubset() &&
		reconfiguredRegistrations.isOrderedSubset()) {

		return TypeSerializerSchemaCompatibility.compatibleAsIs();
	}

	// reconfigure a new KryoSerializer
	KryoSerializer<T> reconfiguredSerializer = new KryoSerializer<>(
		snapshotData.getTypeClass(),
		reconfiguredDefaultKryoSerializers.getMerged(),
		reconfiguredDefaultKryoSerializerClasses.getMerged(),
		reconfiguredRegistrations.getMerged());

	return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(reconfiguredSerializer);
}
 
Example #4
Source File: KryoSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
KryoSerializer(Class<T> type,
			   LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultSerializers,
			   LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultSerializerClasses,
			   LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	this.type = checkNotNull(type, "Type class cannot be null.");
	this.defaultSerializerClasses = checkNotNull(defaultSerializerClasses, "Default serializer classes cannot be null.");
	this.defaultSerializers = checkNotNull(defaultSerializers, "Default serializers cannot be null.");
	this.kryoRegistrations = checkNotNull(kryoRegistrations, "Kryo registrations cannot be null.");
}
 
Example #5
Source File: KryoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
KryoSerializerSnapshot(Class<T> typeClass,
		LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
		LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
		LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	this.snapshotData = createFrom(typeClass, defaultKryoSerializers, defaultKryoSerializerClasses, kryoRegistrations);
}
 
Example #6
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
static <T> KryoSerializerSnapshotData<T> createFrom(DataInputView in, ClassLoader cl) throws IOException {
	Class<T> typeClass = readTypeClass(in, cl);
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations = readKryoRegistrations(in, cl);
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultSerializer = readDefaultKryoSerializers(in, cl);
	LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> defaultSerializerClasses =
		readDefaultKryoSerializerClasses(in, cl);

	return new KryoSerializerSnapshotData<>(
		typeClass,
		defaultSerializer,
		defaultSerializerClasses,
		kryoRegistrations);
}
 
Example #7
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private KryoSerializerSnapshotData(
	Class<T> typeClass,
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
	LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations) {

	this.typeClass = typeClass;
	this.defaultKryoSerializers = defaultKryoSerializers;
	this.defaultKryoSerializerClasses = defaultKryoSerializerClasses;
	this.kryoRegistrations = kryoRegistrations;
}
 
Example #8
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private void writeDefaultKryoSerializers(
	DataOutputView out,
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers) throws IOException {

	writeOptionalMap(
		out,
		defaultKryoSerializers,
		(stream, klass) -> stream.writeUTF(klass.getName()),
		(stream, instance) -> {
			try (final DataOutputViewStream outViewWrapper = new DataOutputViewStream(stream)) {
				InstantiationUtil.serializeObject(outViewWrapper, instance);
			}
		});
}
 
Example #9
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedOptionalMap<Class<?>, SerializableSerializer<?>> readDefaultKryoSerializers(DataInputView in, ClassLoader cl) throws IOException {
	return readOptionalMap(
		in,
		new ClassResolverByName(cl),
		new SerializeableSerializerResolver(cl));
}
 
Example #10
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public SerializableSerializer<?> apply(DataInputView stream, String className) {
	try {
		try (final DataInputViewStream inViewWrapper = new DataInputViewStream(stream)) {
			return InstantiationUtil.deserializeObject(inViewWrapper, classLoader);
		}
	}
	catch (Throwable e) {
		LOG.warn("Cannot deserialize a previously serialized kryo serializer for the type " + className, e);
		return null;
	}
}
 
Example #11
Source File: KryoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
KryoSerializerSnapshot(Class<T> typeClass,
		LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
		LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
		LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	this.snapshotData = createFrom(typeClass, defaultKryoSerializers, defaultKryoSerializerClasses, kryoRegistrations);
}
 
Example #12
Source File: KryoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(KryoSerializer<T> newSerializer) {
	// merge the default serializers
	final MergeResult<Class<?>, SerializableSerializer<?>> reconfiguredDefaultKryoSerializers = mergeRightIntoLeft(
		snapshotData.getDefaultKryoSerializers(),
		optionalMapOf(newSerializer.getDefaultKryoSerializers(), Class::getName));

	if (reconfiguredDefaultKryoSerializers.hasMissingKeys()) {
		logMissingKeys(reconfiguredDefaultKryoSerializers);
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	// merge default serializer classes
	final MergeResult<Class<?>, Class<? extends Serializer<?>>> reconfiguredDefaultKryoSerializerClasses = mergeRightIntoLeft(
		snapshotData.getDefaultKryoSerializerClasses(),
		optionalMapOf(newSerializer.getDefaultKryoSerializerClasses(), Class::getName));

	if (reconfiguredDefaultKryoSerializerClasses.hasMissingKeys()) {
		logMissingKeys(reconfiguredDefaultKryoSerializerClasses);
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	// merge registration
	final MergeResult<String, KryoRegistration> reconfiguredRegistrations = mergeRightIntoLeft(
		snapshotData.getKryoRegistrations(),
		optionalMapOf(newSerializer.getKryoRegistrations(), Function.identity()));

	if (reconfiguredRegistrations.hasMissingKeys()) {
		logMissingKeys(reconfiguredRegistrations);
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	// there are no missing keys, now we have to decide whether we are compatible as-is or we require reconfiguration.
	return resolveSchemaCompatibility(
		reconfiguredDefaultKryoSerializers,
		reconfiguredDefaultKryoSerializerClasses,
		reconfiguredRegistrations);
}
 
Example #13
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
static <T> KryoSerializerSnapshotData<T> createFrom(
	Class<T> typeClass,
	LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
	LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
	LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	return new KryoSerializerSnapshotData<>(
		typeClass,
		optionalMapOf(defaultKryoSerializers, Class::getName),
		optionalMapOf(defaultKryoSerializerClasses, Class::getName),
		optionalMapOf(kryoRegistrations, Function.identity()));
}
 
Example #14
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 #15
Source File: KryoSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
private ExecutionConfig.SerializableSerializer<? extends Serializer<?>> deepCopySerializer(
	ExecutionConfig.SerializableSerializer<? extends Serializer<?>> original) {
	try {
		return InstantiationUtil.clone(original, Thread.currentThread().getContextClassLoader());
	} catch (IOException | ClassNotFoundException ex) {
		throw new CloneFailedException(
			"Could not clone serializer instance of class " + original.getClass(),
			ex);
	}
}
 
Example #16
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
static <T> KryoSerializerSnapshotData<T> createFrom(
	Class<T> typeClass,
	LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
	LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
	LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	return new KryoSerializerSnapshotData<>(
		typeClass,
		optionalMapOf(defaultKryoSerializers, Class::getName),
		optionalMapOf(defaultKryoSerializerClasses, Class::getName),
		optionalMapOf(kryoRegistrations, Function.identity()));
}
 
Example #17
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
static <T> KryoSerializerSnapshotData<T> createFrom(DataInputView in, ClassLoader cl) throws IOException {
	Class<T> typeClass = readTypeClass(in, cl);
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations = readKryoRegistrations(in, cl);
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultSerializer = readDefaultKryoSerializers(in, cl);
	LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> defaultSerializerClasses =
		readDefaultKryoSerializerClasses(in, cl);

	return new KryoSerializerSnapshotData<>(
		typeClass,
		defaultSerializer,
		defaultSerializerClasses,
		kryoRegistrations);
}
 
Example #18
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private KryoSerializerSnapshotData(
	Class<T> typeClass,
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
	LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations) {

	this.typeClass = typeClass;
	this.defaultKryoSerializers = defaultKryoSerializers;
	this.defaultKryoSerializerClasses = defaultKryoSerializerClasses;
	this.kryoRegistrations = kryoRegistrations;
}
 
Example #19
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private void writeDefaultKryoSerializers(
	DataOutputView out,
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers) throws IOException {

	writeOptionalMap(
		out,
		defaultKryoSerializers,
		(stream, klass) -> stream.writeUTF(klass.getName()),
		(stream, instance) -> {
			try (final DataOutputViewStream outViewWrapper = new DataOutputViewStream(stream)) {
				InstantiationUtil.serializeObject(outViewWrapper, instance);
			}
		});
}
 
Example #20
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedOptionalMap<Class<?>, SerializableSerializer<?>> readDefaultKryoSerializers(DataInputView in, ClassLoader cl) throws IOException {
	return readOptionalMap(
		in,
		new ClassResolverByName(cl),
		new SerializeableSerializerResolver(cl));
}
 
Example #21
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public SerializableSerializer<?> apply(DataInputView stream, String className) {
	try {
		try (final DataInputViewStream inViewWrapper = new DataInputViewStream(stream)) {
			return InstantiationUtil.deserializeObject(inViewWrapper, classLoader);
		}
	}
	catch (Throwable e) {
		LOG.warn("Cannot deserialize a previously serialized kryo serializer for the type " + className, e);
		return null;
	}
}
 
Example #22
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 #23
Source File: KryoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(KryoSerializer<T> newSerializer) {
	// merge the default serializers
	final MergeResult<Class<?>, SerializableSerializer<?>> reconfiguredDefaultKryoSerializers = mergeRightIntoLeft(
		snapshotData.getDefaultKryoSerializers(),
		optionalMapOf(newSerializer.getDefaultKryoSerializers(), Class::getName));

	if (reconfiguredDefaultKryoSerializers.hasMissingKeys()) {
		logMissingKeys(reconfiguredDefaultKryoSerializers);
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	// merge default serializer classes
	final MergeResult<Class<?>, Class<? extends Serializer<?>>> reconfiguredDefaultKryoSerializerClasses = mergeRightIntoLeft(
		snapshotData.getDefaultKryoSerializerClasses(),
		optionalMapOf(newSerializer.getDefaultKryoSerializerClasses(), Class::getName));

	if (reconfiguredDefaultKryoSerializerClasses.hasMissingKeys()) {
		logMissingKeys(reconfiguredDefaultKryoSerializerClasses);
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	// merge registration
	final MergeResult<String, KryoRegistration> reconfiguredRegistrations = mergeRightIntoLeft(
		snapshotData.getKryoRegistrations(),
		optionalMapOf(newSerializer.getKryoRegistrations(), Function.identity()));

	if (reconfiguredRegistrations.hasMissingKeys()) {
		logMissingKeys(reconfiguredRegistrations);
		return TypeSerializerSchemaCompatibility.incompatible();
	}

	// there are no missing keys, now we have to decide whether we are compatible as-is or we require reconfiguration.
	return resolveSchemaCompatibility(
		reconfiguredDefaultKryoSerializers,
		reconfiguredDefaultKryoSerializerClasses,
		reconfiguredRegistrations);
}
 
Example #24
Source File: KryoSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
KryoSerializer(Class<T> type,
			   LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultSerializers,
			   LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultSerializerClasses,
			   LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	this.type = checkNotNull(type, "Type class cannot be null.");
	this.defaultSerializerClasses = checkNotNull(defaultSerializerClasses, "Default serializer classes cannot be null.");
	this.defaultSerializers = checkNotNull(defaultSerializers, "Default serializers cannot be null.");
	this.kryoRegistrations = checkNotNull(kryoRegistrations, "Kryo registrations cannot be null.");
}
 
Example #25
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 #26
Source File: KryoSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private ExecutionConfig.SerializableSerializer<? extends Serializer<?>> deepCopySerializer(
	ExecutionConfig.SerializableSerializer<? extends Serializer<?>> original) {
	try {
		return InstantiationUtil.clone(original, Thread.currentThread().getContextClassLoader());
	} catch (IOException | ClassNotFoundException ex) {
		throw new CloneFailedException(
			"Could not clone serializer instance of class " + original.getClass(),
			ex);
	}
}
 
Example #27
Source File: KryoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static <T> KryoSerializerSnapshotData<T> createFrom(
	Class<T> typeClass,
	LinkedHashMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
	LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
	LinkedHashMap<String, KryoRegistration> kryoRegistrations) {

	return new KryoSerializerSnapshotData<>(
		typeClass,
		optionalMapOf(defaultKryoSerializers, Class::getName),
		optionalMapOf(defaultKryoSerializerClasses, Class::getName),
		optionalMapOf(kryoRegistrations, Function.identity()));
}
 
Example #28
Source File: KryoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static <T> KryoSerializerSnapshotData<T> createFrom(DataInputView in, ClassLoader cl) throws IOException {
	Class<T> typeClass = readTypeClass(in, cl);
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations = readKryoRegistrations(in, cl);
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultSerializer = readDefaultKryoSerializers(in, cl);
	LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> defaultSerializerClasses =
		readDefaultKryoSerializerClasses(in, cl);

	return new KryoSerializerSnapshotData<>(
		typeClass,
		defaultSerializer,
		defaultSerializerClasses,
		kryoRegistrations);
}
 
Example #29
Source File: KryoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private KryoSerializerSnapshotData(
	Class<T> typeClass,
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers,
	LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> defaultKryoSerializerClasses,
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations) {

	this.typeClass = typeClass;
	this.defaultKryoSerializers = defaultKryoSerializers;
	this.defaultKryoSerializerClasses = defaultKryoSerializerClasses;
	this.kryoRegistrations = kryoRegistrations;
}
 
Example #30
Source File: KryoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void writeDefaultKryoSerializers(
	DataOutputView out,
	LinkedOptionalMap<Class<?>, SerializableSerializer<?>> defaultKryoSerializers) throws IOException {

	writeOptionalMap(
		out,
		defaultKryoSerializers,
		(stream, klass) -> stream.writeUTF(klass.getName()),
		(stream, instance) -> {
			try (final DataOutputViewStream outViewWrapper = new DataOutputViewStream(stream)) {
				InstantiationUtil.serializeObject(outViewWrapper, instance);
			}
		});
}