@Override public final TypeSerializer<T> restoreSerializer() { @SuppressWarnings("unchecked") TypeSerializer<T> serializer = (TypeSerializer<T>) createOuterSerializerWithNestedSerializers(nestedSerializersSnapshotDelegate.getRestoredNestedSerializers()); return serializer; }
private void internalWriteOuterSnapshot(DataOutputView out) throws IOException { out.writeInt(MAGIC_NUMBER); out.writeInt(getCurrentOuterSnapshotVersion()); writeOuterSnapshot(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); }
@Internal TypeSerializerSchemaCompatibility<T> internalResolveSchemaCompatibility( TypeSerializer<T> newSerializer, TypeSerializerSnapshot<?>[] snapshots) { if (newSerializer.getClass() != correspondingSerializerClass) { return TypeSerializerSchemaCompatibility.incompatible(); } S castedNewSerializer = correspondingSerializerClass.cast(newSerializer); // check that outer configuration is compatible; if not, short circuit result if (!isOuterSnapshotCompatible(castedNewSerializer)) { return TypeSerializerSchemaCompatibility.incompatible(); } return constructFinalSchemaCompatibilityResult( getNestedSerializers(castedNewSerializer), snapshots); }
for (int i = 0; i < nestedSerializerSnapshots.length; i++) { TypeSerializerSchemaCompatibility<?> compatibility = resolveCompatibility(newNestedSerializers[i], nestedSerializerSnapshots[i]); TypeSerializer<T> reconfiguredCompositeSerializer = createOuterSerializerWithNestedSerializers(reconfiguredNestedSerializers); return TypeSerializerSchemaCompatibility.compatibleWithReconfiguredSerializer(reconfiguredCompositeSerializer);
private void legacyInternalReadOuterSnapshot( int legacyReadVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException { // legacy versions did not contain the pre-fixed magic numbers; just read the outer snapshot readOuterSnapshot(legacyReadVersion, in, userCodeClassLoader); }
@Override public final TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer) { return internalResolveSchemaCompatibility(newSerializer, nestedSerializersSnapshotDelegate.getNestedSerializerSnapshots()); }
@Override public final void writeSnapshot(DataOutputView out) throws IOException { internalWriteOuterSnapshot(out); nestedSerializersSnapshotDelegate.writeNestedSerializerSnapshots(out); }
/** * 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(); }
private void internalReadOuterSnapshot(DataInputView in, ClassLoader userCodeClassLoader) throws IOException { final int magicNumber = in.readInt(); if (magicNumber != MAGIC_NUMBER) { throw new IOException(String.format("Corrupt data, magic number mismatch. Expected %8x, found %8x", MAGIC_NUMBER, magicNumber)); } final int outerSnapshotVersion = in.readInt(); readOuterSnapshot(outerSnapshotVersion, in, userCodeClassLoader); }
/** * Delegates compatibility checks to a {@link CompositeTypeSerializerSnapshot} instance. * This can be used by legacy snapshot classes, which have a newer implementation * implemented as a {@link CompositeTypeSerializerSnapshot}. * * @param newSerializer the new serializer to check for compatibility. * @param newCompositeSnapshot an instance of the new snapshot class to delegate compatibility checks to. * This instance should already contain the outer snapshot information. * @param legacyNestedSnapshots the nested serializer snapshots of the legacy composite snapshot. * * @return the result compatibility. */ public static <T> TypeSerializerSchemaCompatibility<T> delegateCompatibilityCheckToNewSnapshot( TypeSerializer<T> newSerializer, CompositeTypeSerializerSnapshot<T, ? extends TypeSerializer> newCompositeSnapshot, TypeSerializerSnapshot<?>... legacyNestedSnapshots) { checkArgument(legacyNestedSnapshots.length > 0); return newCompositeSnapshot.internalResolveSchemaCompatibility(newSerializer, legacyNestedSnapshots); } }