Search in sources :

Example 1 with LinkedOptionalMap

use of org.apache.flink.util.LinkedOptionalMap in project flink by apache.

the class PojoSerializerSnapshotData method createFrom.

/**
 * 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));
}
Also used : Field(java.lang.reflect.Field) LinkedOptionalMap(org.apache.flink.util.LinkedOptionalMap) TypeSerializerSnapshot(org.apache.flink.api.common.typeutils.TypeSerializerSnapshot)

Example 2 with LinkedOptionalMap

use of org.apache.flink.util.LinkedOptionalMap in project flink by apache.

the class PojoSerializerSnapshotData method createFrom.

// ---------------------------------------------------------------------------------------------
// Factory methods
// ---------------------------------------------------------------------------------------------
/**
 * 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));
}
Also used : Field(java.lang.reflect.Field) LinkedOptionalMap(org.apache.flink.util.LinkedOptionalMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TypeSerializerSnapshot(org.apache.flink.api.common.typeutils.TypeSerializerSnapshot) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Field (java.lang.reflect.Field)2 TypeSerializerSnapshot (org.apache.flink.api.common.typeutils.TypeSerializerSnapshot)2 LinkedOptionalMap (org.apache.flink.util.LinkedOptionalMap)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1