Package org.jboss.errai.otec.client.operation

Examples of org.jboss.errai.otec.client.operation.OTOperation


    }
    return true;
  }

  protected void handleOperation(final OTQueuedOperation queuedOp) {
    final OTOperation transformedOp = applyFromRemote(queuedOp.getOperation());

    if (transformedOp == null) {
      OTLogUtil.log("<DROPPED OP: " + queuedOp.getOperation() + " -- will not propagate>");
      return;
    }

    final OTPeer peer = getPeerState().getPeer(queuedOp.getPeerId());

    // broadcast to all other peers subscribed to this entity
    final Set<OTPeer> peers = getPeerState().getPeersFor(queuedOp.getEntityId());
    for (final OTPeer otPeer : peers) {
      if (otPeer != peer && !transformedOp.isNoop()) {
        otPeer.send(transformedOp);
        OTLogUtil.log("SENT OP TO PEER (" + otPeer.getId() + "): " + transformedOp);
      }
    }
  }
View Full Code Here


            }

         //   final Collection<OpDto> enginePlanFor = demux.getEnginePlanFor(value);
            for (final OpDto operation : Collections.singletonList(value)) {

              final OTOperation remoteOp = operation.otOperation(engine);

              OTLogUtil.log("RECV", "<<from: " + remoteOp.getAgentId() + ">>" ,
                  "REMOTE", "Server", operation.getRevision(),
                  "\"" + String.valueOf(entity.getState().get()) + "\"");

              if (!engine.receive(session, remoteOp)) {
                System.out.println("*** WARNING: CORRUPT PATHS - MUST RESYNC ALL ***");
 
View Full Code Here

    }
  }

  private OTOperation toOperation() {

    final OTOperation operation;
    if (!insertState.get().isEmpty()) {
      operation = createOperation(engine, engine.getId(),
          Collections.<Mutation>singletonList(StringMutation.of(MutationType.Insert, start, insertState.get())),
          entity.getId(), entity.getRevision(), entity.getState().getHash()
      );
View Full Code Here

      }

      final ListIterator<OTOperation> delIter = transactionLog.listIterator(index);
      while (delIter.hasNext()) {
        entity.decrementRevisionCounter();
        final OTOperation next = delIter.next();

        final OTOperation outerPath = next.getOuterPath();
        if (outerPath != next && outerPath.getTransformedFrom() != null) {
          if (outerPath.getTransformedFrom().getRemoteOp().equals(next)) {
            outerPath.removeFromCanonHistory();
            continue;
          }
        }

        next.removeFromCanonHistory();
View Full Code Here

      final ListIterator<OTOperation> operationListIterator = transactionLog.listIterator(transactionLog.size());
      final List<OTOperation> operationList = new ArrayList<OTOperation>();
      final int revision = operation.getRevision();

      while (operationListIterator.hasPrevious()) {
        final OTOperation previous = operationListIterator.previous();

        if (!includeNonCanon && !previous.isCanon()) {
          continue;
        }

        operationList.add(previous);

        if (previous.getRevision() == revision || previous.getRevisionHash().equals(operation.getRevisionHash())) {
          Collections.reverse(operationList);
          return operationList;
        }
      }
View Full Code Here

    synchronized (lock) {
      final ListIterator<OTOperation> iter = transactionLog.listIterator(transactionLog.size());

      final List<OTOperation> collect = new LinkedList<OTOperation>();
      while (iter.hasPrevious()) {
        final OTOperation previous = iter.previous();
        if (previous.getRevision() < rev) {
          break;
        }
        if (agentId.equals(previous.getAgentId())) {
          collect.add(previous);
        }
      }

      Collections.reverse(collect);
View Full Code Here

      }

      final Set<OTOperation> contingent = new LinkedHashSet<OTOperation>();
      final List<OTOperation> needsMerge = new LinkedList<OTOperation>();
      while (operationListIterator.hasNext()) {
        final OTOperation op = operationListIterator.next();

        if (!op.isCanon()) {
          continue;
        }

        if (op.getRevision() < revision) {
          for (final Mutation mutation : op.getMutations()) {
            mutation.apply(stateToTranslate);
          }
          contingent.add(op.getOuterPath());
        }
        else {
          needsMerge.add(op);
        }
      }
View Full Code Here

    synchronized (lock) {
      final Set<OTOperation> applied = new HashSet<OTOperation>();

      final Iterator<OTOperation> iterator = transactionLog.iterator();
      while (iterator.hasNext()) {
        final OTOperation next = iterator.next();
        if (next.getRevision() > rev) {
          return;
        }

        if (!next.isCanon() || applied.contains(next)) {
          iterator.remove();
        }
        else {
          applied.add(next.getOuterPath());
        }
      }
    }
  }
View Full Code Here

      throw new BadSync("", entity.getId(), remoteOp.getAgentId());
    }

    boolean first = true;
    boolean appliedRemoteOp = false;
    OTOperation applyOver = remoteOp;
    if (localOps.isEmpty()) {
      createOperation(remoteOp).apply(entity);
      return remoteOp;
    }
    else {
      final LogQuery query = transactionLog.getEffectiveStateForRevision(remoteOp.getRevision() + 1);
      entity.getState().syncStateFrom(query.getEffectiveState());

      OTLogUtil.log("REWIND",
          "<<FOR TRANSFORM OVER: " + remoteOp + ";rev=" + remoteOp.getRevision() + ">>",
          "-",
          engine.getName(),
          remoteOp.getRevision() + 1,
          "\"" + entity.getState().get() + "\"");

      final OTOperation firstOp = localOps.get(0);
      final List<OTOperation> remoteOps = transactionLog.getRemoteOpsSinceRevision(applyOver.getAgentId(), firstOp.getRevision());
      if (!remoteOps.isEmpty()) {
        OTOperation firstPrevRemoteOp = remoteOps.get(0);
        while (firstPrevRemoteOp.getTransformedFrom() != null) {
          firstPrevRemoteOp = firstPrevRemoteOp.getTransformedFrom().getRemoteOp();
        }

        final LogQuery query2 = transactionLog.getEffectiveStateForRevision(firstPrevRemoteOp.getRevision() + 1);
        entity.getState().syncStateFrom(query2.getEffectiveState());
        for (final OTOperation operation : query2.getLocalOpsNeedsMerge()) {
          operation.apply(entity, true);
        }

        applyOver = translateFrom(remoteOp, remoteOps.get(remoteOps.size() - 1));

        OTLogUtil.log("CTRNSFRM", "FOR: " + remoteOp + "->" + applyOver,
            "-", engine.getName(), remoteOp.getRevision() + 1, "\"" + entity.getState().get() + "\"");

        createOperation(applyOver).apply(entity);

        return applyOver;
      }

      for (final OTOperation localOp : localOps) {
        if (first) {
          first = false;
          if (applyOver.getRevisionHash().equals(localOp.getRevisionHash()) || localOp.isResolvedConflict()) {
            applyOver = transform(applyOver, localOp);
          }
          else {
            applyOver = transform(applyOver,
                transform(localOp.getTransformedFrom().getLocalOp(),
                    localOp.getTransformedFrom().getRemoteOp()));
          }
        }
        else {
          final OTOperation ot = transform(localOp, applyOver, false);

          final boolean changedLocally = !localOp.equals(ot);

          if (changedLocally) {
            localOp.removeFromCanonHistory();
            entity.decrementRevisionCounter();
          }

          if (!appliedRemoteOp && changedLocally) {
            applyOver.apply(entity);
            appliedRemoteOp = true;
          }

          applyOver = transform(applyOver, ot);

          ot.apply(entity, !changedLocally);

          if (changedLocally) {
            localOp.removeFromCanonHistory();
            localOp.setOuterPath(ot);
          }
View Full Code Here

    if (transformedFrom == null) {
      return remoteOp;
    }
    else {
      final List<OpPair> translationVector = new ArrayList<OpPair>();
      OTOperation last = basedOn;
      OTOperation op = basedOn;
      while ((transformedFrom = op.getTransformedFrom()) != null) {
        OTOperation root = transformedFrom.getLocalOp();
        int baseRev;
        do {
          baseRev = root.getRevision();
        } while (root.getTransformedFrom() != null && (root = root.getTransformedFrom().getRemoteOp()) != null);
       
        if (remoteOp.getTransformedFrom() == null || baseRev > remoteOp.getLastRevisionTx()) {
          translationVector.add(transformedFrom);
        }
       
        op = transformedFrom.getRemoteOp();

        if (last.equals(op)) {
          continue;
        }

        op.unmarkAsResolvedConflict();
        last = op;
      }

      Collections.reverse(translationVector);
      OTOperation applyOver = remoteOp;
      for (final OpPair o : translationVector) {
        OTLogUtil.log("***");
        applyOver = transform(applyOver, transform(o.getLocalOp(), o.getRemoteOp()));
      }

View Full Code Here

TOP

Related Classes of org.jboss.errai.otec.client.operation.OTOperation

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.