Package org.waveprotocol.wave.concurrencycontrol.common

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


      // 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


      @Override
      public void onSuccess(int opsApplied, HashedVersion newVersion, ResponseCode responseCode,
          String errorMessage) throws ChannelException {
        if (connectionIsCurrent()) {
          if (opsApplied < 0) {
            throw new ChannelException("Delta channel: invalid submit delta response, opsApplied: "
                + opsApplied, NOT_RECOVERABLE);
          }

          // TODO(danilatos): (1/12/2009) Remove this if statement once the
          // error code field is made required in the proto.
          if (errorMessage != null && responseCode == ResponseCode.OK) {
            responseCode = ResponseCode.INTERNAL_ERROR;
          }

          if (opsApplied > 0 || responseCode == ResponseCode.OK) {
            // It is not necessarily the case that
            // opsApplied == delta.getOpListSize() since ops may disappear in
            // transform. Zero ops applied is a valid ack when the server
            // transforms all operations away.
            lastAckedVersion = newVersion;
            onServerMessage(new ServerMessage.Ack(opsApplied, newVersion));
          }

          if (responseCode == ResponseCode.TOO_OLD) {
            throw new ChannelException(ResponseCode.TOO_OLD, "Delta targeted too old version",
                null, Recoverable.RECOVERABLE, null, null);
          } else if (responseCode != ResponseCode.OK) {
            // Using lastServerVersion when opsApplied is 0 is a harmless cop out to deal with the
            // fact that the view server access control responds with a bogus version and 0
            // opsApplied when it rejects a delta.
            onServerMessage(new ServerMessage.Nack(
                (opsApplied > 0) ? newVersion.getVersion() : lastServerVersion,
                responseCode, errorMessage));
          }

          lastTransmitDelta = transmitDelta;
          transmitDelta = null; // Enables flushServerMessages() to transmit.
          flushServerMessages();

          // Check the ack didn't leave a gap in the queue.
          if (!queue.isEmpty() &&
              (queue.get(0).startVersion() != (newVersion.getVersion() - opsApplied))) {
            throw new ChannelException(
                "Delta channel couldn't flush messages after submit response: lastServerVersion "
                    + lastServerVersion + ", queued message version " + queue.get(0).startVersion()
                    + " response version " + newVersion + ", opsApplied " + opsApplied + ", code "
                    + responseCode + ", errorMessage " + errorMessage,
                Recoverable.NOT_RECOVERABLE);
          }
        }
      }

      @Override
      public void onFailure(String reason) throws ChannelException {
        if (connectionIsCurrent()) {
          throw new ChannelException("Delta channel: submission failed: " + reason, RECOVERABLE);
        }
      }

      /**
       * Checks whether the channel is connected and connection tag is current,
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

      if (logger.trace().shouldLog()) {
        logger.trace().log("Received delta: ", delta);
      }
      cc.onServerDelta(delta);
    } catch (TransformException e) {
      throw new ChannelException(ResponseCode.INVALID_OPERATION,
          "Operation channel failed on server delta: " + this + ", " + deltaChannel + ", " + cc,
          e, Recoverable.NOT_RECOVERABLE, null, null);
    } catch (OperationException e) {
      throw new ChannelException(
          e.isSchemaViolation() ? ResponseCode.SCHEMA_VIOLATION : ResponseCode.INVALID_OPERATION,
          "Operation channel failed on server delta: " + this + ", " + deltaChannel + ", " + cc,
          e, Recoverable.NOT_RECOVERABLE, null, null);
    }
  }
View Full Code Here

  @Override
  public void onAck(int opsApplied, HashedVersion signature) throws ChannelException {
    try {
      cc.onSuccess(opsApplied, signature);
    } catch (TransformException e) {
      throw new ChannelException(ResponseCode.INVALID_OPERATION,
          "Operation channel failed on ack: " + this + ", " + deltaChannel + ", " + cc,
          e, Recoverable.NOT_RECOVERABLE, null,
          null);
    }
  }
View Full Code Here

  }

  @Override
  public void onNack(ResponseCode responseCode, String errorString, long version)
      throws ChannelException {
    throw new ChannelException(responseCode,
        "Operation channel failed on nack: code=" + responseCode + ", "
        + errorString + ", " + this + ", " + deltaChannel + ", " + cc,
        null, Recoverable.NOT_RECOVERABLE, null, null);

  }
View Full Code Here

      logger.error().log("Cannot send to closed operation channel: " + this);
    } else if (accessibility.isWritable()) {
      try {
        cc.onClientOperations(operations);
      } catch (TransformException e) {
        throw new ChannelException(ResponseCode.INVALID_OPERATION,
            "Operation channel failed on send: " + this + ", " + deltaChannel + ", " + cc, e,
            Recoverable.NOT_RECOVERABLE, null, null);
      }
    } else {
      throw new ChannelException(ResponseCode.NOT_AUTHORIZED,
          "Attempt to write to inaccessible wavelet", null, Recoverable.NOT_RECOVERABLE, null, null);
    }
  }
View Full Code Here

        whichData.append("lastCommittedVersion, ");
      }
      if (update.hasCurrentVersion()) {
        whichData.append("currentVersion");
      }
      throw new ChannelException("An update contained a channel id AND other data: " + whichData,
          Recoverable.NOT_RECOVERABLE);
    }
    if ((update.hasWaveletSnapshot() || update.hasDeltas() ||
        update.hasLastCommittedVersion() || update.hasCurrentVersion()) &&
        !update.hasWaveletId()) {
      throw new ChannelException("An update lacked a required wavelet id.",
          Recoverable.NOT_RECOVERABLE);
    }
    if (update.hasWaveletSnapshot() && update.hasDeltas()) {
      throw new ChannelException("Message has both snapshot and deltas",
          Recoverable.NOT_RECOVERABLE);
    }
  }
View Full Code Here

            "Unexpected update before view channel opened: %s, update: %s", this, update);
        break;
      case CONNECTING:
        // First update: extract channel id.
        if (!update.hasChannelId()) {
          onException(new ChannelException("First update did not contain channel id. Wave id: " +
            waveId + ", update: " + update, Recoverable.NOT_RECOVERABLE));
          return;
        }
        channelId = update.getChannelId();
        state = State.CONNECTED;
        if (openListener != null) {
          openListener.onConnected();
        }
        break;
      case CONNECTED:
        if (update.hasChannelId()) {
          logger.trace().log("A non-first update contained a channel id: " + update);
        }
        if (openListener != null) {
          WaveletId waveletId = update.hasWaveletId() ? update.getWaveletId() : null;
          HashedVersion lastCommittedVersion = update.hasLastCommittedVersion() ?
              update.getLastCommittedVersion() : null;
          HashedVersion currentVersion = update.hasCurrentVersion() ?
              update.getCurrentVersion() : null;
          try {
            if (update.hasWaveletSnapshot()) {
              // it's a snapshot
              openListener.onSnapshot(waveletId, update.getWaveletSnapshot(),
                  lastCommittedVersion, currentVersion);
            } else if (update.hasDeltas() || update.hasLastCommittedVersion() ||
                update.hasCurrentVersion()) {
              // it's deltas or versions.
              openListener.onUpdate(waveletId, update.getDeltaList(),
                  lastCommittedVersion, currentVersion);
            }
            if (update.hasMarker()) {
              openListener.onOpenFinished();
            }
          } catch (ChannelException e) {
            triggerOnException(e, waveletId);
            terminate("View update raised exception: " + e.toString());
          }
        }
        break;
      case CLOSING:
        // Already closed: do nothing, except in the following special case.
        // If the channel was closed on the client end before any updates were received from the
        // server, then at that point the ViewClose could not have been sent (because there was no
        // channel id to close).  Therefore, if the channel receives its first update (identified
        // by !this.hasChannelId()) when it is already in the CLOSED state, it is assumed that the
        // above scenario has occurred, in which case the ViewClose must be sent now.
        //
        if (!hasChannelId()) {
          if (!update.hasChannelId()) {
            // TODO(anorth): checked exception
            onException(new ChannelException("First update did not contain channel id. Wave id: " +
              waveId + ", update: " + update, Recoverable.NOT_RECOVERABLE));
          }
          channelId = update.getChannelId();
          requestViewClose();
        }
View Full Code Here

            this, response);
        break;
      case CONNECTING:
      case CONNECTED:
        if (fatal) {
          triggerOnException(new ChannelException("Server unexpectedly closed channel" +
              " with error: " + errorMessage, Recoverable.NOT_RECOVERABLE), null);
        }
        terminate("Received onSuccess in state " + state + " with message: " + errorMessage);
        break;
      case CLOSING:
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.