Java Code Examples for com.google.ipc.invalidation.external.client.SystemResources.Logger#warning()

The following examples show how to use com.google.ipc.invalidation.external.client.SystemResources.Logger#warning() . 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: PersistenceUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (ValidationException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  Bytes mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<Bytes>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example 2
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (InvalidProtocolBufferException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  ByteString mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<ByteString>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example 3
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (InvalidProtocolBufferException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  ByteString mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<ByteString>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example 4
Source File: Statistics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Given the serialized {@code performanceCounters} of the client statistics, returns a Statistics
 * object with the performance counter values from {@code performanceCounters}.
 */

public static Statistics deserializeStatistics(Logger logger,
    Collection<PropertyRecord> performanceCounters) {
  Statistics statistics = new Statistics();

  // For each counter, parse out the counter name and value.
  for (PropertyRecord performanceCounter : performanceCounters) {
    String counterName = performanceCounter.getName();
    String[] parts = counterName.split("\\.");
    if (parts.length != 2) {
      logger.warning("Perf counter name must of form: class.value, skipping: %s", counterName);
      continue;
    }
    String className = parts[0];
    String fieldName = parts[1];
    int counterValue = performanceCounter.getValue();

    // Call the relevant method in a loop (i.e., depending on the type of the class).
    if (TypedUtil.<String>equals(className, SENT_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, SENT_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.sentMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, INCOMING_OPERATION_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, INCOMING_OPERATION_TYPE_NAME_TO_VALUE_MAP,
          statistics.incomingOperationTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, RECEIVED_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, RECEIVED_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.receivedMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  LISTENER_EVENT_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, LISTENER_EVENT_TYPE_NAME_TO_VALUE_MAP,
          statistics.listenerEventTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  CLIENT_ERROR_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, CLIENT_ERROR_TYPE_NAME_TO_VALUE_MAP,
          statistics.clientErrorTypes, fieldName, counterValue);
    } else {
      logger.warning("Skipping unknown enum class name %s", className);
    }
  }
  return statistics;
}
 
Example 5
Source File: Statistics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Looks for an enum value with the given {@code fieldName} in {@code valueOfMap} and increments
 * the corresponding entry in {@code counts} by {@code counterValue}. Call to update statistics
 * for a single performance counter.
 */
private static <Key extends Enum<Key>> void incrementPerformanceCounterValue(Logger logger,
    Map<String, Key> valueOfMap, Map<Key, Integer> counts, String fieldName, int counterValue) {
  Key type = TypedUtil.mapGet(valueOfMap, fieldName);
  if (type != null) {
    int currentValue = TypedUtil.mapGet(counts, type);
    counts.put(type, currentValue + counterValue);
  } else {
    logger.warning("Skipping unknown enum value name %s", fieldName);
  }
}
 
Example 6
Source File: AndroidMessageSenderService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Returns the network id for this channel, or {@code null} if one cannot be determined. */


public static NetworkEndpointId getNetworkEndpointId(Context context, Logger logger) {
  String registrationId;
  String clientKey;

  // Select the registration token to use.
  if (AndroidChannelPreferences.getGcmChannelType(context) == GcmChannelType.UPDATED) {
    registrationId = AndroidChannelPreferences.getRegistrationToken(context);
    clientKey = GcmSharedConstants.ANDROID_ENDPOINT_ID_CLIENT_KEY;
  } else {
    // No client key when using old style registration id.
    clientKey = "";
    try {
      registrationId = GCMRegistrar.getRegistrationId(context);
    } catch (RuntimeException exception) {
      // GCMRegistrar#getRegistrationId occasionally throws a runtime exception. Catching the
      // exception rather than crashing.
      logger.warning("Unable to get GCM registration id: %s", exception);
      registrationId = null;
    }
  }
  if ((registrationId == null) || registrationId.isEmpty()) {
    // No registration with GCM; we cannot compute a network id. The GCM documentation says the
    // string is never null, but we'll be paranoid.
    logger.warning(
        "No GCM registration id; cannot determine our network endpoint id: %s", registrationId);
    return null;
  }
  return CommonProtos.newAndroidEndpointId(registrationId, clientKey,
      context.getPackageName(), AndroidChannelConstants.CHANNEL_VERSION);
}
 
Example 7
Source File: TiclStateManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  byte[] computedDigest = digester.getDigest();
  if (!TypedUtil.<Bytes>equals(new Bytes(computedDigest), state.getDigest())) {
    logger.warning("Android TICL state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example 8
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Given the serialized {@code performanceCounters} of the client statistics, returns a Statistics
 * object with the performance counter values from {@code performanceCounters}.
 */

public static Statistics deserializeStatistics(Logger logger,
    Collection<PropertyRecord> performanceCounters) {
  Statistics statistics = new Statistics();

  // For each counter, parse out the counter name and value.
  for (PropertyRecord performanceCounter : performanceCounters) {
    String counterName = performanceCounter.getName();
    String[] parts = counterName.split("\\.");
    if (parts.length != 2) {
      logger.warning("Perf counter name must of form: class.value, skipping: %s", counterName);
      continue;
    }
    String className = parts[0];
    String fieldName = parts[1];
    int counterValue = performanceCounter.getValue();

    // Call the relevant method in a loop (i.e., depending on the type of the class).
    if (TypedUtil.<String>equals(className, SENT_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, SENT_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.sentMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, INCOMING_OPERATION_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, INCOMING_OPERATION_TYPE_NAME_TO_VALUE_MAP,
          statistics.incomingOperationTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, RECEIVED_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, RECEIVED_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.receivedMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  LISTENER_EVENT_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, LISTENER_EVENT_TYPE_NAME_TO_VALUE_MAP,
          statistics.listenerEventTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  CLIENT_ERROR_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, CLIENT_ERROR_TYPE_NAME_TO_VALUE_MAP,
          statistics.clientErrorTypes, fieldName, counterValue);
    } else {
      logger.warning("Skipping unknown enum class name %s", className);
    }
  }
  return statistics;
}
 
Example 9
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Looks for an enum value with the given {@code fieldName} in {@code valueOfMap} and increments
 * the corresponding entry in {@code counts} by {@code counterValue}. Call to update statistics
 * for a single performance counter.
 */
private static <Key extends Enum<Key>> void incrementPerformanceCounterValue(Logger logger,
    Map<String, Key> valueOfMap, Map<Key, Integer> counts, String fieldName, int counterValue) {
  Key type = TypedUtil.mapGet(valueOfMap, fieldName);
  if (type != null) {
    int currentValue = TypedUtil.mapGet(counts, type);
    counts.put(type, currentValue + counterValue);
  } else {
    logger.warning("Skipping unknown enum value name %s", fieldName);
  }
}
 
Example 10
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns the network id for this channel, or {@code null} if one cannot be determined. */


public static NetworkEndpointId getNetworkEndpointId(Context context, Logger logger) {
  String registrationId = GCMRegistrar.getRegistrationId(context);
  if (Strings.isNullOrEmpty(registrationId)) {
    // No registration with GCM; we cannot compute a network id. The GCM documentation says the
    // string is never null, but we'll be paranoid.
    logger.warning("No GCM registration id; cannot determine our network endpoint id: %s",
        registrationId);
    return null;
  }
  return CommonProtos2.newAndroidEndpointId(registrationId,
      NO_CLIENT_KEY, context.getPackageName(), AndroidChannelConstants.CHANNEL_VERSION);
}
 
Example 11
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
  if (!computedDigest.equals(state.getDigest())) {
    logger.warning("Android Ticl state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example 12
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Given the serialized {@code performanceCounters} of the client statistics, returns a Statistics
 * object with the performance counter values from {@code performanceCounters}.
 */

public static Statistics deserializeStatistics(Logger logger,
    Collection<PropertyRecord> performanceCounters) {
  Statistics statistics = new Statistics();

  // For each counter, parse out the counter name and value.
  for (PropertyRecord performanceCounter : performanceCounters) {
    String counterName = performanceCounter.getName();
    String[] parts = counterName.split("\\.");
    if (parts.length != 2) {
      logger.warning("Perf counter name must of form: class.value, skipping: %s", counterName);
      continue;
    }
    String className = parts[0];
    String fieldName = parts[1];
    int counterValue = performanceCounter.getValue();

    // Call the relevant method in a loop (i.e., depending on the type of the class).
    if (TypedUtil.<String>equals(className, SENT_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, SENT_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.sentMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, INCOMING_OPERATION_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, INCOMING_OPERATION_TYPE_NAME_TO_VALUE_MAP,
          statistics.incomingOperationTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className, RECEIVED_MESSAGE_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, RECEIVED_MESSAGE_TYPE_NAME_TO_VALUE_MAP,
          statistics.receivedMessageTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  LISTENER_EVENT_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, LISTENER_EVENT_TYPE_NAME_TO_VALUE_MAP,
          statistics.listenerEventTypes, fieldName, counterValue);
    } else if (TypedUtil.<String>equals(className,  CLIENT_ERROR_TYPE_NAME)) {
      incrementPerformanceCounterValue(logger, CLIENT_ERROR_TYPE_NAME_TO_VALUE_MAP,
          statistics.clientErrorTypes, fieldName, counterValue);
    } else {
      logger.warning("Skipping unknown enum class name %s", className);
    }
  }
  return statistics;
}
 
Example 13
Source File: Statistics.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Looks for an enum value with the given {@code fieldName} in {@code valueOfMap} and increments
 * the corresponding entry in {@code counts} by {@code counterValue}. Call to update statistics
 * for a single performance counter.
 */
private static <Key extends Enum<Key>> void incrementPerformanceCounterValue(Logger logger,
    Map<String, Key> valueOfMap, Map<Key, Integer> counts, String fieldName, int counterValue) {
  Key type = TypedUtil.mapGet(valueOfMap, fieldName);
  if (type != null) {
    int currentValue = TypedUtil.mapGet(counts, type);
    counts.put(type, currentValue + counterValue);
  } else {
    logger.warning("Skipping unknown enum value name %s", fieldName);
  }
}
 
Example 14
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns the network id for this channel, or {@code null} if one cannot be determined. */


public static NetworkEndpointId getNetworkEndpointId(Context context, Logger logger) {
  String registrationId = GCMRegistrar.getRegistrationId(context);
  if (Strings.isNullOrEmpty(registrationId)) {
    // No registration with GCM; we cannot compute a network id. The GCM documentation says the
    // string is never null, but we'll be paranoid.
    logger.warning("No GCM registration id; cannot determine our network endpoint id: %s",
        registrationId);
    return null;
  }
  return CommonProtos2.newAndroidEndpointId(registrationId,
      NO_CLIENT_KEY, context.getPackageName(), AndroidChannelConstants.CHANNEL_VERSION);
}
 
Example 15
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
  if (!computedDigest.equals(state.getDigest())) {
    logger.warning("Android Ticl state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}