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

The following examples show how to use com.google.ipc.invalidation.external.client.types.AckHandle. 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 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 #2
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 #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 android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override  // InvalidationClient
public void acknowledge(final AckHandle acknowledgeHandle) {
  Preconditions.checkNotNull(acknowledgeHandle);
  Preconditions.checkState(internalScheduler.isRunningOnThread(),
      "Not running on internal thread");

  // 1. Parse the ack handle first.
  AckHandleP ackHandle;
  try {
    ackHandle = AckHandleP.parseFrom(acknowledgeHandle.getHandleData());
  } catch (InvalidProtocolBufferException exception) {
    logger.warning("Bad ack handle : %s",
      CommonProtoStrings2.toLazyCompactString(acknowledgeHandle.getHandleData()));
    statistics.recordError(ClientErrorType.ACKNOWLEDGE_HANDLE_FAILURE);
    return;
  }

  // 2. Validate ack handle - it should have a valid invalidation.
  if (!ackHandle.hasInvalidation() ||
      !msgValidator.isValid(ackHandle.getInvalidation())) {
    logger.warning("Incorrect ack handle data: %s", acknowledgeHandle);
    statistics.recordError(ClientErrorType.ACKNOWLEDGE_HANDLE_FAILURE);
    return;
  }

  // Currently, only invalidations have non-trivial ack handle.
  InvalidationP invalidation = ackHandle.getInvalidation();
  if (invalidation.hasPayload()) {
    // Don't send the payload back.
    invalidation = invalidation.toBuilder().clearPayload().build();
  }
  statistics.recordIncomingOperation(IncomingOperationType.ACKNOWLEDGE);
  protocolHandler.sendInvalidationAck(invalidation, batchingTask);
}
 
Example #5
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 #6
Source File: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Tries to handle an ack intent. Returns {@code true} iff the intent is an ack intent. */
private boolean tryHandleAckIntent(Intent intent) {
  byte[] data = AndroidListenerIntents.findAckHandle(intent);
  if (data == null) {
    return false;
  }
  getClient().acknowledge(AckHandle.newInstance(data));
  return true;
}
 
Example #7
Source File: AndroidInvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void acknowledge(AckHandle ackHandle) {
  Request request = Request
      .newBuilder(Action.ACKNOWLEDGE)
      .setClientKey(clientKey)
      .setAckHandle(ackHandle)
      .build();
  executeServiceRequest(request);
}
 
Example #8
Source File: InvalidationTestListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateAll(InvalidationClient client, AckHandle ackHandle) {
  InvalidationListener listener = getListener(client);
  logger.fine("Received INVALIDATE_ALL for %s: %s", getClientKey(client), listener);
  if (listener != null) {
    listener.invalidateAll(client, ackHandle);
  }
}
 
Example #9
Source File: InvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void acknowledge(final AckHandle ackHandle) {
  getResources().getInternalScheduler().schedule(NO_DELAY, new Runnable() {
    @Override
    public void run() {
      InvalidationClientImpl.super.acknowledge(ackHandle);
    }
  });
}
 
Example #10
Source File: AndroidClientProxy.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(
    InvalidationClient client, ObjectId objectId, AckHandle ackHandle) {
  Event event = Event.newBuilder(Event.Action.INVALIDATE_UNKNOWN)
      .setClientKey(clientKey).setObjectId(objectId).setAckHandle(ackHandle).build();
  sendEvent(event);
}
 
Example #11
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(final InvalidationClient client, final ObjectId objectId,
    final AckHandle ackHandle) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  Preconditions.checkNotNull(ackHandle);
  listenerScheduler.schedule(NO_DELAY,
      new NamedRunnable("CheckingInvalListener.invalidateUnknownVersion") {
    @Override
    public void run() {
      statistics.recordListenerEvent(ListenerEventType.INVALIDATE_UNKNOWN);
      delegate.invalidateUnknownVersion(client, objectId, ackHandle);
    }
  });
}
 
Example #12
Source File: AndroidInvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void acknowledge(Request request, Response.Builder response) {
  String clientKey = request.getClientKey();
  AckHandle ackHandle = request.getAckHandle();
  AndroidInvalidationClient client = clientManager.get(clientKey);
  if (setResponseStatus(client, request, response)) {
    client.acknowledge(ackHandle);
  }
}
 
Example #13
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 #14
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 #15
Source File: AndroidInvalidationClientImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(InvalidationClient client, ObjectId objectId,
    AckHandle ackHandle) {
  try {
    AckHandleP ackHandleP = AckHandleP.parseFrom(ackHandle.getHandleData());
    issueIntent(context, ListenerUpcalls.newInvalidateUnknownIntent(
        ProtoWrapperConverter.convertToObjectIdProto(objectId), ackHandleP));
  } catch (ValidationException exception) {
    // Log and drop invalid call.
    logBadAckHandle("invalidateUnknownVersion", ackHandle);
  }
}
 
Example #16
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateAll(final InvalidationClient client, final AckHandle ackHandle) {
  Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
  Preconditions.checkNotNull(ackHandle);
  listenerScheduler.schedule(NO_DELAY, new NamedRunnable("CheckingInvalListener.invalidateAll") {
    @Override
    public void run() {
      statistics.recordListenerEvent(ListenerEventType.INVALIDATE_ALL);
      delegate.invalidateAll(client, ackHandle);
    }
  });
}
 
Example #17
Source File: InvalidationTestListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(
    InvalidationClient client, ObjectId objectId, AckHandle ackHandle) {
  InvalidationListener listener = getListener(client);
  logger.fine("Received INVALIDATE_UNKNOWN_VERSION for %s: %s", getClientKey(client), listener);
  if (listener != null) {
    listener.invalidateUnknownVersion(client, objectId, ackHandle);
  }
}
 
Example #18
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 #19
Source File: AndroidInvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateAll(InvalidationClient client, AckHandle ackHandle) {
  try {
    AckHandleP ackHandleP = AckHandleP.parseFrom(ackHandle.getHandleData());
    issueIntent(context, ListenerUpcalls.newInvalidateAllIntent(ackHandleP));
  } catch (InvalidProtocolBufferException exception) {
    // Log and drop invalid call.
    logBadAckHandle("invalidateAll", ackHandle);
  }
}
 
Example #20
Source File: AndroidInvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(InvalidationClient client, ObjectId objectId,
    AckHandle ackHandle) {
  try {
    AckHandleP ackHandleP = AckHandleP.parseFrom(ackHandle.getHandleData());
    issueIntent(context, ListenerUpcalls.newInvalidateUnknownIntent(
        ProtoConverter.convertToObjectIdProto(objectId), ackHandleP));
  } catch (InvalidProtocolBufferException exception) {
    // Log and drop invalid call.
    logBadAckHandle("invalidateUnknownVersion", ackHandle);
  }
}
 
Example #21
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 #22
Source File: InvalidationTestListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateAll(InvalidationClient client, AckHandle ackHandle) {
  InvalidationListener listener = getListener(client);
  logger.fine("Received INVALIDATE_ALL for %s: %s", getClientKey(client), listener);
  if (listener != null) {
    listener.invalidateAll(client, ackHandle);
  }
}
 
Example #23
Source File: InvalidationTestListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(
    InvalidationClient client, ObjectId objectId, AckHandle ackHandle) {
  InvalidationListener listener = getListener(client);
  logger.fine("Received INVALIDATE_UNKNOWN_VERSION for %s: %s", getClientKey(client), listener);
  if (listener != null) {
    listener.invalidateUnknownVersion(client, objectId, ackHandle);
  }
}
 
Example #24
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 #25
Source File: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Tries to handle an ack intent. Returns {@code true} iff the intent is an ack intent. */
private boolean tryHandleAckIntent(Intent intent) {
  byte[] data = AndroidListenerIntents.findAckHandle(intent);
  if (data == null) {
    return false;
  }
  getClient().acknowledge(AckHandle.newInstance(data));
  return true;
}
 
Example #26
Source File: AndroidInvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void acknowledge(AckHandle ackHandle) {
  Request request = Request
      .newBuilder(Action.ACKNOWLEDGE)
      .setClientKey(clientKey)
      .setAckHandle(ackHandle)
      .build();
  executeServiceRequest(request);
}
 
Example #27
Source File: InvalidationClientImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void acknowledge(final AckHandle ackHandle) {
  getResources().getInternalScheduler().schedule(NO_DELAY, new Runnable() {
    @Override
    public void run() {
      InvalidationClientImpl.super.acknowledge(ackHandle);
    }
  });
}
 
Example #28
Source File: AndroidClientProxy.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void invalidateUnknownVersion(
    InvalidationClient client, ObjectId objectId, AckHandle ackHandle) {
  Event event = Event.newBuilder(Event.Action.INVALIDATE_UNKNOWN)
      .setClientKey(clientKey).setObjectId(objectId).setAckHandle(ackHandle).build();
  sendEvent(event);
}
 
Example #29
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 #30
Source File: AndroidInvalidationService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void acknowledge(Request request, Response.Builder response) {
  String clientKey = request.getClientKey();
  AckHandle ackHandle = request.getAckHandle();
  AndroidInvalidationClient client = clientManager.get(clientKey);
  if (setResponseStatus(client, request, response)) {
    client.acknowledge(ackHandle);
  }
}