org.apache.flink.api.common.typeutils.TypeSerializerUtils Java Examples

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializerUtils. 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: PojoSerializerSnapshotData.java    From Flink-CEPplus 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 #2
Source File: InternalTimersSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/** Constructor to use when snapshotting the timers. */
public InternalTimersSnapshot(
		TypeSerializer<K> keySerializer,
		TypeSerializer<N> namespaceSerializer,
		@Nullable Set<TimerHeapInternalTimer<K, N>> eventTimeTimers,
		@Nullable Set<TimerHeapInternalTimer<K, N>> processingTimeTimers) {

	Preconditions.checkNotNull(keySerializer);
	this.keySerializerSnapshot = TypeSerializerUtils.snapshotBackwardsCompatible(keySerializer);
	Preconditions.checkNotNull(namespaceSerializer);
	this.namespaceSerializerSnapshot = TypeSerializerUtils.snapshotBackwardsCompatible(namespaceSerializer);

	this.eventTimeTimers = eventTimeTimers;
	this.processingTimeTimers = processingTimeTimers;
}
 
Example #3
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 #4
Source File: InternalTimersSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Constructor to use when snapshotting the timers. */
public InternalTimersSnapshot(
		TypeSerializer<K> keySerializer,
		TypeSerializer<N> namespaceSerializer,
		@Nullable Set<TimerHeapInternalTimer<K, N>> eventTimeTimers,
		@Nullable Set<TimerHeapInternalTimer<K, N>> processingTimeTimers) {

	Preconditions.checkNotNull(keySerializer);
	this.keySerializerSnapshot = TypeSerializerUtils.snapshotBackwardsCompatible(keySerializer);
	Preconditions.checkNotNull(namespaceSerializer);
	this.namespaceSerializerSnapshot = TypeSerializerUtils.snapshotBackwardsCompatible(namespaceSerializer);

	this.eventTimeTimers = eventTimeTimers;
	this.processingTimeTimers = processingTimeTimers;
}
 
Example #5
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 #6
Source File: InternalTimersSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Constructor to use when snapshotting the timers. */
public InternalTimersSnapshot(
		TypeSerializer<K> keySerializer,
		TypeSerializer<N> namespaceSerializer,
		@Nullable Set<TimerHeapInternalTimer<K, N>> eventTimeTimers,
		@Nullable Set<TimerHeapInternalTimer<K, N>> processingTimeTimers) {

	Preconditions.checkNotNull(keySerializer);
	this.keySerializerSnapshot = TypeSerializerUtils.snapshotBackwardsCompatible(keySerializer);
	Preconditions.checkNotNull(namespaceSerializer);
	this.namespaceSerializerSnapshot = TypeSerializerUtils.snapshotBackwardsCompatible(namespaceSerializer);

	this.eventTimeTimers = eventTimeTimers;
	this.processingTimeTimers = processingTimeTimers;
}