Package org.waveprotocol.wave.concurrencycontrol.common

Examples of org.waveprotocol.wave.concurrencycontrol.common.ChannelException


   * @param waveletId associated wavelet id (may be null)
   */
  private void triggerOnException(ChannelException e, WaveletId waveletId) {
    if (openListener != null) {
      openListener.onException(
          new ChannelException(e.getResponseCode(), "Exception in view channel, state " + this,
              e, e.getRecoverable(), waveId, waveletId));
    }
  }
View Full Code Here


      public void onOpenFinished() throws ChannelException {
        if (connectionTag == expectedTag) {
          if (missingWavelets == null) {
            // TODO(anorth): Add an error code for a protocol error and use
            // it here.
            throw new ChannelException(ResponseCode.INTERNAL_ERROR,
                "Multiplexer received openFinished twice", null, Recoverable.NOT_RECOVERABLE,
                waveId, null);
          }

          // If a missing wavelet could be reconnected at version zero then
          // fake the resync message here. The server no longer knows about
          // the wavelet so we should resubmit changes from version zero.
          Iterator<WaveletId> itr = missingWavelets.iterator();
          while (itr.hasNext()) {
            WaveletId maybeMissing = itr.next();
            List<HashedVersion> resyncVersions = expectedWavelets.get(maybeMissing);
            Preconditions.checkState(!resyncVersions.isEmpty(),
                "Empty resync versions for wavelet " + maybeMissing);
            if (resyncVersions.get(0).getVersion() == 0) {
              Stacklet stacklet = channels.get(maybeMissing);
              if (stacklet == null) {
                Preconditions.illegalState("Resync wavelet has no stacklet. Channels: "
                    + channels.keySet() + ", resync: " + expectedWavelets.keySet());
              }
              WaveletName wavelet = WaveletName.of(waveId, maybeMissing);
              List<TransformedWaveletDelta> resyncDeltaList = createVersionZeroResync(wavelet);
              HashedVersion v0 = hashFactory.createVersionZero(wavelet);
              stacklet.onWaveletUpdate(resyncDeltaList, v0, v0);
              itr.remove();
            }
          }

          // Check we received a message for each expected wavelet.
          if (!missingWavelets.isEmpty()) {
            throw new ChannelException(ResponseCode.NOT_AUTHORIZED,
                "Server didn't acknowledge known wavelets; perhaps access has been lost: "
                    + missingWavelets, null, Recoverable.NOT_RECOVERABLE, waveId, null);
          }
          missingWavelets = null;
          maybeOpenFinished();
View Full Code Here

  /**
   * Wraps a channel exception in another providing wave and wavelet id context.
   */
  private ChannelException exceptionWithContext(ChannelException e, WaveletId waveletId) {
    return new ChannelException(e.getResponseCode(), "Nested ChannelException", e,
        e.getRecoverable(), waveId, waveletId);
  }
View Full Code Here

  @Override
  public void onOpen(HashedVersion connectVersion, HashedVersion currentVersion)
      throws ChannelException {
    if ((connectVersion == null) || (currentVersion == null) || (connectVersion.getVersion() < 0)
        || (currentVersion.getVersion() < connectVersion.getVersion())) {
      throw new ChannelException("ConcurrencyControl onOpen received invalid versions, "
          + "connect version: " + connectVersion + ", current version: " + currentVersion,
          Recoverable.NOT_RECOVERABLE);
    }

    // Try to recover from where we were.
    // Find the point in the inferred server path to start resending pending
    // deltas to the server.
    int startResend = -1;
    if (startSignature.equals(connectVersion)) {
      startResend = 0;
    } else {
      int i = 0;
      Iterator<AckedDelta> iter = inferredServerPath.iterator();
      while (iter.hasNext()) {
        if (connectVersion.equals(iter.next().ack.ackedVersion)) {
          startResend = i + 1;
          break;
        }
        i++;
      }
    }

    if (startResend < 0) {
      // No matching signatures.
      throw new ChannelException(
          "Failed to recover from reconnection to server. No matching signatures. "
              + "[Received startSignature:" + connectVersion + " endSignature:" + currentVersion
              + "] " + this, Recoverable.NOT_RECOVERABLE);
    } else if (startResend < inferredServerPath.size()) {
      // Found a matching signature.
View Full Code Here

  private void processConnect(HashedVersion connectVersion,
      HashedVersion lastCommittedVersion, HashedVersion currentSignedVersion)
      throws ChannelException {
    // The first update must contain a committed version.
    if (lastCommittedVersion == null) {
      throw new ChannelException("Channel connect message lacks committed version",
          NOT_RECOVERABLE);
    }
    // Update must contain either wavelet (+ blips etc)
    // or deltas (beginning with an empty delta to communicate the initial
    // version and signature).
View Full Code Here

   */
  private void processConnectSnapshotMessage(ObservableWaveletData wavelet,
      HashedVersion lastCommittedVersion, HashedVersion currentSignedVersion)
      throws ChannelException {
    if (wavelet == null) {
      throw new ChannelException("Delta channel: invalid first wave stream message: null"
          + ", last committed version: " + lastCommittedVersion
          + "currentSignedVersion: " + currentSignedVersion, NOT_RECOVERABLE);
    }

    HashedVersion connectVersion;
View Full Code Here

   */
  private void processConnectUpdateMessage(List<TransformedWaveletDelta> deltas,
      HashedVersion lastCommittedVersion, HashedVersion currentSignedVersion)
      throws ChannelException {
    if (deltas == null || deltas.size() == 0) {
      throw new ChannelException("Delta channel: no deltas in first wave stream message",
          NOT_RECOVERABLE);
    }

    HashedVersion connectVersion;
    // This stream has reconnected at a previous version of the wavelet.
    // The first delta has zero operations. It carries the reconnect version
    // and signature.
    TransformedWaveletDelta firstDelta = deltas.get(0);
    if (firstDelta.size() != 0) {
      throw new ChannelException("Delta channel: invalid first wave stream message, "
          + "expected no ops, got " + firstDelta.size(), NOT_RECOVERABLE);
    }
    connectVersion = HashedVersion.of(firstDelta.getAppliedAtVersion(),
        firstDelta.getResultingVersion().getHistoryHash());
    logTrace("Delta channel reconnecting, connect version ",
View Full Code Here

  private void processUpdateMessage(List<TransformedWaveletDelta> deltas,
      HashedVersion lastCommittedVersion) throws ChannelException {
    if (deltas != null) {
      // Update must contain deltas or lastCommittedVersion, no wave.
      if (deltas.size() == 0 && (lastCommittedVersion == null)) {
        throw new ChannelException("Delta channel: invalid non-first wave stream message: count "
            + (deltas.size()) + "deltas (lastServerVersion: " + lastServerVersion + ")",
            NOT_RECOVERABLE);
      }
      processDeltas(deltas);
    }
View Full Code Here

   * @return the position in {@code queue} at which the message was inserted
   * @see #flushServerMessages()
   */
  private int onServerMessage(ServerMessage message) throws ChannelException {
    if (message.startVersion() < lastServerVersion) {
      throw new ChannelException("Delta channel: out of sequence server message with version "
          + message.startVersion() + ": " + message + ", " + this.toString()
          + "; lastServerVersion: " + lastServerVersion, NOT_RECOVERABLE);
    }
    int pos = queue.size();
    while (pos > 0 && (queue.get(pos - 1).compareTo(message) > 0)) {
View Full Code Here

      // Server deltas are fully processed synchronously upon receiving them,
      // and the server sends them in order with no gaps except for our own
      // submissions, so a valid gap may only occur at the front of the queue.
      if (deltaIsInFlight() && (queuePos == 0)) {
        if (gap > transmitDelta.size()) {
          throw new ChannelException("Message missing! Incoming message " + incoming
              + " expected version " + expectedVersion + ", gap " + gap + ", in-flight delta has "
              + transmitDelta.size() + " ops", Recoverable.NOT_RECOVERABLE);
        }
      } else {
        throw new ChannelException("Message missing! Incoming message " + incoming
            + " expected version " + expectedVersion + ", gap " + gap + ", no in-flight delta",
            Recoverable.NOT_RECOVERABLE);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.concurrencycontrol.common.ChannelException

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.