@Override public void submitRequest(ParticipantId loggedInUser, WaveletName waveletName, ProtocolWaveletDelta delta, String channelId, SubmitRequestListener listener) { submitRecords.put(waveletName, new SubmitRecord(delta.getOperationCount(), listener)); }
@Override public void submitRequest(ParticipantId loggedInUser, WaveletName waveletName, ProtocolWaveletDelta delta, @Nullable String channelId, SubmitRequestListener listener) { super.submitRequest(loggedInUser, waveletName, delta, channelId, listener); Map<WaveletId, WaveletData> wavelets = waves.get(waveletName.waveId); if (wavelets == null) { wavelets = Maps.newHashMap(); waves.put(waveletName.waveId, wavelets); } WaveletData wavelet = wavelets.get(waveletName.waveletId); if (wavelet == null) { long dummyCreationTime = System.currentTimeMillis(); wavelet = WaveletDataUtil.createEmptyWavelet( waveletName, ParticipantId.ofUnsafe(delta.getAuthor()), HashedVersion.unsigned(0), dummyCreationTime); wavelets.put(waveletName.waveletId, wavelet); } // Add the delta to the history and update the wavelet's version. HashedVersion resultingVersion = updateAndGetVersion(waveletName, delta.getOperationCount()); TransformedWaveletDelta versionedDelta = CoreWaveletOperationSerializer.deserialize(delta, resultingVersion, APP_TIMESTAMP); deltas.put(waveletName, versionedDelta); // Confirm submit success. doSubmitSuccess(waveletName, resultingVersion, APP_TIMESTAMP); // Send an update echoing the submitted delta. Note: the document state is // ignored. waveletUpdate(wavelet, DeltaSequence.of(versionedDelta)); // Send a corresponding update of the index wave. }
/** * Deserializes a {@link ProtocolWaveletDelta} as a transformed wavelet delta. */ public static TransformedWaveletDelta deserialize(ProtocolWaveletDelta delta, HashedVersion resultingVersion, long applicationTimestamp) { ParticipantId author = ParticipantId.ofUnsafe(delta.getAuthor()); int count = delta.getOperationCount(); Preconditions.checkArgument(count > 0, "Cannot deserialize an empty delta"); List<WaveletOperation> ops = Lists.newArrayListWithCapacity(count); if (count > 1) { WaveletOperationContext context = new WaveletOperationContext(author, applicationTimestamp, 1); for (int i = 0; i < count - 1; i++) { ProtocolWaveletOperation op = delta.getOperation(i); ops.add(deserialize(op, context)); } } WaveletOperationContext context = new WaveletOperationContext(author, applicationTimestamp, 1, resultingVersion); ops.add(deserialize(delta.getOperation(count - 1), context)); return new TransformedWaveletDelta(author, resultingVersion, applicationTimestamp, ops); }
Preconditions.checkArgument(delta.getOperationCount() > 0, "empty delta"); + delta.getHashedVersion().getVersion() + " with " + delta.getOperationCount() + " ops");
ByteStringMessage.parseProtocolWaveletDelta(signedDelta.getDelta()).getMessage(); Preconditions.checkArgument(protocolDelta.getOperationCount() > 0, "empty delta");
@Override public void submitRequest(WaveletName waveletName, ProtocolWaveletDelta delta, final SubmitRequestListener listener) { Preconditions.checkState(initialized, "Wave server not yet initialized"); if (delta.getOperationCount() == 0) { listener.onFailure("Empty delta at version " + delta.getHashedVersion().getVersion()); return; } // The serialised version of this delta happens now. This should be the only place, ever! ProtocolSignedDelta signedDelta = certificateManager.signDelta(ByteStringMessage.serializeMessage(delta)); submitDelta(waveletName, delta, signedDelta, new SubmitResultListener() { @Override public void onFailure(FederationError errorMessage) { listener.onFailure(errorMessage.getErrorMessage()); } @Override public void onSuccess(int operationsApplied, ProtocolHashedVersion hashedVersionAfterApplication, long applicationTimestamp) { listener.onSuccess(operationsApplied, CoreWaveletOperationSerializer.deserialize(hashedVersionAfterApplication), applicationTimestamp); } }); }