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

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


  }

  @SuppressWarnings("unchecked")
  private OTOperation transform(final OTOperation remoteOp, final OTOperation localOp, final boolean invertWinRule) {
    final boolean remoteWins = invertWinRule ? !this.remoteWins : this.remoteWins;
    final OTOperation transformedOp;
    final List<Mutation> remoteMutations = remoteOp.getMutations();
    final List<Mutation> localMutations = localOp.getMutations();
    final List<Mutation> transformedMutations = new ArrayList<Mutation>(remoteMutations.size());

    final Iterator<Mutation> remoteOpMutations;
    final Iterator<Mutation> localOpMutations;

    if (remoteMutations.size() > localMutations.size()) {
      remoteOpMutations = noopPaddedIterator(remoteMutations, remoteMutations.size());
      localOpMutations = noopPaddedIterator(localMutations, remoteMutations.size());
    }
    else if (remoteMutations.size() < localMutations.size()) {
      remoteOpMutations = noopPaddedIterator(remoteMutations, localMutations.size());
      localOpMutations = noopPaddedIterator(localMutations, localMutations.size());
    }
    else {
      remoteOpMutations = remoteMutations.iterator();
      localOpMutations = localMutations.iterator();
    }

    int offset = 0;
    boolean resolvesConflict = false;

    while (remoteOpMutations.hasNext()) {
      final Mutation rm = remoteOpMutations.next();
      final Mutation lm = localOpMutations.next();

      final int rmIdx = rm.getPosition();
      final int diff = rmIdx - lm.getPosition();

      final TransactionLog transactionLog = entity.getTransactionLog();
      if (diff < 0) {
        if (rm.getType() == MutationType.Delete) {
          if (rm.getPosition() + rm.length() > lm.getPosition()) {
            if (lm.getType() == MutationType.Insert) {
              // uh-oh.. our local insert is inside the range of this remote delete ... move the insert
              // to the beginning of the delete range to resolve this.

              final LogQuery effectiveStateForRevision = transactionLog.getEffectiveStateForRevision(localOp.getRevision());
              final State rewind = effectiveStateForRevision.getEffectiveState();
              localOp.removeFromCanonHistory();
              transactionLog.markDirty();
              final Mutation mutation = lm.newBasedOn(rm.getPosition());
              mutation.apply(rewind);

              final OTOperation localOnlyOperation
                  = createLocalOnlyOperation(engine, remoteOp.getAgentId(), singletonList(mutation), entity, localOp.getRevision(), OpPair.of(remoteOp, localOp));
              transactionLog.insertLog(localOp.getRevision(), localOnlyOperation);

              entity.getState().syncStateFrom(rewind);
View Full Code Here


    if (combined == null) {
      return toCombine;
    }
    else {
      final List<OTOperation> combinedOps = new ArrayList<OTOperation>();
      final OTOperation operation
          = createOperation(engine,
          toCombine.get(0).getAgentId(),
          singletonList(combined),
          toCombine.get(0).getEntityId(),
          -1,
View Full Code Here

          final int lastTransmittedSequence = peer.getLastTransmittedSequence(entry.getKey());
          final List<OTOperation> toSend = new ArrayList<OTOperation>();

          final ListIterator<OTOperation> iter = log.listIterator(log.size());
          while (iter.hasPrevious()) {
            final OTOperation previous = iter.previous();

            toSend.add(previous);

            if (previous.getRevision() == lastTransmittedSequence) {
              Collections.reverse(toSend);
              break;
            }
          }
View Full Code Here

    flushing = true;
    Atomizer.stopEvents();

    try {
      final OTOperation operation = toOperation();
      engine.notifyOperation(operation);
      insertState.clear();
      deleteState.clear();
      logger.debug("FLUSH: " + operation + ";rev=" + operation.getRevision());
    }
    catch (Throwable t) {
      t.printStackTrace();
    }
    finally {
View Full Code Here

    flushing = true;
    Atomizer.stopEvents();

    try {
      final OTOperation operation = toOperation();
      engine.notifyOperation(operation);
      insertState.clear();
      deleteState.clear();
      LogUtil.log("FLUSH: " + operation + ";rev=" + operation.getRevision());
    }
    catch (Throwable t) {
      t.printStackTrace();
    }
    finally {
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

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.