com.google.ipc.invalidation.ticl.Statistics.ReceivedMessageType Java Examples

The following examples show how to use com.google.ipc.invalidation.ticl.Statistics.ReceivedMessageType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Handles incoming {@code invalidations}. */
private void handleInvalidations(Collection<InvalidationP> invalidations) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");

  for (InvalidationP invalidation : invalidations) {
    AckHandle ackHandle = AckHandle.newInstance(AckHandleP.create(invalidation).toByteArray());
    if (ackCache.isAcked(invalidation)) {
      // If the ack cache indicates that the client has already acked a restarted invalidation
      // with an equal or greater version, then the TICL can simply acknowledge it immediately
      // rather than delivering it to the listener.
      logger.info("Stale invalidation {0}, not delivering", invalidation);
      acknowledge(ackHandle);
      statistics.recordReceivedMessage(ReceivedMessageType.STALE_INVALIDATION);
    } else if (CommonProtos.isAllObjectId(invalidation.getObjectId())) {
      logger.info("Issuing invalidate all");
      listener.invalidateAll(InvalidationClientCore.this, ackHandle);
    } else {
      // Regular object. Could be unknown version or not.
      Invalidation inv = ProtoWrapperConverter.convertFromInvalidationProto(invalidation);

      boolean isSuppressed = invalidation.getIsTrickleRestart();
      logger.info("Issuing invalidate (known-version = %s, is-trickle-restart = %s): %s",
          invalidation.getIsKnownVersion(), isSuppressed, inv);

      // Issue invalidate if the invalidation had a known version AND either no suppression has
      // occurred or the client allows suppression.
      if (invalidation.getIsKnownVersion() &&
          (!isSuppressed || InvalidationClientCore.this.config.getAllowSuppression())) {
        listener.invalidate(InvalidationClientCore.this, inv, ackHandle);
      } else {
        // Otherwise issue invalidateUnknownVersion.
        listener.invalidateUnknownVersion(InvalidationClientCore.this, inv.getObjectId(),
            ackHandle);
      }
    }
  }
}
 
Example #2
Source File: ProtocolHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a message from the server. If the message can be processed (i.e., is valid, is
 * of the right version, and is not a silence message), returns a {@link ParsedMessage}
 * representing it. Otherwise, returns {@code null}.
 * <p>
 * This class intercepts and processes silence messages. In this case, it will discard any other
 * data in the message.
 * <p>
 * Note that this method does <b>not</b> check the session token of any message.
 */
ParsedMessage handleIncomingMessage(byte[] incomingMessage) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  ServerToClientMessage message;
  try {
    message = ServerToClientMessage.parseFrom(incomingMessage);
  } catch (ValidationException exception) {
    statistics.recordError(ClientErrorType.INCOMING_MESSAGE_FAILURE);
    logger.warning("Incoming message is invalid: %s", Bytes.toLazyCompactString(incomingMessage));
    return null;
  }

  // Check the version of the message.
  if (message.getHeader().getProtocolVersion().getVersion().getMajorVersion() !=
      ClientConstants.PROTOCOL_MAJOR_VERSION) {
    statistics.recordError(ClientErrorType.PROTOCOL_VERSION_FAILURE);
    logger.severe("Dropping message with incompatible version: %s", message);
    return null;
  }

  // Check if it is a ConfigChangeMessage which indicates that messages should no longer be
  // sent for a certain duration. Perform this check before the token is even checked.
  if (message.hasConfigChangeMessage()) {
    ConfigChangeMessage configChangeMsg = message.getConfigChangeMessage();
    statistics.recordReceivedMessage(ReceivedMessageType.CONFIG_CHANGE);
    if (configChangeMsg.hasNextMessageDelayMs()) {  // Validator has ensured that it is positive.
      nextMessageSendTimeMs =
          internalScheduler.getCurrentTimeMs() + configChangeMsg.getNextMessageDelayMs();
    }
    return null;  // Ignore all other messages in the envelope.
  }

  lastKnownServerTimeMs = Math.max(lastKnownServerTimeMs, message.getHeader().getServerTimeMs());
  return new ParsedMessage(message);
}
 
Example #3
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Handles an {@code incomingMessage} from the data center. If it is valid and addressed to
 * this client, dispatches to methods to handle sub-parts of the message; if not, drops the
 * message.
 */
void handleIncomingMessage(byte[] incomingMessage) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  statistics.recordReceivedMessage(ReceivedMessageType.TOTAL);
  ParsedMessage parsedMessage = protocolHandler.handleIncomingMessage(incomingMessage);
  if (parsedMessage == null) {
    // Invalid message.
    return;
  }

  // Ensure we have either a matching token or a matching nonce.
  if (!validateToken(parsedMessage)) {
    return;
  }

  // Handle a token-control message, if present.
  if (parsedMessage.tokenControlMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.TOKEN_CONTROL);
    handleTokenChanged(parsedMessage.header.token,
        parsedMessage.tokenControlMessage.hasNewToken() ?
            parsedMessage.tokenControlMessage.getNewToken() : null);
  }

  // We might have lost our token or failed to acquire one. Ensure that we do not proceed in
  // either case.
  if (clientToken == null) {
    return;
  }

  // First, handle the message header.
  handleIncomingHeader(parsedMessage.header);

  // Then, handle any work remaining in the message.
  if (parsedMessage.invalidationMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.INVALIDATION);
    handleInvalidations(parsedMessage.invalidationMessage.getInvalidation());
  }
  if (parsedMessage.registrationStatusMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.REGISTRATION_STATUS);
    handleRegistrationStatus(parsedMessage.registrationStatusMessage.getRegistrationStatus());
  }
  if (parsedMessage.registrationSyncRequestMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.REGISTRATION_SYNC_REQUEST);
    handleRegistrationSyncRequest();
  }
  if (parsedMessage.infoRequestMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.INFO_REQUEST);
    handleInfoMessage(parsedMessage.infoRequestMessage.getInfoType());
  }
  if (parsedMessage.errorMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.ERROR);
    handleErrorMessage(parsedMessage.header, parsedMessage.errorMessage.getCode(),
        parsedMessage.errorMessage.getDescription());
  }
}
 
Example #4
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Handles an {@code incomingMessage} from the data center. If it is valid and addressed to
 * this client, dispatches to methods to handle sub-parts of the message; if not, drops the
 * message.
 */
void handleIncomingMessage(byte[] incomingMessage) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  statistics.recordReceivedMessage(ReceivedMessageType.TOTAL);
  ParsedMessage parsedMessage = protocolHandler.handleIncomingMessage(incomingMessage);
  if (parsedMessage == null) {
    // Invalid message.
    return;
  }

  // Ensure we have either a matching token or a matching nonce.
  if (!validateToken(parsedMessage)) {
    return;
  }

  // Handle a token-control message, if present.
  if (parsedMessage.tokenControlMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.TOKEN_CONTROL);
    handleTokenChanged(parsedMessage.header.token,
        parsedMessage.tokenControlMessage.hasNewToken() ?
            parsedMessage.tokenControlMessage.getNewToken() : null);
  }

  // We might have lost our token or failed to acquire one. Ensure that we do not proceed in
  // either case.
  if (clientToken == null) {
    return;
  }

  // First, handle the message header.
  handleIncomingHeader(parsedMessage.header);

  // Then, handle any work remaining in the message.
  if (parsedMessage.invalidationMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.INVALIDATION);
    handleInvalidations(parsedMessage.invalidationMessage.getInvalidationList());
  }
  if (parsedMessage.registrationStatusMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.REGISTRATION_STATUS);
    handleRegistrationStatus(parsedMessage.registrationStatusMessage.getRegistrationStatusList());
  }
  if (parsedMessage.registrationSyncRequestMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.REGISTRATION_SYNC_REQUEST);
    handleRegistrationSyncRequest();
  }
  if (parsedMessage.infoRequestMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.INFO_REQUEST);
    handleInfoMessage(parsedMessage.infoRequestMessage.getInfoTypeList());
  }
  if (parsedMessage.errorMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.ERROR);
    handleErrorMessage(parsedMessage.header, parsedMessage.errorMessage.getCode(),
        parsedMessage.errorMessage.getDescription());
  }
}
 
Example #5
Source File: ProtocolHandler.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Handles a message from the server. If the message can be processed (i.e., is valid, is
 * of the right version, and is not a silence message), returns a {@link ParsedMessage}
 * representing it. Otherwise, returns {@code null}.
 * <p>
 * This class intercepts and processes silence messages. In this case, it will discard any other
 * data in the message.
 * <p>
 * Note that this method does <b>not</b> check the session token of any message.
 */
ParsedMessage handleIncomingMessage(byte[] incomingMessage) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  ServerToClientMessage message;
  try {
    message = ServerToClientMessage.parseFrom(incomingMessage);
  } catch (InvalidProtocolBufferException exception) {
    logger.warning("Incoming message is unparseable: %s",
        CommonProtoStrings2.toLazyCompactString(incomingMessage));
    return null;
  }

  // Validate the message. If this passes, we can blindly assume valid messages from here on.
  logger.fine("Incoming message: %s", message);
  if (!msgValidator.isValid(message)) {
    statistics.recordError(ClientErrorType.INCOMING_MESSAGE_FAILURE);
    logger.severe("Received invalid message: %s", message);
    return null;
  }

  // Check the version of the message.
  if (message.getHeader().getProtocolVersion().getVersion().getMajorVersion() !=
      CommonInvalidationConstants2.PROTOCOL_MAJOR_VERSION) {
    statistics.recordError(ClientErrorType.PROTOCOL_VERSION_FAILURE);
    logger.severe("Dropping message with incompatible version: %s", message);
    return null;
  }

  // Check if it is a ConfigChangeMessage which indicates that messages should no longer be
  // sent for a certain duration. Perform this check before the token is even checked.
  if (message.hasConfigChangeMessage()) {
    ConfigChangeMessage configChangeMsg = message.getConfigChangeMessage();
    statistics.recordReceivedMessage(ReceivedMessageType.CONFIG_CHANGE);
    if (configChangeMsg.hasNextMessageDelayMs()) {  // Validator has ensured that it is positive.
      nextMessageSendTimeMs =
          internalScheduler.getCurrentTimeMs() + configChangeMsg.getNextMessageDelayMs();
    }
    return null;  // Ignore all other messages in the envelope.
  }

  lastKnownServerTimeMs = Math.max(lastKnownServerTimeMs, message.getHeader().getServerTimeMs());
  return new ParsedMessage(message);
}
 
Example #6
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Handles an {@code incomingMessage} from the data center. If it is valid and addressed to
 * this client, dispatches to methods to handle sub-parts of the message; if not, drops the
 * message.
 */
void handleIncomingMessage(byte[] incomingMessage) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  statistics.recordReceivedMessage(ReceivedMessageType.TOTAL);
  ParsedMessage parsedMessage = protocolHandler.handleIncomingMessage(incomingMessage);
  if (parsedMessage == null) {
    // Invalid message.
    return;
  }

  // Ensure we have either a matching token or a matching nonce.
  if (!validateToken(parsedMessage)) {
    return;
  }

  // Handle a token-control message, if present.
  if (parsedMessage.tokenControlMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.TOKEN_CONTROL);
    handleTokenChanged(parsedMessage.header.token,
        parsedMessage.tokenControlMessage.hasNewToken() ?
            parsedMessage.tokenControlMessage.getNewToken() : null);
  }

  // We might have lost our token or failed to acquire one. Ensure that we do not proceed in
  // either case.
  if (clientToken == null) {
    return;
  }

  // First, handle the message header.
  handleIncomingHeader(parsedMessage.header);

  // Then, handle any work remaining in the message.
  if (parsedMessage.invalidationMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.INVALIDATION);
    handleInvalidations(parsedMessage.invalidationMessage.getInvalidationList());
  }
  if (parsedMessage.registrationStatusMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.REGISTRATION_STATUS);
    handleRegistrationStatus(parsedMessage.registrationStatusMessage.getRegistrationStatusList());
  }
  if (parsedMessage.registrationSyncRequestMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.REGISTRATION_SYNC_REQUEST);
    handleRegistrationSyncRequest();
  }
  if (parsedMessage.infoRequestMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.INFO_REQUEST);
    handleInfoMessage(parsedMessage.infoRequestMessage.getInfoTypeList());
  }
  if (parsedMessage.errorMessage != null) {
    statistics.recordReceivedMessage(ReceivedMessageType.ERROR);
    handleErrorMessage(parsedMessage.header, parsedMessage.errorMessage.getCode(),
        parsedMessage.errorMessage.getDescription());
  }
}
 
Example #7
Source File: ProtocolHandler.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Handles a message from the server. If the message can be processed (i.e., is valid, is
 * of the right version, and is not a silence message), returns a {@link ParsedMessage}
 * representing it. Otherwise, returns {@code null}.
 * <p>
 * This class intercepts and processes silence messages. In this case, it will discard any other
 * data in the message.
 * <p>
 * Note that this method does <b>not</b> check the session token of any message.
 */
ParsedMessage handleIncomingMessage(byte[] incomingMessage) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  ServerToClientMessage message;
  try {
    message = ServerToClientMessage.parseFrom(incomingMessage);
  } catch (InvalidProtocolBufferException exception) {
    logger.warning("Incoming message is unparseable: %s",
        CommonProtoStrings2.toLazyCompactString(incomingMessage));
    return null;
  }

  // Validate the message. If this passes, we can blindly assume valid messages from here on.
  logger.fine("Incoming message: %s", message);
  if (!msgValidator.isValid(message)) {
    statistics.recordError(ClientErrorType.INCOMING_MESSAGE_FAILURE);
    logger.severe("Received invalid message: %s", message);
    return null;
  }

  // Check the version of the message.
  if (message.getHeader().getProtocolVersion().getVersion().getMajorVersion() !=
      CommonInvalidationConstants2.PROTOCOL_MAJOR_VERSION) {
    statistics.recordError(ClientErrorType.PROTOCOL_VERSION_FAILURE);
    logger.severe("Dropping message with incompatible version: %s", message);
    return null;
  }

  // Check if it is a ConfigChangeMessage which indicates that messages should no longer be
  // sent for a certain duration. Perform this check before the token is even checked.
  if (message.hasConfigChangeMessage()) {
    ConfigChangeMessage configChangeMsg = message.getConfigChangeMessage();
    statistics.recordReceivedMessage(ReceivedMessageType.CONFIG_CHANGE);
    if (configChangeMsg.hasNextMessageDelayMs()) {  // Validator has ensured that it is positive.
      nextMessageSendTimeMs =
          internalScheduler.getCurrentTimeMs() + configChangeMsg.getNextMessageDelayMs();
    }
    return null;  // Ignore all other messages in the envelope.
  }

  lastKnownServerTimeMs = Math.max(lastKnownServerTimeMs, message.getHeader().getServerTimeMs());
  return new ParsedMessage(message);
}