Package org.waveprotocol.wave.model.version

Examples of org.waveprotocol.wave.model.version.HashedVersion


      id = ModernIdSerialiser.INSTANCE.deserialiseWaveletId(snapshot.getWaveletId());
    } catch (InvalidIdException e) {
      throw new IllegalArgumentException(e);
    }
    ParticipantId creator = ParticipantId.ofUnsafe(snapshot.getParticipantId(0));
    HashedVersion version = deserialize(snapshot.getVersion());
    long lmt = snapshot.getLastModifiedTime();
    long ctime = snapshot.getCreationTime();
    long lmv = version.getVersion();

    WaveletDataImpl waveletData =
        new WaveletDataImpl(id, creator, ctime, lmv, version, lmt, waveId, docFactory);
    for (String participant : snapshot.getParticipantId()) {
      waveletData.addParticipant(new ParticipantId(participant));
View Full Code Here


      throws InvalidProtocolBufferException {
    ProtocolAppliedWaveletDelta appliedDelta = appliedDeltaBytes.getMessage();
    Preconditions.checkArgument(
        getHashedVersionAppliedAt(appliedDeltaBytes).equals(transformed.getTargetVersion()));
    Preconditions.checkArgument(appliedDelta.getOperationsApplied() == transformed.size());
    HashedVersion resultingVersion = HASH_FACTORY.create(appliedDeltaBytes.getByteArray(),
        transformed.getTargetVersion(), appliedDelta.getOperationsApplied());
    return TransformedWaveletDelta.cloneOperations(resultingVersion,
        appliedDelta.getApplicationTimestamp(), transformed);
  }
View Full Code Here

      PersistenceException, WaveletStateException {
    awaitLoad();
    acquireWriteLock();
    try {
      checkStateOk();
      HashedVersion before = getCurrentVersion();
      WaveletDeltaRecord result = transformAndApplyLocalDelta(signedDelta);
      HashedVersion after = getCurrentVersion();
      // Only publish and persist the delta if it wasn't transformed away
      // (right now it never is since the current OT algorithm doesn't transform ops away)
      // and wasn't a duplicate of a previously applied delta.
      if (!after.equals(before)) {
        Preconditions.checkState(!result.isEmpty());
        Preconditions.checkState(result.getAppliedAtVersion().equals(before));
        ImmutableSet<String> domainsToNotify = domainsOf(Iterables.concat(
            accessSnapshot().getParticipants(),
            participantsRemovedBy(result.getTransformedDelta())));
View Full Code Here

        CoreWaveletOperationSerializer.deserialize(protocolDelta));

    // TODO(ljvderijk): a Clock needs to be injected here (Issue 104)
    long applicationTimestamp = System.currentTimeMillis();

    HashedVersion currentVersion = getCurrentVersion();

    // This is always false right now because the current algorithm doesn't transform ops away.
    if (transformed.size() == 0) {
      Preconditions.checkState(currentVersion.getVersion() != 0,
          "currentVersion can not be 0 if delta was transformed");
      Preconditions.checkState(
          transformed.getTargetVersion().getVersion() <= currentVersion.getVersion());
      // The delta was transformed away. That's OK but we don't call either
      // applyWaveletOperations(), because that will throw IllegalArgumentException, or
      // commitAppliedDelta(), because empty deltas cannot be part of the delta history.
      TransformedWaveletDelta emptyDelta = new TransformedWaveletDelta(transformed.getAuthor(),
          transformed.getTargetVersion(), applicationTimestamp, transformed);
      return new WaveletDeltaRecord(transformed.getTargetVersion(), null, emptyDelta);
    }

    if (!transformed.getTargetVersion().equals(currentVersion)) {
      Preconditions.checkState(
          transformed.getTargetVersion().getVersion() < currentVersion.getVersion());
      // The delta was a duplicate of an existing server delta.
      // We duplicate-eliminate it (don't apply it to the wavelet state and don't store it in
      // the delta history) and return the server delta which it was a duplicate of
      // (so delta submission becomes idempotent).
      ByteStringMessage<ProtocolAppliedWaveletDelta> existingDeltaBytes =
View Full Code Here

  protected void notifyOfDeltas(ImmutableList<WaveletDeltaRecord> deltas,
      ImmutableSet<String> domainsToNotify) {
    Preconditions.checkState(writeLock.isHeldByCurrentThread(), "must hold write lock");
    Preconditions.checkArgument(!deltas.isEmpty(), "empty deltas");
    HashedVersion endVersion = deltas.get(deltas.size() - 1).getResultingVersion();
    HashedVersion currentVersion = getCurrentVersion();
    Preconditions.checkArgument(endVersion.equals(currentVersion),
        "cannot notify of deltas ending in %s != current version %s", endVersion, currentVersion);
    notifiee.waveletUpdate(waveletState.getSnapshot(), deltas, domainsToNotify);
  }
View Full Code Here

   * @throws InvalidHashException if submitting against same version but different hash
   * @throws OperationException if transformation fails
   */
  protected WaveletDelta maybeTransformSubmittedDelta(WaveletDelta delta)
      throws InvalidHashException, OperationException {
    HashedVersion targetVersion = delta.getTargetVersion();
    HashedVersion currentVersion = getCurrentVersion();
    if (targetVersion.equals(currentVersion)) {
      // Applied version is the same, we're submitting against head, don't need to do OT
      return delta;
    } else {
      // Not submitting against head, we need to do OT, but check the versions really are different
      if (targetVersion.getVersion() == currentVersion.getVersion()) {
        LOG.warning("Mismatched hash, expected " + currentVersion + ") but delta targets (" +
            targetVersion + ")");
        throw new InvalidHashException(currentVersion, targetVersion);
      } else {
        return transformSubmittedDelta(delta);
View Full Code Here

   * Finds range of server deltas needed to transform against, then transforms all client
   * ops against the server ops.
   */
  private WaveletDelta transformSubmittedDelta(WaveletDelta submittedDelta)
      throws OperationException, InvalidHashException {
    HashedVersion targetVersion = submittedDelta.getTargetVersion();
    HashedVersion currentVersion = getCurrentVersion();
    Preconditions.checkArgument(!targetVersion.equals(currentVersion));
    ListReceiver<TransformedWaveletDelta> receiver = new ListReceiver<TransformedWaveletDelta>();
    waveletState.getTransformedDeltaHistory(targetVersion, currentVersion, receiver);
    DeltaSequence serverDeltas = DeltaSequence.of(receiver);
    Preconditions.checkState(!serverDeltas.isEmpty(),
View Full Code Here

   * @throws AccessControlException with the given message if version does not
   *         match a delta boundary in the wavelet history.
   */
  private void checkVersionIsDeltaBoundary(HashedVersion version, String message)
      throws AccessControlException {
    HashedVersion actual = waveletState.getHashedVersion(version.getVersion());
    if (!version.equals(actual)) {
      LOG.info("Unrecognized " + message + " at version " + version + ", actual " + actual);
      // We omit the hash from the message to avoid leaking it.
      throw new AccessControlException(
          "Unrecognized " + message + " at version " + version.getVersion());
View Full Code Here

  public static TransformedWaveletDelta deserializeTransformedWaveletDelta(DBObject dbObject)
      throws PersistenceException {

    ParticipantId author = deserializeParicipantId((DBObject) dbObject.get(FIELD_AUTHOR));
    HashedVersion resultingVersion =
        deserializeHashedVersion((DBObject) dbObject.get(FIELD_RESULTINGVERSION));
    long applicationTimestamp = (Long) dbObject.get(FIELD_APPLICATIONTIMESTAMP);

    BasicDBList dbOps = (BasicDBList) dbObject.get(FIELD_OPS);
    ImmutableList.Builder<WaveletOperation> operations = ImmutableList.builder();
View Full Code Here

      String name = deltaFile.getName();
      String encodedWaveletId =
          name.substring(0, name.lastIndexOf(FileDeltaCollection.DELTAS_FILE_SUFFIX));
      WaveletId waveletId = FileUtils.waveletIdFromPathSegment(encodedWaveletId);
        FileDeltaCollection deltas = open(WaveletName.of(waveId, waveletId));
        HashedVersion endVersion = deltas.getEndVersion();
        if (endVersion != null && endVersion.getVersion() > 0) {
          results.add(waveletId);
        }
      try {
        deltas.close();
      } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.version.HashedVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.