org.apache.flink.util.LinkedOptionalMap Java Examples

The following examples show how to use org.apache.flink.util.LinkedOptionalMap. 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: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Finds which registered subclasses exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of this preexisting registered subclasses.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingRegisteredSubclasses(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots) {

	final LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> unwrappedSerializerSnapshots = registeredSubclassSerializerSnapshots.unwrapOptionals();

	final ArrayList<TypeSerializerSnapshot<?>> associatedSubclassSerializerSnapshots = new ArrayList<>();
	final ArrayList<TypeSerializer<?>> associatedNewSubclassSerializers = new ArrayList<>();

	final LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassSerializerRegistry = newPojoSerializer.getBundledSubclassSerializerRegistry();

	for (Map.Entry<Class<?>, TypeSerializerSnapshot<?>> entry : unwrappedSerializerSnapshots.entrySet()) {
		TypeSerializer<?> newRegisteredSerializer = newSubclassSerializerRegistry.get(entry.getKey());
		if (newRegisteredSerializer != null) {
			associatedSubclassSerializerSnapshots.add(entry.getValue());
			associatedNewSubclassSerializers.add(newRegisteredSerializer);
		}
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewSubclassSerializers.toArray(new TypeSerializer<?>[associatedNewSubclassSerializers.size()]),
		associatedSubclassSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedSubclassSerializerSnapshots.size()]));
}
 
Example #2
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a reconfigured version of the {@link PojoSerializer}.
 *
 * @param originalNewPojoSerializer the original new {@link PojoSerializer} to create a reconfigured version of.
 * @param fieldSerializerCompatibility compatibility of preexisting fields' serializers.
 * @param registeredSerializerSnapshots snapshot of previous registered subclasses' serializers.
 * @param preExistingRegistrationsCompatibility compatibility of preexisting subclasses' serializers.
 * @param nonRegisteredSubclassSerializerSnapshots snapshot of previous non-registered subclasses' serializers.
 *
 * @return a reconfigured version of the original new {@link PojoSerializer}.
 */
private static <T> PojoSerializer<T> constructReconfiguredPojoSerializer(
		PojoSerializer<T> originalNewPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	@SuppressWarnings("unchecked")
	final TypeSerializer<Object>[] reconfiguredFieldSerializers = constructReconfiguredFieldSerializers(fieldSerializerCompatibility);

	Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> reconfiguredSubclassRegistry = constructReconfiguredSubclassRegistry(
		originalNewPojoSerializer.getBundledSubclassSerializerRegistry(),
		registeredSerializerSnapshots,
		preExistingRegistrationsCompatibility);

	return new PojoSerializer<>(
		originalNewPojoSerializer.getPojoClass(),
		originalNewPojoSerializer.getFields(),
		reconfiguredFieldSerializers,
		reconfiguredSubclassRegistry.f0,
		reconfiguredSubclassRegistry.f1,
		restoreSerializers(nonRegisteredSubclassSerializerSnapshots.unwrapOptionals()),
		originalNewPojoSerializer.getExecutionConfig());
}
 
Example #3
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Finds which registered subclasses exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of this preexisting registered subclasses.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingRegisteredSubclasses(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots) {

	final LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> unwrappedSerializerSnapshots = registeredSubclassSerializerSnapshots.unwrapOptionals();

	final ArrayList<TypeSerializerSnapshot<?>> associatedSubclassSerializerSnapshots = new ArrayList<>();
	final ArrayList<TypeSerializer<?>> associatedNewSubclassSerializers = new ArrayList<>();

	final LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassSerializerRegistry = newPojoSerializer.getBundledSubclassSerializerRegistry();

	for (Map.Entry<Class<?>, TypeSerializerSnapshot<?>> entry : unwrappedSerializerSnapshots.entrySet()) {
		TypeSerializer<?> newRegisteredSerializer = newSubclassSerializerRegistry.get(entry.getKey());
		if (newRegisteredSerializer != null) {
			associatedSubclassSerializerSnapshots.add(entry.getValue());
			associatedNewSubclassSerializers.add(newRegisteredSerializer);
		}
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewSubclassSerializers.toArray(new TypeSerializer<?>[associatedNewSubclassSerializers.size()]),
		associatedSubclassSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedSubclassSerializerSnapshots.size()]));
}
 
Example #4
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a reconfigured version of the {@link PojoSerializer}.
 *
 * @param originalNewPojoSerializer the original new {@link PojoSerializer} to create a reconfigured version of.
 * @param fieldSerializerCompatibility compatibility of preexisting fields' serializers.
 * @param registeredSerializerSnapshots snapshot of previous registered subclasses' serializers.
 * @param preExistingRegistrationsCompatibility compatibility of preexisting subclasses' serializers.
 * @param nonRegisteredSubclassSerializerSnapshots snapshot of previous non-registered subclasses' serializers.
 *
 * @return a reconfigured version of the original new {@link PojoSerializer}.
 */
private static <T> PojoSerializer<T> constructReconfiguredPojoSerializer(
		PojoSerializer<T> originalNewPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	@SuppressWarnings("unchecked")
	final TypeSerializer<Object>[] reconfiguredFieldSerializers = constructReconfiguredFieldSerializers(fieldSerializerCompatibility);

	Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> reconfiguredSubclassRegistry = constructReconfiguredSubclassRegistry(
		originalNewPojoSerializer.getBundledSubclassSerializerRegistry(),
		registeredSerializerSnapshots,
		preExistingRegistrationsCompatibility);

	return new PojoSerializer<>(
		originalNewPojoSerializer.getPojoClass(),
		originalNewPojoSerializer.getFields(),
		reconfiguredFieldSerializers,
		reconfiguredSubclassRegistry.f0,
		reconfiguredSubclassRegistry.f1,
		restoreSerializers(nonRegisteredSubclassSerializerSnapshots.unwrapOptionals()),
		originalNewPojoSerializer.getExecutionConfig());
}
 
Example #5
Source File: PojoSerializerSnapshot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> constructReconfiguredSubclassRegistry(
		LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassRegistrations,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<?> preExistingRegistrationsCompatibility) {

	checkArgument(!preExistingRegistrationsCompatibility.isIncompatible() && !preExistingRegistrationsCompatibility.isCompatibleAfterMigration());

	LinkedHashMap<Class<?>, TypeSerializer<?>> reconfiguredSubclassSerializerRegistry =
		restoreSerializers(registeredSerializerSnapshots.unwrapOptionals());

	Iterator<TypeSerializer<?>> serializersForPreexistingRegistrations =
		Arrays.asList(preExistingRegistrationsCompatibility.getNestedSerializers()).iterator();

	for (Map.Entry<Class<?>, TypeSerializer<?>> registration : newSubclassRegistrations.entrySet()) {
		// new registrations should simply be appended to the subclass serializer registry with their new serializers;
		// preexisting registrations should use the compatibility-checked serializer
		TypeSerializer<?> newRegistration = (reconfiguredSubclassSerializerRegistry.containsKey(registration.getKey()))
			? serializersForPreexistingRegistrations.next()
			: registration.getValue();
		reconfiguredSubclassSerializerRegistry.put(registration.getKey(), newRegistration);
	}

	return decomposeSubclassSerializerRegistry(reconfiguredSubclassSerializerRegistry);
}
 
Example #6
Source File: PojoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static <T> PojoSerializerSnapshotData<T> readSnapshotData(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	Class<T> pojoClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);

	LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = readOptionalMap(
		in,
		fieldReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));

	return new PojoSerializerSnapshotData<>(pojoClass, fieldSerializerSnapshots, registeredSubclassSerializerSnapshots, nonRegisteredSubclassSerializerSnapshots);
}
 
Example #7
Source File: PojoSerializerSnapshotData.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link PojoSerializerSnapshotData} from existing snapshotted configuration of a {@link PojoSerializer}.
 */
static <T> PojoSerializerSnapshotData<T> createFrom(
		Class<T> pojoClass,
		Field[] fields,
		TypeSerializerSnapshot<?>[] existingFieldSerializerSnapshots,
		LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> existingRegisteredSubclassSerializerSnapshots,
		Map<Class<?>, TypeSerializerSnapshot<?>> existingNonRegisteredSubclassSerializerSnapshots) {

	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = new LinkedOptionalMap<>(fields.length);
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		String fieldName = (field == null) ? getDummyNameForMissingField(i) : field.getName();
		fieldSerializerSnapshots.put(fieldName, field, existingFieldSerializerSnapshots[i]);
	}

	return new PojoSerializerSnapshotData<>(
		pojoClass,
		fieldSerializerSnapshots,
		optionalMapOf(existingRegisteredSubclassSerializerSnapshots, Class::getName),
		optionalMapOf(existingNonRegisteredSubclassSerializerSnapshots, Class::getName));
}
 
Example #8
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link PojoSerializerSnapshotData} from existing snapshotted configuration of a {@link PojoSerializer}.
 */
static <T> PojoSerializerSnapshotData<T> createFrom(
		Class<T> pojoClass,
		Field[] fields,
		TypeSerializerSnapshot<?>[] existingFieldSerializerSnapshots,
		LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> existingRegisteredSubclassSerializerSnapshots,
		Map<Class<?>, TypeSerializerSnapshot<?>> existingNonRegisteredSubclassSerializerSnapshots) {

	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = new LinkedOptionalMap<>(fields.length);
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		String fieldName = (field == null) ? getDummyNameForMissingField(i) : field.getName();
		fieldSerializerSnapshots.put(fieldName, field, existingFieldSerializerSnapshots[i]);
	}

	return new PojoSerializerSnapshotData<>(
		pojoClass,
		fieldSerializerSnapshots,
		optionalMapOf(existingRegisteredSubclassSerializerSnapshots, Class::getName),
		optionalMapOf(existingNonRegisteredSubclassSerializerSnapshots, Class::getName));
}
 
Example #9
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> PojoSerializerSnapshotData<T> readSnapshotData(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	Class<T> pojoClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);

	LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = readOptionalMap(
		in,
		fieldReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));

	return new PojoSerializerSnapshotData<>(pojoClass, fieldSerializerSnapshots, registeredSubclassSerializerSnapshots, nonRegisteredSubclassSerializerSnapshots);
}
 
Example #10
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> PojoSerializerSnapshotData<T> readSnapshotData(DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
	Class<T> pojoClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);

	LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = readOptionalMap(
		in,
		fieldReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));
	LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = readOptionalMap(
		in,
		classReader(userCodeClassLoader),
		snapshotReader(userCodeClassLoader));

	return new PojoSerializerSnapshotData<>(pojoClass, fieldSerializerSnapshots, registeredSubclassSerializerSnapshots, nonRegisteredSubclassSerializerSnapshots);
}
 
Example #11
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Finds which registered subclasses exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of this preexisting registered subclasses.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingRegisteredSubclasses(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots) {

	final LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> unwrappedSerializerSnapshots = registeredSubclassSerializerSnapshots.unwrapOptionals();

	final ArrayList<TypeSerializerSnapshot<?>> associatedSubclassSerializerSnapshots = new ArrayList<>();
	final ArrayList<TypeSerializer<?>> associatedNewSubclassSerializers = new ArrayList<>();

	final LinkedHashMap<Class<?>, TypeSerializer<?>> newSubclassSerializerRegistry = newPojoSerializer.getBundledSubclassSerializerRegistry();

	for (Map.Entry<Class<?>, TypeSerializerSnapshot<?>> entry : unwrappedSerializerSnapshots.entrySet()) {
		TypeSerializer<?> newRegisteredSerializer = newSubclassSerializerRegistry.get(entry.getKey());
		if (newRegisteredSerializer != null) {
			associatedSubclassSerializerSnapshots.add(entry.getValue());
			associatedNewSubclassSerializers.add(newRegisteredSerializer);
		}
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewSubclassSerializers.toArray(new TypeSerializer<?>[associatedNewSubclassSerializers.size()]),
		associatedSubclassSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedSubclassSerializerSnapshots.size()]));
}
 
Example #12
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link PojoSerializerSnapshotData} from existing snapshotted configuration of a {@link PojoSerializer}.
 */
static <T> PojoSerializerSnapshotData<T> createFrom(
		Class<T> pojoClass,
		Field[] fields,
		TypeSerializerSnapshot<?>[] existingFieldSerializerSnapshots,
		LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> existingRegisteredSubclassSerializerSnapshots,
		Map<Class<?>, TypeSerializerSnapshot<?>> existingNonRegisteredSubclassSerializerSnapshots) {

	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = new LinkedOptionalMap<>(fields.length);
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		String fieldName = (field == null) ? getDummyNameForMissingField(i) : field.getName();
		fieldSerializerSnapshots.put(fieldName, field, existingFieldSerializerSnapshots[i]);
	}

	return new PojoSerializerSnapshotData<>(
		pojoClass,
		fieldSerializerSnapshots,
		optionalMapOf(existingRegisteredSubclassSerializerSnapshots, Class::getName),
		optionalMapOf(existingNonRegisteredSubclassSerializerSnapshots, Class::getName));
}
 
Example #13
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a reconfigured version of the {@link PojoSerializer}.
 *
 * @param originalNewPojoSerializer the original new {@link PojoSerializer} to create a reconfigured version of.
 * @param fieldSerializerCompatibility compatibility of preexisting fields' serializers.
 * @param registeredSerializerSnapshots snapshot of previous registered subclasses' serializers.
 * @param preExistingRegistrationsCompatibility compatibility of preexisting subclasses' serializers.
 * @param nonRegisteredSubclassSerializerSnapshots snapshot of previous non-registered subclasses' serializers.
 *
 * @return a reconfigured version of the original new {@link PojoSerializer}.
 */
private static <T> PojoSerializer<T> constructReconfiguredPojoSerializer(
		PojoSerializer<T> originalNewPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSerializerSnapshots,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	@SuppressWarnings("unchecked")
	final TypeSerializer<Object>[] reconfiguredFieldSerializers = constructReconfiguredFieldSerializers(fieldSerializerCompatibility);

	Tuple2<LinkedHashMap<Class<?>, Integer>, TypeSerializer<Object>[]> reconfiguredSubclassRegistry = constructReconfiguredSubclassRegistry(
		originalNewPojoSerializer.getBundledSubclassSerializerRegistry(),
		registeredSerializerSnapshots,
		preExistingRegistrationsCompatibility);

	return new PojoSerializer<>(
		originalNewPojoSerializer.getPojoClass(),
		originalNewPojoSerializer.getFields(),
		reconfiguredFieldSerializers,
		reconfiguredSubclassRegistry.f0,
		reconfiguredSubclassRegistry.f1,
		restoreSerializers(nonRegisteredSubclassSerializerSnapshots.unwrapOptionals()),
		originalNewPojoSerializer.getExecutionConfig());
}
 
Example #14
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the new {@link PojoSerializer} has new or removed fields compared to the previous one.
 */
private static boolean newPojoHasNewOrRemovedFields(
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots,
		PojoSerializer<?> newPojoSerializer) {
	int numRemovedFields = fieldSerializerSnapshots.absentKeysOrValues().size();
	int numPreexistingFields = fieldSerializerSnapshots.size() - numRemovedFields;

	boolean hasRemovedFields = numRemovedFields > 0;
	boolean hasNewFields = newPojoSerializer.getFields().length - numPreexistingFields > 0;
	return hasRemovedFields || hasNewFields;
}
 
Example #15
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible with a reconfigured instance.
 */
private static <T> boolean newPojoSerializerIsCompatibleWithReconfiguredSerializer(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {
	return newPojoHasDifferentSubclassRegistrationOrder(registeredSubclassSerializerSnapshots, newPojoSerializer)
		|| previousSerializerHasNonRegisteredSubclasses(nonRegisteredSubclassSerializerSnapshots)
		|| fieldSerializerCompatibility.isCompatibleWithReconfiguredSerializer()
		|| preExistingRegistrationsCompatibility.isCompatibleWithReconfiguredSerializer();
}
 
Example #16
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 #17
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Finds which Pojo fields exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of those preexisting fields.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingFields(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {

	// the present entries dictates the preexisting fields, because removed fields would be
	// represented as absent keys in the optional map.
	final Set<LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>>> presentFieldSnapshots =
		fieldSerializerSnapshots.getPresentEntries();

	final ArrayList<TypeSerializerSnapshot<?>> associatedFieldSerializerSnapshots = new ArrayList<>(presentFieldSnapshots.size());
	final ArrayList<TypeSerializer<?>> associatedNewFieldSerializers = new ArrayList<>(presentFieldSnapshots.size());

	final Map<Field, TypeSerializer<?>> newFieldSerializersIndex = buildNewFieldSerializersIndex(newPojoSerializer);
	for (LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>> presentFieldEntry : presentFieldSnapshots) {
		TypeSerializer<?> associatedNewFieldSerializer = newFieldSerializersIndex.get(presentFieldEntry.getKey());
		checkState(
			associatedNewFieldSerializer != null,
			"a present field should have its associated new field serializer available.");

		associatedFieldSerializerSnapshots.add(presentFieldEntry.getValue());
		associatedNewFieldSerializers.add(associatedNewFieldSerializer);
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewFieldSerializers.toArray(new TypeSerializer<?>[associatedNewFieldSerializers.size()]),
		associatedFieldSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedFieldSerializerSnapshots.size()]));
}
 
Example #18
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> readDefaultKryoSerializerClasses(
	DataInputView in,
	ClassLoader cl) throws IOException {

	return readOptionalMap(in, new ClassResolverByName(cl), new ClassResolverByName<Serializer<?>>(cl));
}
 
Example #19
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private PojoSerializerSnapshotData(
		Class<T> typeClass,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	this.pojoClass = checkNotNull(typeClass);
	this.fieldSerializerSnapshots = checkNotNull(fieldSerializerSnapshots);
	this.registeredSubclassSerializerSnapshots = checkNotNull(registeredSubclassSerializerSnapshots);
	this.nonRegisteredSubclassSerializerSnapshots = checkNotNull(nonRegisteredSubclassSerializerSnapshots);
}
 
Example #20
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link PojoSerializerSnapshotData} from configuration of a {@link PojoSerializer}.
 *
 * <p>This factory method is meant to be used in regular write paths, i.e. when taking a snapshot
 * of the {@link PojoSerializer}. All registered subclass classes, and non-registered
 * subclass classes are all present. Some POJO fields may be absent, if the originating
 * {@link PojoSerializer} was a restored one with already missing fields, and was never replaced
 * by a new {@link PojoSerializer} (i.e. because the serialized old data was never accessed).
 */
static <T> PojoSerializerSnapshotData<T> createFrom(
		Class<T> pojoClass,
		Field[] fields,
		TypeSerializer<?>[] fieldSerializers,
		LinkedHashMap<Class<?>, TypeSerializer<?>> registeredSubclassSerializers,
		Map<Class<?>, TypeSerializer<?>> nonRegisteredSubclassSerializers) {

	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = new LinkedOptionalMap<>(fields.length);

	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		String fieldName = (field == null) ? getDummyNameForMissingField(i) : field.getName();
		fieldSerializerSnapshots.put(fieldName, field, TypeSerializerUtils.snapshotBackwardsCompatible(fieldSerializers[i]));
	}

	LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = new LinkedHashMap<>(registeredSubclassSerializers.size());
	registeredSubclassSerializers.forEach((k, v) -> registeredSubclassSerializerSnapshots.put(k, TypeSerializerUtils.snapshotBackwardsCompatible(v)));

	Map<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = new HashMap<>(nonRegisteredSubclassSerializers.size());
	nonRegisteredSubclassSerializers.forEach((k, v) -> nonRegisteredSubclassSerializerSnapshots.put(k, TypeSerializerUtils.snapshotBackwardsCompatible(v)));

	return new PojoSerializerSnapshotData<>(
		pojoClass,
		fieldSerializerSnapshots,
		optionalMapOf(registeredSubclassSerializerSnapshots, Class::getName),
		optionalMapOf(nonRegisteredSubclassSerializerSnapshots, Class::getName));
}
 
Example #21
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible after migration.
 */
private static <T> boolean newPojoSerializerIsCompatibleAfterMigration(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {
	return newPojoHasNewOrRemovedFields(fieldSerializerSnapshots, newPojoSerializer)
		|| fieldSerializerCompatibility.isCompatibleAfterMigration()
		|| preExistingRegistrationsCompatibility.isCompatibleAfterMigration();
}
 
Example #22
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void writeKryoRegistrations(
	DataOutputView out,
	LinkedOptionalMap<String, KryoRegistration> kryoRegistrations) throws IOException {

	writeOptionalMap(
		out,
		kryoRegistrations,
		DataOutput::writeUTF,
		KryoRegistrationUtil::writeKryoRegistration);
}
 
Example #23
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the new {@link PojoSerializer} has a different subclass registration order
 * compared to the previous one.
 */
private static boolean newPojoHasDifferentSubclassRegistrationOrder(
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		PojoSerializer<?> newPojoSerializer) {
	Set<Class<?>> previousRegistrationOrder = registeredSubclassSerializerSnapshots.unwrapOptionals().keySet();
	Set<Class<?>> newRegistrationOrder = newPojoSerializer.getRegisteredClasses().keySet();
	return !isPreviousRegistrationPrefixOfNewRegistration(previousRegistrationOrder, newRegistrationOrder);
}
 
Example #24
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the new {@link PojoSerializer} has new or removed fields compared to the previous one.
 */
private static boolean newPojoHasNewOrRemovedFields(
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots,
		PojoSerializer<?> newPojoSerializer) {
	int numRemovedFields = fieldSerializerSnapshots.absentKeysOrValues().size();
	int numPreexistingFields = fieldSerializerSnapshots.size() - numRemovedFields;

	boolean hasRemovedFields = numRemovedFields > 0;
	boolean hasNewFields = newPojoSerializer.getFields().length - numPreexistingFields > 0;
	return hasRemovedFields || hasNewFields;
}
 
Example #25
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible with a reconfigured instance.
 */
private static <T> boolean newPojoSerializerIsCompatibleWithReconfiguredSerializer(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {
	return newPojoHasDifferentSubclassRegistrationOrder(registeredSubclassSerializerSnapshots, newPojoSerializer)
		|| previousSerializerHasNonRegisteredSubclasses(nonRegisteredSubclassSerializerSnapshots)
		|| fieldSerializerCompatibility.isCompatibleWithReconfiguredSerializer()
		|| preExistingRegistrationsCompatibility.isCompatibleWithReconfiguredSerializer();
}
 
Example #26
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the new {@link PojoSerializer} is compatible after migration.
 */
private static <T> boolean newPojoSerializerIsCompatibleAfterMigration(
		PojoSerializer<T> newPojoSerializer,
		IntermediateCompatibilityResult<T> fieldSerializerCompatibility,
		IntermediateCompatibilityResult<T> preExistingRegistrationsCompatibility,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {
	return newPojoHasNewOrRemovedFields(fieldSerializerSnapshots, newPojoSerializer)
		|| fieldSerializerCompatibility.isCompatibleAfterMigration()
		|| preExistingRegistrationsCompatibility.isCompatibleAfterMigration();
}
 
Example #27
Source File: PojoSerializerSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Finds which Pojo fields exists both in the new {@link PojoSerializer} as well as in the previous one
 * (represented by this snapshot), and returns an {@link IntermediateCompatibilityResult}
 * of the serializers of those preexisting fields.
 */
private static <T> IntermediateCompatibilityResult<T> getCompatibilityOfPreExistingFields(
		PojoSerializer<T> newPojoSerializer,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots) {

	// the present entries dictates the preexisting fields, because removed fields would be
	// represented as absent keys in the optional map.
	final Set<LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>>> presentFieldSnapshots =
		fieldSerializerSnapshots.getPresentEntries();

	final ArrayList<TypeSerializerSnapshot<?>> associatedFieldSerializerSnapshots = new ArrayList<>(presentFieldSnapshots.size());
	final ArrayList<TypeSerializer<?>> associatedNewFieldSerializers = new ArrayList<>(presentFieldSnapshots.size());

	final Map<Field, TypeSerializer<?>> newFieldSerializersIndex = buildNewFieldSerializersIndex(newPojoSerializer);
	for (LinkedOptionalMap.KeyValue<Field, TypeSerializerSnapshot<?>> presentFieldEntry : presentFieldSnapshots) {
		TypeSerializer<?> associatedNewFieldSerializer = newFieldSerializersIndex.get(presentFieldEntry.getKey());
		checkState(
			associatedNewFieldSerializer != null,
			"a present field should have its associated new field serializer available.");

		associatedFieldSerializerSnapshots.add(presentFieldEntry.getValue());
		associatedNewFieldSerializers.add(associatedNewFieldSerializer);
	}

	return CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(
		associatedNewFieldSerializers.toArray(new TypeSerializer<?>[associatedNewFieldSerializers.size()]),
		associatedFieldSerializerSnapshots.toArray(new TypeSerializerSnapshot<?>[associatedFieldSerializerSnapshots.size()]));
}
 
Example #28
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
private PojoSerializerSnapshotData(
		Class<T> typeClass,
		LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots,
		LinkedOptionalMap<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots) {

	this.pojoClass = checkNotNull(typeClass);
	this.fieldSerializerSnapshots = checkNotNull(fieldSerializerSnapshots);
	this.registeredSubclassSerializerSnapshots = checkNotNull(registeredSubclassSerializerSnapshots);
	this.nonRegisteredSubclassSerializerSnapshots = checkNotNull(nonRegisteredSubclassSerializerSnapshots);
}
 
Example #29
Source File: PojoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link PojoSerializerSnapshotData} from configuration of a {@link PojoSerializer}.
 *
 * <p>This factory method is meant to be used in regular write paths, i.e. when taking a snapshot
 * of the {@link PojoSerializer}. All registered subclass classes, and non-registered
 * subclass classes are all present. Some POJO fields may be absent, if the originating
 * {@link PojoSerializer} was a restored one with already missing fields, and was never replaced
 * by a new {@link PojoSerializer} (i.e. because the serialized old data was never accessed).
 */
static <T> PojoSerializerSnapshotData<T> createFrom(
		Class<T> pojoClass,
		Field[] fields,
		TypeSerializer<?>[] fieldSerializers,
		LinkedHashMap<Class<?>, TypeSerializer<?>> registeredSubclassSerializers,
		Map<Class<?>, TypeSerializer<?>> nonRegisteredSubclassSerializers) {

	final LinkedOptionalMap<Field, TypeSerializerSnapshot<?>> fieldSerializerSnapshots = new LinkedOptionalMap<>(fields.length);

	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		String fieldName = (field == null) ? getDummyNameForMissingField(i) : field.getName();
		fieldSerializerSnapshots.put(fieldName, field, TypeSerializerUtils.snapshotBackwardsCompatible(fieldSerializers[i]));
	}

	LinkedHashMap<Class<?>, TypeSerializerSnapshot<?>> registeredSubclassSerializerSnapshots = new LinkedHashMap<>(registeredSubclassSerializers.size());
	registeredSubclassSerializers.forEach((k, v) -> registeredSubclassSerializerSnapshots.put(k, TypeSerializerUtils.snapshotBackwardsCompatible(v)));

	Map<Class<?>, TypeSerializerSnapshot<?>> nonRegisteredSubclassSerializerSnapshots = new HashMap<>(nonRegisteredSubclassSerializers.size());
	nonRegisteredSubclassSerializers.forEach((k, v) -> nonRegisteredSubclassSerializerSnapshots.put(k, TypeSerializerUtils.snapshotBackwardsCompatible(v)));

	return new PojoSerializerSnapshotData<>(
		pojoClass,
		fieldSerializerSnapshots,
		optionalMapOf(registeredSubclassSerializerSnapshots, Class::getName),
		optionalMapOf(nonRegisteredSubclassSerializerSnapshots, Class::getName));
}
 
Example #30
Source File: KryoSerializerSnapshotData.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedOptionalMap<Class<?>, Class<? extends Serializer<?>>> readDefaultKryoSerializerClasses(
	DataInputView in,
	ClassLoader cl) throws IOException {

	return readOptionalMap(in, new ClassResolverByName(cl), new ClassResolverByName<Serializer<?>>(cl));
}