/** * Returns the extended address path, i.e., the addresses in the delta's * address path, plus the author of the delta. */ private Iterable<String> getExtendedAddressPath(ProtocolWaveletDelta delta) { return Iterables.concat(delta.getAddressPathList(), ImmutableList.of(delta.getAuthor())); }
@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); }
LOG.info("Submit to " + waveletName + " by " + delta.getAuthor() + " @ " + delta.getHashedVersion().getVersion() + " with " + delta.getOperationCount() + " ops"); if (!wavelet.checkAccessPermission(ParticipantId.of(delta.getAuthor()))) { resultListener.onFailure(FederationErrors.badRequest( delta.getAuthor() + " is not a participant of " + waveletName)); return;
@Override public void submitRequest(ParticipantId loggedInUser, final WaveletName waveletName, final ProtocolWaveletDelta delta, final String channelId, final SubmitRequestListener listener) { final ParticipantId author = new ParticipantId(delta.getAuthor()); if (!author.equals(loggedInUser)) { listener.onFailure("Author field on delta must match logged in user"); return; } waveletInfo.getUserManager(author).submitRequest(channelId, waveletName); waveletProvider.submitRequest(waveletName, delta, new SubmitRequestListener() { @Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { listener.onSuccess(operationsApplied, hashedVersionAfterApplication, applicationTimestamp); waveletInfo.getUserManager(author).submitResponse(channelId, waveletName, hashedVersionAfterApplication); } @Override public void onFailure(String error) { listener.onFailure(error); waveletInfo.getUserManager(author).submitResponse(channelId, waveletName, null); } }); }
/** * Deserializes a {@link ProtocolWaveletDelta} as an untransformed wavelet * delta. */ public static WaveletDelta deserialize(ProtocolWaveletDelta delta) { List<WaveletOperation> ops = Lists.newArrayList(); for (ProtocolWaveletOperation op : delta.getOperationList()) { WaveletOperationContext context = new WaveletOperationContext( ParticipantId.ofUnsafe(delta.getAuthor()), Constants.NO_TIMESTAMP, 1); ops.add(deserialize(op, context)); } HashedVersion hashedVersion = deserialize(delta.getHashedVersion()); return new WaveletDelta(new ParticipantId(delta.getAuthor()), hashedVersion, ops); }
public void testConvertOfDelta() throws WaveletStateException, InvalidParticipantAddress { ProtocolWaveletDelta delta = DomainConverter.convertDelta(DELTA_ADD_USER, DOMAIN); assertEquals(USER, delta.getAuthor()); assertEquals(USER, delta.getOperation(0).getAddParticipant()); } }
public void testConvertOfDelta() throws WaveletStateException, InvalidParticipantAddress { ProtocolWaveletDelta delta = DomainConverter.convertDelta(DELTA_ADD_USER, DOMAIN); assertEquals(USER, delta.getAuthor()); assertEquals(USER, delta.getOperation(0).getAddParticipant()); } }