Java Code Examples for com.google.ipc.invalidation.external.client.types.AckHandle#newInstance()

The following examples show how to use com.google.ipc.invalidation.external.client.types.AckHandle#newInstance() . 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: AndroidInvalidationListenerIntentMapper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Handles an invalidation-related listener {@code upcall} by dispatching to the appropriate
 * method on an instance of {@link InvalidationListener}.
 */
private void onInvalidateUpcall(InvalidateUpcall invalidate, InvalidationListener listener) {
  AckHandle ackHandle = AckHandle.newInstance(invalidate.getAckHandle().getByteArray());
  if (invalidate.getNullableInvalidation() != null) {
    listener.invalidate(client,
        ProtoWrapperConverter.convertFromInvalidationProto(invalidate.getNullableInvalidation()),
        ackHandle);
  } else if (invalidate.hasInvalidateAll()) {
    listener.invalidateAll(client, ackHandle);
  } else if (invalidate.getNullableInvalidateUnknown() != null) {
    listener.invalidateUnknownVersion(client,
        ProtoWrapperConverter.convertFromObjectIdProto(invalidate.getNullableInvalidateUnknown()),
        ackHandle);
  } else {
    throw new RuntimeException("Invalid invalidate upcall: " + invalidate);
  }
}
 
Example 2
Source File: AndroidInvalidationListenerIntentMapper.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Handles an invalidation-related listener {@code upcall} by dispatching to the appropriate
 * method on an instance of {@link #listenerClass}.
 */
private void onInvalidateUpcall(ListenerUpcall upcall, InvalidationListener listener) {
  InvalidateUpcall invalidate = upcall.getInvalidate();
  AckHandle ackHandle = AckHandle.newInstance(invalidate.getAckHandle().toByteArray());
  if (invalidate.hasInvalidation()) {
    listener.invalidate(client,
        ProtoConverter.convertFromInvalidationProto(invalidate.getInvalidation()),
        ackHandle);
  } else if (invalidate.hasInvalidateAll()) {
    listener.invalidateAll(client, ackHandle);
  } else if (invalidate.hasInvalidateUnknown()) {
    listener.invalidateUnknownVersion(client,
        ProtoConverter.convertFromObjectIdProto(invalidate.getInvalidateUnknown()), ackHandle);
  } else {
    throw new RuntimeException("Invalid invalidate upcall: " + invalidate);
  }
}
 
Example 3
Source File: AndroidInvalidationListenerIntentMapper.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Handles an invalidation-related listener {@code upcall} by dispatching to the appropriate
 * method on an instance of {@link #listenerClass}.
 */
private void onInvalidateUpcall(ListenerUpcall upcall, InvalidationListener listener) {
  InvalidateUpcall invalidate = upcall.getInvalidate();
  AckHandle ackHandle = AckHandle.newInstance(invalidate.getAckHandle().toByteArray());
  if (invalidate.hasInvalidation()) {
    listener.invalidate(client,
        ProtoConverter.convertFromInvalidationProto(invalidate.getInvalidation()),
        ackHandle);
  } else if (invalidate.hasInvalidateAll()) {
    listener.invalidateAll(client, ackHandle);
  } else if (invalidate.hasInvalidateUnknown()) {
    listener.invalidateUnknownVersion(client,
        ProtoConverter.convertFromObjectIdProto(invalidate.getInvalidateUnknown()), ackHandle);
  } else {
    throw new RuntimeException("Invalid invalidate upcall: " + invalidate);
  }
}
 
Example 4
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 5
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 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(
        CommonProtos2.newAckHandleP(invalidation).toByteArray());
    if (CommonProtos2.isAllObjectId(invalidation.getObjectId())) {
      logger.info("Issuing invalidate all");
      listener.invalidateAll(InvalidationClientCore.this, ackHandle);
    } else {
      // Regular object. Could be unknown version or not.
      Invalidation inv = ProtoConverter.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 6
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 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(
        CommonProtos2.newAckHandleP(invalidation).toByteArray());
    if (CommonProtos2.isAllObjectId(invalidation.getObjectId())) {
      logger.info("Issuing invalidate all");
      listener.invalidateAll(InvalidationClientCore.this, ackHandle);
    } else {
      // Regular object. Could be unknown version or not.
      Invalidation inv = ProtoConverter.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 7
Source File: Message.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the acknowledgement handle set on the message or {@code null} if not set */
public AckHandle getAckHandle() {
  byte [] tokenData = parameters.getByteArray(Parameter.ACK_TOKEN);
  return tokenData != null ? AckHandle.newInstance(tokenData) : null;
}
 
Example 8
Source File: Message.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the acknowledgement handle set on the message or {@code null} if not set */
public AckHandle getAckHandle() {
  byte [] tokenData = parameters.getByteArray(Parameter.ACK_TOKEN);
  return tokenData != null ? AckHandle.newInstance(tokenData) : null;
}