/** * Constructor to create the snapshot for writing. */ public EitherSerializerSnapshot( TypeSerializer<L> leftSerializer, TypeSerializer<R> rightSerializer) { this.nestedSnapshot = new NestedSerializersSnapshotDelegate(leftSerializer, rightSerializer); }
@Override public final TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) { return internalResolveSchemaCompatibility(newSerializer, nestedSerializersSnapshotDelegate.getNestedSerializerSnapshots()); }
@Override public EitherSerializer<L, R> restoreSerializer() { checkState(nestedSnapshot != null); return new EitherSerializer<>( nestedSnapshot.getRestoredNestedSerializer(0), nestedSnapshot.getRestoredNestedSerializer(1)); }
@Override public final void writeSnapshot(DataOutputView out) throws IOException { internalWriteOuterSnapshot(out); nestedSerializersSnapshotDelegate.writeNestedSerializerSnapshots(out); }
private void readV2(DataInputView in, ClassLoader classLoader) throws IOException { nestedSnapshot = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(in, classLoader); }
private void readV1(DataInputView in, ClassLoader classLoader) throws IOException { nestedSnapshot = NestedSerializersSnapshotDelegate.legacyReadNestedSerializerSnapshots(in, classLoader); }
/** * Produces a restore serializer from each contained serializer configuration snapshot. * The serializers are returned in the same order as the snapshots are stored. */ public TypeSerializer<?>[] getRestoredNestedSerializers() { return snapshotsToRestoreSerializers(nestedSnapshots); }
@Override public final TypeSerializer<T> restoreSerializer() { @SuppressWarnings("unchecked") TypeSerializer<T> serializer = (TypeSerializer<T>) createOuterSerializerWithNestedSerializers(nestedSerializersSnapshotDelegate.getRestoredNestedSerializers()); return serializer; }
for (int i = 0; i < nestedSnapshots.length; i++) { TypeSerializerSchemaCompatibility<?> compatibility = resolveCompatibility(newNestedSerializers[i], nestedSnapshots[i]);
@Override public void writeSnapshot(DataOutputView out) throws IOException { checkState(nestedSnapshot != null); nestedSnapshot.writeNestedSerializerSnapshots(out); }
private void readV2(DataInputView in, ClassLoader classLoader) throws IOException { componentClass = InstantiationUtil.resolveClassByName(in, classLoader); nestedSnapshot = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(in, classLoader); }
private void readV1(DataInputView in, ClassLoader classLoader) throws IOException { nestedSnapshot = NestedSerializersSnapshotDelegate.legacyReadNestedSerializerSnapshots(in, classLoader); try (DataInputViewStream inViewWrapper = new DataInputViewStream(in)) { componentClass = InstantiationUtil.deserializeObject(inViewWrapper, classLoader); } catch (ClassNotFoundException e) { throw new IOException("Could not find requested element class in classpath.", e); } }
/** * Reads the composite snapshot of all the contained serializers in a way that is compatible * with Version 1 of the deprecated {@link CompositeTypeSerializerConfigSnapshot}. */ public static NestedSerializersSnapshotDelegate legacyReadNestedSerializerSnapshots(DataInputView in, ClassLoader cl) throws IOException { @SuppressWarnings("deprecation") final List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndSnapshots = TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, cl); final TypeSerializerSnapshot<?>[] nestedSnapshots = serializersAndSnapshots.stream() .map(t -> t.f1) .toArray(TypeSerializerSnapshot<?>[]::new); return new NestedSerializersSnapshotDelegate(nestedSnapshots); }
@Override public TypeSerializerSchemaCompatibility<C[]> resolveSchemaCompatibility(TypeSerializer<C[]> newSerializer) { checkState(nestedSnapshot != null); if (!(newSerializer instanceof GenericArraySerializer)) { return TypeSerializerSchemaCompatibility.incompatible(); } // delegate to the new snapshot class return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot( newSerializer, new GenericArraySerializerSnapshot<>(componentClass), nestedSnapshot.getNestedSerializerSnapshots()); } }
@Override public void writeSnapshot(DataOutputView out) throws IOException { checkState(componentClass != null && nestedSnapshot != null); out.writeUTF(componentClass.getName()); nestedSnapshot.writeNestedSerializerSnapshots(out); }
@Override public final void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException { if (readVersion > HIGHEST_LEGACY_READ_VERSION) { internalReadOuterSnapshot(in, userCodeClassLoader); } else { legacyInternalReadOuterSnapshot(readVersion, in, userCodeClassLoader); } this.nestedSerializersSnapshotDelegate = NestedSerializersSnapshotDelegate.readNestedSerializerSnapshots(in, userCodeClassLoader); }
@Override public GenericArraySerializer<C> restoreSerializer() { checkState(componentClass != null && nestedSnapshot != null); return new GenericArraySerializer<>(componentClass, nestedSnapshot.getRestoredNestedSerializer(0)); }
/** * Constructor to be used for writing the snapshot. * * @param serializerInstance an instance of the originating serializer of this snapshot. */ @SuppressWarnings("unchecked") public CompositeTypeSerializerSnapshot(S serializerInstance) { Preconditions.checkNotNull(serializerInstance); this.nestedSerializersSnapshotDelegate = new NestedSerializersSnapshotDelegate(getNestedSerializers(serializerInstance)); this.correspondingSerializerClass = (Class<S>) serializerInstance.getClass(); }
@Override public TypeSerializerSchemaCompatibility<Either<L, R>> resolveSchemaCompatibility( TypeSerializer<Either<L, R>> newSerializer) { checkState(nestedSnapshot != null); if (newSerializer instanceof EitherSerializer) { // delegate compatibility check to the new snapshot class return CompositeTypeSerializerUtil.delegateCompatibilityCheckToNewSnapshot( newSerializer, new JavaEitherSerializerSnapshot<>(), nestedSnapshot.getNestedSerializerSnapshots()); } else { return TypeSerializerSchemaCompatibility.incompatible(); } } }
/** * Constructor to create the snapshot for writing. */ public GenericArraySerializerConfigSnapshot(GenericArraySerializer<C> serializer) { this.componentClass = serializer.getComponentClass(); this.nestedSnapshot = new NestedSerializersSnapshotDelegate(serializer.getComponentSerializer()); }