• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java WaveletDelta类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.waveprotocol.wave.model.operation.wave.WaveletDelta的典型用法代码示例。如果您正苦于以下问题:Java WaveletDelta类的具体用法?Java WaveletDelta怎么用?Java WaveletDelta使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

WaveletDelta类属于org.waveprotocol.wave.model.operation.wave包,在下文中一共展示了WaveletDelta类的39个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getDeltas

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Returns a list of deltas for all the operations performed on this wavelet
 * in order of the participants passed into getOpBasedWavelet(). The deltas
 * apply to the version given during construction of the
 * {@link RobotWaveletData}.
 */
public List<WaveletDelta> getDeltas() {
  List<WaveletDelta> deltas = Lists.newArrayList();

  for (Entry<ParticipantId, CapturingOperationSink<WaveletOperation>> entry :
      sinkMap.entrySet()) {
    ParticipantId author = entry.getKey();
    List<WaveletOperation> ops = entry.getValue().getOps();

    if (ops.isEmpty()) {
      // No ops to generate delta for
      continue;
    }
    WaveletDelta delta = new WaveletDelta(author, snapshotVersion, ops);
    deltas.add(delta);
  }
  return deltas;
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:24,
代码来源:RobotWaveletData.java

示例2: maybeTransformSubmittedDelta

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Transform a wavelet delta if it has been submitted against a different head (currentVersion).
 * Must be called with write lock held.
 *
 * @param delta to possibly transform
 * @return the transformed delta and the version it was applied at
 *   (the version is the current version of the wavelet, unless the delta is
 *   a duplicate in which case it is the version at which it was originally
 *   applied)
 * @throws InvalidHashException if submitting against same version but different hash
 * @throws OperationException if transformation fails
 */
protected WaveletDelta maybeTransformSubmittedDelta(WaveletDelta delta)
    throws InvalidHashException, OperationException, TransformException, WaveletStateException {
  HashedVersion targetVersion = delta.getTargetVersion();
  HashedVersion currentVersion = getLastModifiedVersion();
  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 {
      DeltaHistory history = new WaveletDeltaHistory(deltaStateAccessor.get());
      WaveletDelta transformedDelta = ConcurrencyControlCore.onClientDelta(delta, history);
      LOG.info("OT transformed " +
          delta.getTargetVersion().getVersion() + "-" + delta.getResultingVersion() + " -> " +
          transformedDelta.getTargetVersion().getVersion() + "-" + transformedDelta.getResultingVersion());
      return transformedDelta;
    }
  }
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:36,
代码来源:WaveletContainerImpl.java

示例3: testGetDeltas

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testGetDeltas() {
  // Alex adds a participant to the wavelet
  OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX);
  waveletAlex.addParticipant(TRIXIE);

  // Bob doesn't perform any operations but we do retrieve his wavelet
  wavelet.getOpBasedWavelet(BOB);

  List<WaveletDelta> deltas = wavelet.getDeltas();
  assertTrue("Only one participant has performed operations", deltas.size() == 1);

  WaveletDelta delta = deltas.get(0);

  HashedVersion version = delta.getTargetVersion();
  assertEquals(
      "Delta should apply to the version given on construction", hashedVersionZero, version);

  assertEquals(ALEX, delta.getAuthor());

  assertTrue(delta.size() == 1);

  AddParticipant addParticipantOp = new AddParticipant(null, TRIXIE);
  assertEquals("Expected operation that adds Trixie to the wavelet", addParticipantOp,
      delta.iterator().next());
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:26,
代码来源:RobotWaveletTest.java

示例4: testOperationsOfDifferentSizes

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testOperationsOfDifferentSizes() throws Exception {
  String docId = "b+somedoc";
  DocOp docOp1 = new DocOpBuilder().characters("hi").build();
  WaveletDelta delta1 = createDelta(docId, docOp1, localVersion0);

  WaveServerTestUtil.applyDeltaToWavelet(localWavelet, delta1, 0L);
  try {
    DocOp docOp2 = new DocOpBuilder().characters("bye").build();
    WaveletDelta delta2 = createDelta(docId, docOp2, localWavelet.getLastModifiedVersion());

    WaveServerTestUtil.applyDeltaToWavelet(localWavelet, delta2, 0L);
    fail("Composition of \"hi\" and \"bye\" did not throw OperationException");
  } catch (WaveletStateException expected) {
    // Correct
  }
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:17,
代码来源:WaveletContainerTest.java

示例5: testReconnectWithPendingAckNotRecievedByServer

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Test reconnect where there was an unACKed delta during the failure which
 * was not received by the server, expect the client to immediately resend the
 * delta.
 */
public void testReconnectWithPendingAckNotRecievedByServer() throws Exception {
  final int initialVersion = 42;
  final byte[] ackSignature = SIG2;
  connectChannel(initialVersion, SIG1);

  WaveletDelta delta = sendAndCheckRandomOp(operationChannel, 42, SIG1);

  // The server's version is still 42 when it responds. Expect a retransmission.
  reconnectChannel(initialVersion, SIG1, initialVersion, SIG1, null, delta);

  // Now ack.
  listener.checkOpsReceived(0);
  operationChannel.onAck(1, HashedVersion.of(43, ackSignature));

  // There should be a fake op resulting from ack that updates version info
  listener.checkOpsReceived(1);
  checkExpectationsSatisfied();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:24,
代码来源:OperationChannelImplTest.java

示例6: testReconnectWhereAnAckWasNotCommittedCanBeRecovered

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Check that the client sends the correct last known signatures.
 */
public void testReconnectWhereAnAckWasNotCommittedCanBeRecovered() throws Exception {
  final int initialVersion = 42;
  connectChannel(initialVersion, SIG1);

  // Send op and expect an Ack.
  byte[] signature43 = SIG2;
  byte[] signature44 = SIG3;
  sendAndCheckRandomOp(operationChannel, 42, SIG1);
  operationChannel.onAck(1, HashedVersion.of(43, signature43));
  // Send another op and expect an Ack.
  WaveletDelta delta2 = sendAndCheckRandomOp(operationChannel, 43, signature43);
  operationChannel.onAck(1, HashedVersion.of(44, signature44));
  // send commit for first Ack.
  operationChannel.onCommit(43);

  // Check that we reconnect, the server went down and has a LCV of 43.
  // Channel will resend delta2.
  reconnectChannel(43, signature43, 43, signature43, null, delta2);
  deltaChannel.checkExpectationsSatisfied();
  checkExpectationsSatisfied();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:25,
代码来源:OperationChannelImplTest.java

示例7: testMuxReconnectUsingScheduler

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testMuxReconnectUsingScheduler() throws ChannelException {
  final ChannelInfo chInfo1 = new ChannelInfo(WAVELET_ID_1, 1, SIG1);

  FakeScheduler scheduler = new FakeScheduler();
  viewChannel = new MockViewChannel();
  mux = new OperationChannelMultiplexerImpl(WAVE_ID, viewChannel, DATA_FACTORY,
      LOGGERS, null, scheduler, FakeHashedVersionFactory.INSTANCE);

  MuxInfo muxInfo = openMux(chInfo1);
  muxListener.verifyNoMoreInteractions();

  // Send but don't ack delta.
  WaveletDelta delta =
      checkSendDelta(viewChannel, muxInfo.channels.get(0).channel,
        chInfo1.initialHashedVersion, WAVELET_ID_1);

  // Reconnect channel.
  Map<WaveletId, WaveletDelta> unacknowledgetDeltas = new HashMap<>();
  unacknowledgetDeltas.put(chInfo1.waveletId, delta);
  reopenMux(muxInfo, unacknowledgetDeltas, scheduler, true);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:22,
代码来源:OperationChannelMultiplexerImplTest.java

示例8: reopenMux

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private void reopenMux(MuxInfo muxInfo, Map<WaveletId, WaveletDelta> unacknowledgedDeltas,
    FakeScheduler scheduler, boolean doConnect) throws ChannelException {
  viewChannel.expectDisconnect();
  if (scheduler != null) {
    assertNull(scheduler.command);
  }
  mux.disconnect();
  
  viewChannel.expectOpen(muxInfo.getReconnectVersions(), Collections.EMPTY_MAP, unacknowledgedDeltas);
  if (unacknowledgedDeltas != null) {
    for (Entry<WaveletId, WaveletDelta> entry : unacknowledgedDeltas.entrySet()) {
      viewChannel.expectSubmitDelta(entry.getKey(), entry.getValue());
    }
  }
  mux.reopen(Collections.EMPTY_MAP);
  if (scheduler != null) {
    assertNotNull(scheduler.command);
    scheduler.command.execute();
  }

  if (doConnect) {
    connectChannels(muxInfo);
    triggerAndCheckConnected(muxInfo.viewListener);
  }
  viewChannel.checkExpectationsSatisified();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:27,
代码来源:OperationChannelMultiplexerImplTest.java

示例9: testReflectedSubmittedDeltaAfterAckIsError

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Tests that receiving an acknowledged delta submitted by this client is
 * detected as a server-side error.
 */
public void testReflectedSubmittedDeltaAfterAckIsError() throws ChannelException {
  final long lastModifiedVersion = 57;
  final int ops1 = 7;
  final byte[] signature1 = sig(1);
  final WaveletDelta delta1 = buildDelta(lastModifiedVersion, ops1);
  checkedConnectChannel(lastModifiedVersion);

  // Send delta1.
  submitDeltaOnConnectedChannel(delta1);

  // All ops are acked.
  receiver.expectAck(ops1, HashedVersion.of(lastModifiedVersion + ops1, signature1));
  ackDeltaOnConnectedChannel(lastModifiedVersion + ops1, ops1, signature1);

  // Receive the delta (erroneously). Expect termination to be reported.
  try {
    receiveUpdateOnConnectedChannel(buildServerDelta(lastModifiedVersion, ops1));
    fail("ChannelException expected");
  } catch (ChannelException expected) {
  }
  receiver.checkExpectationsSatisfied();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:27,
代码来源:WaveletDeltaChannelImplTest.java

示例10: testAckForReceivedDeltaIsError

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Tests that receiving an ack for a delta already received by this client
 * is detected as a server-side error.
 */
public void testAckForReceivedDeltaIsError() throws ChannelException {
  final long lastModifiedVersion = 57;
  final int ops1 = 7;
  final byte[] signature1 = sig(1);
  final WaveletDelta delta1 = buildDelta(lastModifiedVersion, ops1);
  checkedConnectChannel(lastModifiedVersion);

  // Send delta1.
  submitDeltaOnConnectedChannel(delta1);

  // Receive the delta (erroneously), but we can't detect it's an error yet.
  TransformedWaveletDelta serverDelta1 = buildServerDelta(lastModifiedVersion, ops1);
  receiver.expectDelta(serverDelta1);
  receiveUpdateOnConnectedChannel(serverDelta1);

  // Now receive the ack for the delta. Expect failure.
  try {
    ackDeltaOnConnectedChannel(lastModifiedVersion + ops1, ops1, signature1);
    fail("ChannelException expected");
  } catch (ChannelException expected) {
  }
  receiver.checkExpectationsSatisfied();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:28,
代码来源:WaveletDeltaChannelImplTest.java

示例11: testAckAfterReconnectIgnored

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Tests that an ack received for a delta submitted before a channel
 * reconnects is dropped.
 */
public void testAckAfterReconnectIgnored() throws ChannelException {
  final long initialVersion = 57;
  final byte[] initialSignature = sig(4);
  checkedConnectChannel(initialVersion);

  // Submit delta.
  final int clientOps = 5;
  final WaveletDelta clientDelta = buildDelta(initialVersion, clientOps);
  submitDeltaOnConnectedChannel(clientDelta);

  // Reset channel.
  deltaChannel.reset(receiver);
  checkedReconnectChannel(HashedVersion.of(0, new byte[0]), HashedVersion.of(initialVersion, initialSignature),
      HashedVersion.of(initialVersion, initialSignature), null, clientDelta);

  // Acknowledge outstanding submit.
  final long versionAfterClient = initialVersion + clientOps;
  final byte[] ackedSignature = sig(1);
  // Don't expect the ack at the receiver.
  ackDeltaOnConnectedChannel(versionAfterClient, clientOps, ackedSignature);
  receiver.checkExpectationsSatisfied();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:27,
代码来源:WaveletDeltaChannelImplTest.java

示例12: testNackTooOldIsRecoverable

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testNackTooOldIsRecoverable() throws ChannelException {
  final long initialVersion = 0;
  checkedConnectChannel(initialVersion);

  // Submit delta.
  final long submitVersion = 0;
  final byte[] signature = sig(1);
  final int clientOps = 1;
  final WaveletDelta clientDelta = buildDelta(submitVersion, clientOps);
  submitDeltaOnConnectedChannel(clientDelta);

  // Nack delta immediately with TOO_OLD.
  try {
    nackDeltaOnConnectedChannel(submitVersion, signature, "too old", ReturnCode.TOO_OLD);
    fail("Expected an exception");
  } catch (ChannelException e) {
    assertEquals(Recoverable.RECOVERABLE, e.getRecoverable());
  }
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:20,
代码来源:WaveletDeltaChannelImplTest.java

示例13: testOnConnectedCalledAfterAllWaveletsIsOpened

点赞 3

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testOnConnectedCalledAfterAllWaveletsIsOpened() {
  Map<WaveletId, List<HashedVersion>> knownWavelets = new HashMap<>();
  knownWavelets.put(WAVELET_ID1, Lists.create(HASHED_VERSION1));
  knownWavelets.put(WAVELET_ID2, Lists.create(HASHED_VERSION1));
  Map<WaveletId, WaveletDelta> unacknowledgedDeltas = new HashMap<>();
  channel.open(knownWavelets, Collections.EMPTY_MAP, unacknowledgedDeltas, viewListener);
  waveViewService.opens.get(waveViewService.opens.size()-1).callback.onWaveletOpen(CHANNEL_ID1, 
    HASHED_VERSION1, HASHED_VERSION1, 0, HASHED_VERSION1, null, null);
  viewListener.expectedWaveletOpenCall(WAVELET_ID1, 
      HASHED_VERSION1, HASHED_VERSION1, HASHED_VERSION1, null, null);
  viewListener.expectedNothing();
  waveViewService.opens.get(waveViewService.opens.size()-2).callback.onWaveletOpen(CHANNEL_ID2, 
    HASHED_VERSION1, HASHED_VERSION1, 0, HASHED_VERSION1, null, null);
  viewListener.expectedWaveletOpenCall(WAVELET_ID2, 
      HASHED_VERSION1, HASHED_VERSION1, HASHED_VERSION1, null, null);
  viewListener.expectedConnectedCall();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:18,
代码来源:ViewChannelImplTest.java

示例14: viewSubmit

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
@Override
public void viewSubmit(String channelId, WaveletDelta delta, final SubmitCallback callback) {
  LOG.trace().log("submit on " + channelId + " of wave " + waveId);
  Preconditions.checkArgument(!shutdowned, "Is shut down");
  SubmitDeltaRequestJsoImpl submitRequest = SubmitDeltaRequestJsoImpl.create();
  submitRequest.setChannelId(channelId);
  submitRequest.setDelta(serialize(delta));
  final AsyncCallContext callContext = AsyncCallContext.start("SubmitDeltaRequest");
  socket.submit(submitRequest, new ResponseCallback<SubmitDeltaResponse>() {

    @Override
    public void run(SubmitDeltaResponse response) {
      callContext.stop();
      if (!shutdowned) {
        ReturnStatus status = deserialize(response.getStatus());
        HashedVersion resultVersion = HashedVersion.unsigned(0);
        if (response.hasHashedVersionAfterApplication()) {
          resultVersion =
              WaveletOperationSerializer.deserialize(response.getHashedVersionAfterApplication());
        }
        callback.onResponse(response.getOperationsApplied(), resultVersion,
            response.getTimestampAfterApplication(), status);
      }
    }

  });
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:28,
代码来源:RemoteWaveViewService.java

示例15: serialize

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private ProtocolWaveletDelta serialize(WaveletDelta delta) {
  ProtocolWaveletDeltaJsoImpl protocolDelta = ProtocolWaveletDeltaJsoImpl.create();
  for (WaveletOperation op : delta) {
    protocolDelta.addOperation(operationSerializer.serialize(op));
  }
  protocolDelta.setAuthor(delta.getAuthor().getAddress());
  protocolDelta.setHashedVersion(serialize(delta.getTargetVersion()));
  return protocolDelta;
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:10,
代码来源:RemoteWaveViewService.java

示例16: serialize

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Serializes an untransformed delta as a {@link ProtocolWaveletDelta}.
 *
 * @param delta to serialize
 * @return serialized protocol buffer wavelet delta
 */
public static ProtocolWaveletDelta serialize(WaveletDelta delta) {
 ProtocolWaveletDelta.Builder protobufDelta = ProtocolWaveletDelta.newBuilder();

 for (WaveletOperation waveletOp : delta) {
   protobufDelta.addOperation(serialize(waveletOp));
 }
 protobufDelta.setAuthor(delta.getAuthor().getAddress());
 protobufDelta.setHashedVersion(serialize(delta.getTargetVersion()));

 return protobufDelta.build();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:18,
代码来源:OperationSerializer.java

示例17: prepareDeltaRecord

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private void prepareDeltaRecord(WaveletDeltaRecord deltaRecord) throws InvalidProtocolBufferException {
  ByteStringMessage<Proto.ProtocolAppliedWaveletDelta> appliedDelta = deltaRecord.getAppliedDelta();    
  WaveletDelta delta = DataUtil.deserialize(appliedDelta);
  long timestamp = deltaRecord.getApplicationTimestamp();
  log(2, "Delta - Ver: " + delta.getResultingVersion() +
      " (" + deltaRecord.getAuthor().getName() +
      ", " + dateFormat.format(timestamp) + ", timestamp: " + timestamp + ")");
  for (int i = 0; i < delta.size(); i++) {
    prepareOperation(delta.get(i));
  }
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:12,
代码来源:DeltaPreparator.java

示例18: deserialize

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public static WaveletDelta deserialize(
    ByteStringMessage<Proto.ProtocolAppliedWaveletDelta> appliedDelta)
    throws InvalidProtocolBufferException {
  Proto.ProtocolAppliedWaveletDelta pawDelta = appliedDelta.getMessage();
  Proto.ProtocolSignedDelta psDelta = pawDelta.getSignedOriginalDelta();
  Proto.ProtocolWaveletDelta pwDelta =
      ByteStringMessage.parseProtocolWaveletDelta(psDelta.getDelta()).getMessage();
  return OperationSerializer.deserialize(pwDelta);    
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:10,
代码来源:DataUtil.java

示例19: submitDeltas

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Submits all deltas to the wavelet provider that are generated by the open
 * wavelets in the {@link OperationResults}.
 *
 * @param results the results of performing robot operations.
 * @param waveletProvider wavelet provider used to send the deltas to.
 * @param requestListener callback for deltas that are submitted to the
 *        wavelet provider.
 */
public static void submitDeltas(OperationResults results, WaveletProvider waveletProvider,
    SubmitRequestCallback requestListener) {
  for (Entry<WaveletName, RobotWaveletData> entry : results.getOpenWavelets().entrySet()) {
    WaveletName waveletName = entry.getKey();
    RobotWaveletData w = entry.getValue();
    for (WaveletDelta delta : w.getDeltas()) {
      ProtocolWaveletDelta protocolDelta = OperationSerializer.serialize(delta);
      waveletProvider.submitRequest(waveletName, protocolDelta, requestListener);
    }
  }
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:21,
代码来源:OperationUtil.java

示例20: buildTransformedDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Builds a transformed delta from an applied delta and its transformed ops.
 */
public static TransformedWaveletDelta buildTransformedDelta(
    ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDeltaBytes, WaveletDelta transformed)
    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);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:16,
代码来源:AppliedDeltaUtil.java

示例21: applyDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Builds a {@link WaveletDeltaRecord} and applies it to the wavelet container.
 * The delta must be non-empty.
 */
protected WaveletDeltaRecord applyDelta(
    ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta, WaveletDelta transformed)
    throws InvalidProtocolBufferException, WaveletStateException {
  TransformedWaveletDelta transformedDelta =
      AppliedDeltaUtil.buildTransformedDelta(appliedDelta, transformed);

  WaveletDeltaRecord deltaRecord = new WaveletDeltaRecord(transformed.getTargetVersion(),
      appliedDelta, transformedDelta);
  segmentWaveletState.appendDelta(deltaRecord);
  deltaStateAccessor.get().appendDelta(deltaRecord);

  return deltaRecord;
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:18,
代码来源:WaveletContainerImpl.java

示例22: connect

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private void connect(Map<WaveletId, List<HashedVersion>> knownWavelets,
    Map<WaveletId, Set<SegmentId>> knownSegmentIds, Map<WaveletId, WaveletDelta> unacknowledgedDeltas) {
  Preconditions.checkState(state != State.CONNECTED, "Cannot connect already-connected channel");
  logger.trace().log("Multiplexer reconnecting wave " + waveId);
  state = State.CONNECTING;
  viewChannel.open(knownWavelets, knownSegmentIds, unacknowledgedDeltas, createViewListener());
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:8,
代码来源:OperationChannelMultiplexerImpl.java

示例23: reconnect

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Reconnects with the known versions provided by stacklets.
 *
 * @param exception The exception that caused the reconnection
 */
private void reconnect(final Map<WaveletId, Set<SegmentId>> knownSegmentIds) {
  Preconditions.checkState(state != State.CONNECTED, "Cannot connect already-connected channel");
  logger.trace().log("Reconnecting multiplexer");
  state = State.RECONNECTING;

  // NOTE(zdwang): don't clear this as we'll lose wavelets if we've never
  // been connected. This is a reminder.
  // onConnected.clear();

  // Reset each stacklet, collecting the reconnect versions.
  final Map<WaveletId, List<HashedVersion>> knownWavelets = CollectionUtils.newHashMap();
  final Map<WaveletId, WaveletDelta> unacknowledgedDeltas = CollectionUtils.newHashMap();
  for (final WaveletId waveletId : channels.keySet()) {
    Stacklet stacklet = channels.get(waveletId);
    knownWavelets.put(waveletId, stacklet.getOperationChannel().getReconnectVersions());
    if (stacklet.getOperationChannel().getUnacknowledgedDelta() != null) {
      unacknowledgedDeltas.put(waveletId, stacklet.getOperationChannel().getUnacknowledgedDelta());
    }
  }

  // Run the connect part in the scheduler
  scheduler.schedule(new Scheduler.Command() {

        @Override
        public void execute() {
          connect(knownWavelets, knownSegmentIds, unacknowledgedDeltas.isEmpty() ? null : unacknowledgedDeltas);
        }
      });
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:35,
代码来源:OperationChannelMultiplexerImpl.java

示例24: createWaveletChannel

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Creates a wavelet channel for submissions against a wavelet.
 *
 * @param waveletId wavelet id for the channel
 */
private WaveletChannel createWaveletChannel(final WaveletId waveletId) {
  return new WaveletChannel() {
    @Override
    public void submit(WaveletDelta delta, final SubmitCallback callback) {
      viewChannel.submitDelta(waveletId, delta, callback);
    }
  };
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:14,
代码来源:OperationChannelMultiplexerImpl.java

示例25: getUnacknowledgedDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
@Override
public WaveletDelta getUnacknowledgedDelta() {
  if (state == State.CLOSED) {
    throw new IllegalStateException("Cannot query closed operation channel: " + this);
  }
  return cc.getUnacknowledgedDelta();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:8,
代码来源:OperationChannelImpl.java

示例26: takeArgs

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Invokes the transmitter to get a (delta) and decorates/wraps it as in an
 * argument object. Returns null to abort transmission.
 */
private WaveletDelta takeArgs() {
  if (transmitter == null) {
    return null; // Transmission has been cancelled.
  }

  Transmitter.ClientMessage message = transmitter.takeMessage();
  transmitter = null; // Transmitter is one-shot, will not be used again.
  return message.getDelta();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:14,
代码来源:WaveletDeltaChannelImpl.java

示例27: summariseDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private static String summariseDelta(WaveletDelta delta) {
  if (delta == null) {
    return "null";
  }
  StringBuilder b = new StringBuilder("delta ");
  b.append("version: ").append(delta.getTargetVersion()).append(", ");
  b.append("ops: ").append(delta.size()).append(", ");
  for (WaveletOperation op : delta) {
    b.append(op.toString()).append(", ");
  }
  return b.toString();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:13,
代码来源:WaveletDeltaChannelImpl.java

示例28: makeDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Creates a delta of no-ops and builds the corresponding applied and
 * transformed delta objects.
 */
static WaveletDeltaRecord makeDelta(HashedVersion appliedAtVersion, long timestamp,
    int numOps) throws InvalidProtocolBufferException {
  // Use no-op delta so the ops can actually apply.
  WaveletDelta delta = UTIL.makeNoOpDelta(appliedAtVersion, timestamp, numOps);
  ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta =
      WaveServerTestUtil.buildAppliedDelta(delta, timestamp);
  TransformedWaveletDelta transformedDelta =
      AppliedDeltaUtil.buildTransformedDelta(appliedDelta, delta);
  return new WaveletDeltaRecord(appliedAtVersion, appliedDelta, transformedDelta);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:15,
代码来源:WaveletStateTestBase.java

示例29: testCreateWaveletService

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testCreateWaveletService() throws Exception {
  when(waveletData.getParticipants()).thenReturn(Collections.singletonList(BOB.getAddress()));

  service.execute(operation, context, ALEX);

  JsonRpcResponse response = context.getResponse(OPERATION_ID);
  assertFalse(response.isError());
  Map<ParamsProperty, Object> responseData = response.getData();
  assertEquals("Expected message to be set", MESSAGE, responseData.get(ParamsProperty.MESSAGE));

  WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId(
      (String)responseData.get(ParamsProperty.WAVE_ID));
  WaveletId waveletId = ApiIdSerializer.instance().deserialiseWaveletId(
      (String) responseData.get(ParamsProperty.WAVELET_ID));
  RobotWaveletData newWavelet = context.getOpenWavelets().get(WaveletName.of(waveId, waveletId));
  assertNotNull("A new wavelet must be open", newWavelet);

  List<WaveletDelta> deltas = newWavelet.getDeltas();
  boolean seenAddAlex = false;
  boolean seenAddBob = false;
  for (WaveletOperation op : deltas.get(0)) {
    if (op instanceof AddParticipant) {
      AddParticipant addParticipant = (AddParticipant) op;
      if (addParticipant.getParticipantId().equals(ALEX)) {
        seenAddAlex = true;
      } else if (addParticipant.getParticipantId().equals(BOB)) {
        seenAddBob = true;
      } else {
        fail("No one else but Alex and Bob should be added");
      }
    }
  }
  assertTrue("Alex was not added", seenAddAlex);
  assertTrue("Bob was not added", seenAddBob);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:36,
代码来源:CreateWaveletServiceTest.java

示例30: testDeltasAreReturnedInOrder

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
public void testDeltasAreReturnedInOrder() {
  // Alex adds a participant to the wavelet
  OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX);
  waveletAlex.addParticipant(TRIXIE);

  // Bob adds a new document to the wavelet
  OpBasedWavelet waveletBob = wavelet.getOpBasedWavelet(BOB);
  waveletBob.getDocument("r+randomDocument").insertText(0, "/nHello");

  List<WaveletDelta> deltas = wavelet.getDeltas();
  assertTrue(deltas.size() == 2);

  assertEquals("Expected Alex to be first", ALEX, deltas.get(0).getAuthor());
  assertEquals("Expected Bob to be the second author", BOB, deltas.get(1).getAuthor());
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:16,
代码来源:RobotWaveletTest.java

示例31: makeDeltaFromCapturedOps

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Builds a "transformed" delta from client ops (no transformation happens).
 */
private TransformedWaveletDelta makeDeltaFromCapturedOps(ParticipantId author,
    List<WaveletOperation> ops, HashedVersion endVersion, long timestamp) {
  WaveletDelta clientDelta =
      new WaveletDelta(author, HashedVersion.unsigned(endVersion.getVersion() - ops.size()), ops);
  return TransformedWaveletDelta.cloneOperations(endVersion, timestamp, clientDelta);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:10,
代码来源:EventGeneratorTest.java

示例32: buildAppliedDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Build an applied delta message from a POJO delta. The delta is not signed.
 */
public static ByteStringMessage<ProtocolAppliedWaveletDelta> buildAppliedDelta(WaveletDelta delta,
    long applicationTimestamp) {
  ProtocolWaveletDelta protoDelta = OperationSerializer.serialize(delta);
  ByteStringMessage<ProtocolWaveletDelta> deltaBytes =
      ByteStringMessage.serializeMessage(protoDelta);
  ProtocolSignedDelta signedDelta =
      ProtocolSignedDelta.newBuilder().setDelta(deltaBytes.getByteString()).build();
  return AppliedDeltaUtil.buildAppliedDelta(signedDelta, delta.getTargetVersion(), delta.size(),
      applicationTimestamp);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:14,
代码来源:WaveServerTestUtil.java

示例33: applyDeltaToWavelet

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Applies a delta to a wavelet container.
 */
public static void applyDeltaToWavelet(WaveletContainerImpl wavelet, WaveletDelta delta,
    long applicationTimestamp) throws InvalidProtocolBufferException, WaveletStateException {
  ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta =
      buildAppliedDelta(delta, applicationTimestamp);
  wavelet.applyDelta(appliedDelta, delta);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:10,
代码来源:WaveServerTestUtil.java

示例34: assertDeepEquals

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private static void assertDeepEquals(WaveletDelta a, WaveletDelta b) {
  assertEquals(a.getAuthor(), b.getAuthor());
  assertEquals(a.size(), b.size());
  Iterator<WaveletOperation> aItr = a.iterator();
  Iterator<WaveletOperation> bItr = b.iterator();
  while(aItr.hasNext()) {
    assertEquals(aItr.next(), bItr.next());
  }
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:10,
代码来源:WaveletOperationSerializerTest.java

示例35: makeDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Builds a random client delta.
 */
public WaveletDelta makeDelta(HashedVersion targetVersion, long timestamp, int numOps) {
  List<WaveletOperation> ops = CollectionUtils.newArrayList();
  WaveletOperationContext context =
      new WaveletOperationContext(author, Constants.NO_TIMESTAMP, 1);
  for (int i = 0; i < numOps; ++i) {
    ops.add(randomOp(context));
  }
  return new WaveletDelta(author, targetVersion, ops);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:13,
代码来源:DeltaTestUtil.java

示例36: makeNoOpDelta

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Builds a no-op client delta.
 */
public WaveletDelta makeNoOpDelta(HashedVersion targetVersion, long timestamp, int numOps) {
  List<WaveletOperation> ops = CollectionUtils.newArrayList();
  WaveletOperationContext context =
      new WaveletOperationContext(author, Constants.NO_TIMESTAMP, 1);
  for (int i = 0; i < numOps; ++i) {
    ops.add(new NoOp(context));
  }
  return new WaveletDelta(author, targetVersion, ops);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:13,
代码来源:DeltaTestUtil.java

示例37: reconnectChannel

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Fails and reconnects the channel at the provided connection version and
 * current version. The channel is expected to provide a distinct version
 * matching the connect version. If expectRetransmission is not null expects
 * the channel to attempt to send that message on reconnection.
 */
private void reconnectChannel(long connectVersion, byte[] connectSignature,
    long currentVersion, byte[] currentSignature, HashedVersion unackHashedVersion,
    WaveletDelta expectRetransmission)
    throws ChannelException {
  final HashedVersion connectHashedVersion = HashedVersion.of(connectVersion, connectSignature);
  final HashedVersion currentHashedVersion = HashedVersion.of(currentVersion, currentSignature);

  // Simulate failure elsewhere.
  operationChannel.reset();

  // Check reconnect versions provided by the channel include the
  // version we'll reconnect at.
  List<HashedVersion> reconnectVersions = operationChannel.getReconnectVersions();
  assertTrue(reconnectVersions.size() > 0);
  boolean matchedSignature = false;
  for (HashedVersion rcv : reconnectVersions) {
    if (connectHashedVersion.equals(rcv)) {
      matchedSignature = true;
    }
  }
  assertTrue("No matching signature provided", matchedSignature);

  // Simulate reconnection reconnection message from delta channel.
  if (expectRetransmission != null) {
    deltaChannel.expectSend(expectRetransmission);
  }
  List<WaveletOperation> operations = new ArrayList<WaveletOperation>();
  if (!connectHashedVersion.equals(currentHashedVersion)) {
    operations.add(new NoOp(new WaveletOperationContext(null, 0, currentHashedVersion.getVersion(), currentHashedVersion)));
  }
  operationChannel.onConnection(connectHashedVersion, currentHashedVersion,
      unackHashedVersion, operations);
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:40,
代码来源:OperationChannelImplTest.java

示例38: sendAndCheckRandomOp

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
private WaveletDelta sendAndCheckRandomOp(OperationChannelImpl opChannel,
    long currentVersion, byte[] signature) throws ChannelException {
  WaveletDelta delta = UTIL.makeDelta(HashedVersion.of(currentVersion, signature), 0L, 1);

  deltaChannel.expectSend(delta);
  opChannel.send(new WaveletOperation[] {delta.get(0)});
  return delta;
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:9,
代码来源:OperationChannelImplTest.java

示例39: testReconnectWithPendingAckAndNewDeltaSentByServer

点赞 2

import org.waveprotocol.wave.model.operation.wave.WaveletDelta; //导入依赖的package包/类
/**
 * Test reconnect where there was an unACKed delta during the failure which
 * was received and ACKed by the server, but this was unseen by the client. On
 * reconnect, the server responds with that delta and a new one, the client
 * should receive only the new one.
 */
public void testReconnectWithPendingAckAndNewDeltaSentByServer() throws Exception {
  final int initialVersion = 42;
  final byte[] initialSignature = SIG1;
  connectChannel(initialVersion, initialSignature);

  WaveletDelta delta = sendAndCheckRandomOp(operationChannel, 42, SIG1);

  // Reconnect at the version before that delta, but with a later
  // current version including it.
  final long afterVersion = 44;
  final byte[] afterSignature = SIG3;
  reconnectChannel(initialVersion, initialSignature, afterVersion, afterSignature,
      HashedVersion.of(afterVersion, afterSignature), null);

  listener.checkOpsReceived(1);
  assertNotNull(operationChannel.receive());
  listener.clear();

  // Receive another op
  TransformedWaveletDelta rdelta = createRandomTransformedDelta(45, 1, SIG4);
  operationChannel.onDelta(rdelta);
  // Recovery should be complete since the client has caught up with the
  // server, and there should be one readable delta.
  listener.checkOpsReceived(1);
  assertNotNull(operationChannel.receive());
  checkExpectationsSatisfied();
}
 

开发者ID:jorkey,
项目名称:Wiab.pro,
代码行数:34,
代码来源:OperationChannelImplTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)