com.google.ipc.invalidation.external.client.types.Invalidation Java Examples

The following examples show how to use com.google.ipc.invalidation.external.client.types.Invalidation. 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: AndroidListener.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to handle a background invalidation intent. Returns {@code true} iff the intent is a
 * background invalidation intent.
 */
private boolean tryHandleBackgroundInvalidationsIntent(Intent intent) {
  byte[] data = intent.getByteArrayExtra(ProtocolIntents.BACKGROUND_INVALIDATION_KEY);
  if (data == null) {
    return false;
  }
  try {
    InvalidationMessage invalidationMessage = InvalidationMessage.parseFrom(data);
    List<Invalidation> invalidations = new ArrayList<Invalidation>();
    for (InvalidationP invalidation : invalidationMessage.getInvalidation()) {
      invalidations.add(ProtoWrapperConverter.convertFromInvalidationProto(invalidation));
    }
    backgroundInvalidateForInternalUse(invalidations);
  } catch (ValidationException exception) {
    logger.info("Failed to parse background invalidation intent payload: %s",
        exception.getMessage());
  }
  return false;
}
 
Example #2
Source File: AndroidInvalidationClientImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void invalidate(InvalidationClient client, Invalidation invalidation,
    AckHandle ackHandle) {
  try {
    AckHandleP ackHandleP = AckHandleP.parseFrom(ackHandle.getHandleData());
    issueIntent(context, ListenerUpcalls.newInvalidateIntent(
        ProtoWrapperConverter.convertToInvalidationProto(invalidation), ackHandleP));
  } catch (ValidationException exception) {
    // Log and drop invalid call.
    logBadAckHandle("invalidate", ackHandle);
  }
}
 
Example #3
Source File: InvalidationTestListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(
    InvalidationClient client, Invalidation invalidation, AckHandle ackHandle) {
  InvalidationListener listener = getListener(client);
  logger.fine("Received INVALIDATE for %s: %s", getClientKey(client), listener);
  if (listener != null) {
    listener.invalidate(client, invalidation, ackHandle);
  }
}
 
Example #4
Source File: ParcelableInvalidation.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a new invalidation wrapper by reading data from a parcel.
 */
public ParcelableInvalidation(Parcel in) {
  // Read parcelable object id from parcel using the application class loader
  ParcelableObjectId objectId = in.readParcelable(getClass().getClassLoader());
  long version = in.readLong();
  boolean isTrickleRestart = in.createBooleanArray()[0];
  boolean[] values = in.createBooleanArray();
  byte[] payload = null;
  if (values[0]) { // hasPayload
    payload = in.createByteArray();
  }
  this.invalidation = Invalidation.newInstance(objectId.objectId, version, payload,
      isTrickleRestart);
  this.includePayload = payload != null;
}
 
Example #5
Source File: AndroidClientProxy.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(
    InvalidationClient client, Invalidation invalidation, AckHandle ackHandle) {
  Event event = Event.newBuilder(Event.Action.INVALIDATE)
      .setClientKey(clientKey).setInvalidation(invalidation).setAckHandle(ackHandle).build();
  sendEvent(event);
}
 
Example #6
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(final InvalidationClient client, final Invalidation invalidation,
    final AckHandle ackHandle) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  Preconditions.checkNotNull(ackHandle);
  listenerScheduler.schedule(NO_DELAY, new NamedRunnable("CheckingInvalListener.invalidate") {
    @Override
    public void run() {
      statistics.recordListenerEvent(ListenerEventType.INVALIDATE);
      delegate.invalidate(client, invalidation, ackHandle);
    }
  });
}
 
Example #7
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 #8
Source File: AndroidInvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(InvalidationClient client, Invalidation invalidation,
    AckHandle ackHandle) {
  try {
    AckHandleP ackHandleP = AckHandleP.parseFrom(ackHandle.getHandleData());
    issueIntent(context, ListenerUpcalls.newInvalidateIntent(
        ProtoConverter.convertToInvalidationProto(invalidation), ackHandleP));
  } catch (InvalidProtocolBufferException exception) {
    // Log and drop invalid call.
    logBadAckHandle("invalidate", ackHandle);
  }
}
 
Example #9
Source File: ProtoConverter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts an invalidation {@code invalidation} to the corresponding protocol
 * buffer and returns it.
 */
public static InvalidationP convertToInvalidationProto(Invalidation invalidation) {
  Preconditions.checkNotNull(invalidation);
  ObjectIdP objectId = convertToObjectIdProto(invalidation.getObjectId());

  // Invalidations clients do not know about trickle restarts. Every invalidation is allowed
  // to suppress earlier invalidations and acks implicitly acknowledge all previous
  // invalidations. Therefore the correct semanantics are provided by setting isTrickleRestart to
  // true.
  return CommonProtos2.newInvalidationP(objectId, invalidation.getVersion(),
      TrickleState.fromBoolean(invalidation.getIsTrickleRestartForInternalUse()),
      invalidation.getPayload() == null ? null : ByteString.copyFrom(invalidation.getPayload()));
}
 
Example #10
Source File: ProtoConverter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts an invalidation protocol buffer {@code invalidation} to the
 * corresponding external object and returns it
 */
public static Invalidation convertFromInvalidationProto(InvalidationP invalidation) {
  Preconditions.checkNotNull(invalidation);
  ObjectId objectId = convertFromObjectIdProto(invalidation.getObjectId());

  // No bridge arrival time in invalidation.
  return Invalidation.newInstance(objectId, invalidation.getVersion(),
      invalidation.hasPayload() ? invalidation.getPayload().toByteArray() : null,
          invalidation.getIsTrickleRestart());
}
 
Example #11
Source File: ExampleListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(Invalidation invalidation, byte[] ackHandle) {
  Log.i(TAG, "invalidate: " + invalidation);

  // Do real work here based upon the invalidation
  MainActivity.State.setVersion(
      invalidation.getObjectId(), "invalidate", invalidation.toString());

  acknowledge(ackHandle);
}
 
Example #12
Source File: InvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(Invalidation invalidation, byte[] ackHandle) {
    byte[] payload = invalidation.getPayload();
    String payloadStr = (payload == null) ? null : new String(payload);
    requestSync(invalidation.getObjectId(), invalidation.getVersion(), payloadStr);
    acknowledge(ackHandle);
}
 
Example #13
Source File: InvalidationTestListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(
    InvalidationClient client, Invalidation invalidation, AckHandle ackHandle) {
  InvalidationListener listener = getListener(client);
  logger.fine("Received INVALIDATE for %s: %s", getClientKey(client), listener);
  if (listener != null) {
    listener.invalidate(client, invalidation, ackHandle);
  }
}
 
Example #14
Source File: ParcelableInvalidation.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a new invalidation wrapper by reading data from a parcel.
 */
public ParcelableInvalidation(Parcel in) {
  // Read parcelable object id from parcel using the application class loader
  ParcelableObjectId objectId = in.readParcelable(getClass().getClassLoader());
  long version = in.readLong();
  boolean isTrickleRestart = in.createBooleanArray()[0];
  boolean[] values = in.createBooleanArray();
  byte[] payload = null;
  if (values[0]) { // hasPayload
    payload = in.createByteArray();
  }
  this.invalidation = Invalidation.newInstance(objectId.objectId, version, payload,
      isTrickleRestart);
  this.includePayload = payload != null;
}
 
Example #15
Source File: AndroidClientProxy.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(
    InvalidationClient client, Invalidation invalidation, AckHandle ackHandle) {
  Event event = Event.newBuilder(Event.Action.INVALIDATE)
      .setClientKey(clientKey).setInvalidation(invalidation).setAckHandle(ackHandle).build();
  sendEvent(event);
}
 
Example #16
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(final InvalidationClient client, final Invalidation invalidation,
    final AckHandle ackHandle) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  Preconditions.checkNotNull(ackHandle);
  listenerScheduler.schedule(NO_DELAY, new NamedRunnable("CheckingInvalListener.invalidate") {
    @Override
    public void run() {
      statistics.recordListenerEvent(ListenerEventType.INVALIDATE);
      delegate.invalidate(client, invalidation, ackHandle);
    }
  });
}
 
Example #17
Source File: AndroidInvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(InvalidationClient client, Invalidation invalidation,
    AckHandle ackHandle) {
  try {
    AckHandleP ackHandleP = AckHandleP.parseFrom(ackHandle.getHandleData());
    issueIntent(context, ListenerUpcalls.newInvalidateIntent(
        ProtoConverter.convertToInvalidationProto(invalidation), ackHandleP));
  } catch (InvalidProtocolBufferException exception) {
    // Log and drop invalid call.
    logBadAckHandle("invalidate", ackHandle);
  }
}
 
Example #18
Source File: InvalidationClientService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void invalidate(Invalidation invalidation, byte[] ackHandle) {
    byte[] payload = invalidation.getPayload();
    String payloadStr = (payload == null) ? null : new String(payload);
    requestSync(invalidation.getObjectId(), invalidation.getVersion(), payloadStr);
    acknowledge(ackHandle);
}
 
Example #19
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 #20
Source File: CheckingInvalidationListener.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void invalidate(final InvalidationClient client, final Invalidation invalidation,
    final AckHandle ackHandle) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  Preconditions.checkNotNull(ackHandle);
  listenerScheduler.schedule(NO_DELAY, new NamedRunnable("CheckingInvalListener.invalidate") {
    @Override
    public void run() {
      statistics.recordListenerEvent(ListenerEventType.INVALIDATE);
      delegate.invalidate(client, invalidation, ackHandle);
    }
  });
}
 
Example #21
Source File: ProtoWrapperConverter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an invalidation protocol buffer {@code invalidation} to the
 * corresponding external object and returns it
 */
public static Invalidation convertFromInvalidationProto(InvalidationP invalidation) {
  Preconditions.checkNotNull(invalidation);
  ObjectId objectId = convertFromObjectIdProto(invalidation.getObjectId());

  // No bridge arrival time in invalidation.
  return Invalidation.newInstance(objectId, invalidation.getVersion(),
      invalidation.hasPayload() ? invalidation.getPayload().getByteArray() : null,
          invalidation.getIsTrickleRestart());
}
 
Example #22
Source File: ProtoWrapperConverter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an invalidation {@code invalidation} to the corresponding protocol
 * buffer and returns it.
 */
public static InvalidationP convertToInvalidationProto(Invalidation invalidation) {
  Preconditions.checkNotNull(invalidation);
  ObjectIdP objectId = convertToObjectIdProto(invalidation.getObjectId());

  // Invalidations clients do not know about trickle restarts. Every invalidation is allowed
  // to suppress earlier invalidations and acks implicitly acknowledge all previous
  // invalidations. Therefore the correct semanantics are provided by setting isTrickleRestart to
  // true.
  return CommonProtos.newInvalidationP(objectId, invalidation.getVersion(),
      invalidation.getIsTrickleRestartForInternalUse(), invalidation.getPayload());
}
 
Example #23
Source File: InvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(Invalidation invalidation, byte[] ackHandle) {
    byte[] payload = invalidation.getPayload();
    String payloadStr = (payload == null) ? null : new String(payload);
    requestSync(invalidation.getObjectId(), invalidation.getVersion(), payloadStr);
    acknowledge(ackHandle);
}
 
Example #24
Source File: ExampleListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidate(Invalidation invalidation, byte[] ackHandle) {
  Log.i(TAG, "invalidate: " + invalidation);

  // Do real work here based upon the invalidation
  MainActivity.State.setVersion(
      invalidation.getObjectId(), "invalidate", invalidation.toString());

  acknowledge(ackHandle);
}
 
Example #25
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 #26
Source File: ProtoConverter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts an invalidation protocol buffer {@code invalidation} to the
 * corresponding external object and returns it
 */
public static Invalidation convertFromInvalidationProto(InvalidationP invalidation) {
  Preconditions.checkNotNull(invalidation);
  ObjectId objectId = convertFromObjectIdProto(invalidation.getObjectId());

  // No bridge arrival time in invalidation.
  return Invalidation.newInstance(objectId, invalidation.getVersion(),
      invalidation.hasPayload() ? invalidation.getPayload().toByteArray() : null,
          invalidation.getIsTrickleRestart());
}
 
Example #27
Source File: ProtoConverter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts an invalidation {@code invalidation} to the corresponding protocol
 * buffer and returns it.
 */
public static InvalidationP convertToInvalidationProto(Invalidation invalidation) {
  Preconditions.checkNotNull(invalidation);
  ObjectIdP objectId = convertToObjectIdProto(invalidation.getObjectId());

  // Invalidations clients do not know about trickle restarts. Every invalidation is allowed
  // to suppress earlier invalidations and acks implicitly acknowledge all previous
  // invalidations. Therefore the correct semanantics are provided by setting isTrickleRestart to
  // true.
  return CommonProtos2.newInvalidationP(objectId, invalidation.getVersion(),
      TrickleState.fromBoolean(invalidation.getIsTrickleRestartForInternalUse()),
      invalidation.getPayload() == null ? null : ByteString.copyFrom(invalidation.getPayload()));
}
 
Example #28
Source File: Event.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Stores in invalidation within an event message.
 */
public Builder setInvalidation(Invalidation invalidation) {
  bundle.putParcelable(Parameter.INVALIDATION, new ParcelableInvalidation(invalidation, true));
  return this;
}
 
Example #29
Source File: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void invalidate(InvalidationClient client, Invalidation invalidation,
    AckHandle ackHandle) {
  AndroidListener.this.invalidate(invalidation, ackHandle.getHandleData());
}
 
Example #30
Source File: ParcelableInvalidation.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Creates a new wrapper around the provided invalidation
 */
ParcelableInvalidation(Invalidation invalidation, boolean includePayload) {
  this.invalidation = invalidation;
  this.includePayload = includePayload;
}