// Extract the serialised wavelet delta
ByteStringMessage<ProtocolWaveletDelta> protocolDelta =
ByteStringMessage.parseProtocolWaveletDelta(
appliedDelta.getMessage().getSignedOriginalDelta().getDelta());
WaveletDelta delta = CoreWaveletOperationSerializer.deserialize(protocolDelta.getMessage());
// Transform operations against earlier deltas, if necessary
WaveletDelta transformed = maybeTransformSubmittedDelta(delta);
if (transformed.getTargetVersion().equals(delta.getTargetVersion())) {
// No transformation took place.
// As a sanity check, the hash from the applied delta should NOT be set (an optimisation, but
// part of the protocol).
if (appliedDelta.getMessage().hasHashedVersionAppliedAt()) {
LOG.warning("Hashes are the same but applied delta has hashed_version_applied_at");
// TODO: re-enable this exception for version 0.3 of the spec
// throw new InvalidHashException("Applied delta and its contained delta have same hash");
}
}
if (transformed.size() == 0) {
// The host shouldn't be forwarding empty deltas!
markStateCorrupted();
throw new WaveServerException("Couldn't apply authoritative delta, " +
"it transformed away at version " + transformed.getTargetVersion().getVersion());
}
if (!transformed.getTargetVersion().equals(hashedVersion)) {
markStateCorrupted();
throw new WaveServerException("Couldn't apply authoritative delta, " +
"it transformed to wrong version. Expected " + hashedVersion +
", actual " + transformed.getTargetVersion().getVersion());
}
// Apply the delta to the local wavelet state.
// This shouldn't fail since the delta is from the authoritative server, so if it fails
// then the wavelet is corrupted (and the caller of this method will sort it out).