Java Code Examples for com.google.ipc.invalidation.util.TypedUtil#mapGet()
The following examples show how to use
com.google.ipc.invalidation.util.TypedUtil#mapGet() .
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: InvalidationTestService.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected void create(Request request, Response.Builder response) { synchronized (LOCK) { validateRequest(request, Action.CREATE, Parameter.ACTION, Parameter.CLIENT, Parameter.CLIENT_TYPE, Parameter.ACCOUNT, Parameter.AUTH_TYPE, Parameter.INTENT); logger.info("Creating client %s:%s", request.getClientKey(), clientMap.keySet()); if (!TypedUtil.containsKey(clientMap, request.getClientKey())) { // If no client exists with this key, create one. clientMap.put( request.getClientKey(), new ClientState(request.getAccount(), request.getAuthType(), request.getIntent())); } else { // Otherwise, verify that the existing client has the same account / auth type / intent. ClientState existingState = TypedUtil.mapGet(clientMap, request.getClientKey()); Preconditions.checkState(request.getAccount().equals(existingState.account)); Preconditions.checkState(request.getAuthType().equals(existingState.authType)); } response.setStatus(Response.Status.SUCCESS); } }
Example 2
Source File: AndroidInvalidationService.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns the persisted state for the client with key {@code clientKey} in * {@code storageForClient}, or {@code null} if no valid state could be found. * <p> * REQUIRES: {@code storageForClient}.load() has been called successfully. */ PersistentTiclState decodeTiclState(final String clientKey, AndroidStorage storageForClient) { synchronized (lock) { // Retrieve the serialized state. final Map<String, byte[]> properties = storageForClient.getPropertiesUnsafe(); byte[] clientStateBytes = TypedUtil.mapGet(properties, InvalidationClientCore.CLIENT_TOKEN_KEY); if (clientStateBytes == null) { logger.warning("No client state found in storage for %s: %s", clientKey, properties.keySet()); return null; } // Deserialize it. PersistentTiclState clientState = PersistenceUtils.deserializeState(logger, clientStateBytes, digestFn); if (clientState == null) { logger.warning("Invalid client state found in storage for %s", clientKey); return null; } return clientState; } }
Example 3
Source File: AndroidInternalScheduler.java From 365browser with Apache License 2.0 | 6 votes |
/** Runs all tasks that are ready to run. */ void handleImplicitSchedulerEvent() { try { while (!scheduledTasks.isEmpty() && (scheduledTasks.firstKey() <= clock.nowMs())) { Map.Entry<Long, String> scheduledTask = scheduledTasks.pollFirstEntry(); Runnable runnable = TypedUtil.mapGet(registeredTasks, scheduledTask.getValue()); if (runnable == null) { logger.severe("No task registered for %s", scheduledTask.getValue()); continue; } runnable.run(); } } finally { if (!scheduledTasks.isEmpty()) { ensureIntentScheduledForSoonestTask(); } } }
Example 4
Source File: AndroidInvalidationService.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns the persisted state for the client with key {@code clientKey} in * {@code storageForClient}, or {@code null} if no valid state could be found. * <p> * REQUIRES: {@code storageForClient}.load() has been called successfully. */ PersistentTiclState decodeTiclState(final String clientKey, AndroidStorage storageForClient) { synchronized (lock) { // Retrieve the serialized state. final Map<String, byte[]> properties = storageForClient.getPropertiesUnsafe(); byte[] clientStateBytes = TypedUtil.mapGet(properties, InvalidationClientCore.CLIENT_TOKEN_KEY); if (clientStateBytes == null) { logger.warning("No client state found in storage for %s: %s", clientKey, properties.keySet()); return null; } // Deserialize it. PersistentTiclState clientState = PersistenceUtils.deserializeState(logger, clientStateBytes, digestFn); if (clientState == null) { logger.warning("Invalid client state found in storage for %s", clientKey); return null; } return clientState; } }
Example 5
Source File: InvalidationTestService.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected void create(Request request, Response.Builder response) { synchronized (LOCK) { validateRequest(request, Action.CREATE, Parameter.ACTION, Parameter.CLIENT, Parameter.CLIENT_TYPE, Parameter.ACCOUNT, Parameter.AUTH_TYPE, Parameter.INTENT); logger.info("Creating client %s:%s", request.getClientKey(), clientMap.keySet()); if (!TypedUtil.containsKey(clientMap, request.getClientKey())) { // If no client exists with this key, create one. clientMap.put( request.getClientKey(), new ClientState(request.getAccount(), request.getAuthType(), request.getIntent())); } else { // Otherwise, verify that the existing client has the same account / auth type / intent. ClientState existingState = TypedUtil.mapGet(clientMap, request.getClientKey()); Preconditions.checkState(request.getAccount().equals(existingState.account)); Preconditions.checkState(request.getAuthType().equals(existingState.authType)); } response.setStatus(Response.Status.SUCCESS); } }
Example 6
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 7
Source File: Statistics.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: AndroidInternalScheduler.java From 365browser with Apache License 2.0 | 5 votes |
/** * Handles an event intent created in {@link #schedule} by running that event, along with any * other events whose time has come. */ void handleSchedulerEvent(AndroidSchedulerEvent event) { Runnable recurringTaskRunnable = TypedUtil.mapGet(registeredTasks, event.getEventName()); if (recurringTaskRunnable == null) { throw new NullPointerException("No task registered for " + event.getEventName()); } if (ticlId != event.getTiclId()) { logger.warning("Ignoring event with wrong ticl id (not %s): %s", ticlId, event); return; } recurringTaskRunnable.run(); handleImplicitSchedulerEvent(); }
Example 9
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the counter value for {@code receivedMessageType}. */ int getReceivedMessageCounterForTest(ReceivedMessageType receivedMessageType) { return TypedUtil.mapGet(receivedMessageTypes, receivedMessageType); }
Example 11
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the counter value for {@code receivedMessageType}. */ int getReceivedMessageCounterForTest(ReceivedMessageType receivedMessageType) { return TypedUtil.mapGet(receivedMessageTypes, receivedMessageType); }
Example 12
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the counter value for {@code sentMessageType}. */ int getSentMessageCounterForTest(SentMessageType sentMessageType) { return TypedUtil.mapGet(sentMessageTypes, sentMessageType); }
Example 13
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the counter value for {@code clientErrorType}. */ int getClientErrorCounterForTest(ClientErrorType clientErrorType) { return TypedUtil.mapGet(clientErrorTypes, clientErrorType); }
Example 14
Source File: AckCache.java From 365browser with Apache License 2.0 | 4 votes |
/** * Returns the highest acked version for the object id with the given key, or * -1 if no versions have been acked. */ private long getHighestAckedVersion(ObjectIdP objectId) { Long version = TypedUtil.mapGet(highestAckedVersionMap, objectId); return (version != null) ? version : -1L; }
Example 15
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the counter value for {@code sentMessageType}. */ int getSentMessageCounterForTest(SentMessageType sentMessageType) { return TypedUtil.mapGet(sentMessageTypes, sentMessageType); }
Example 16
Source File: Statistics.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the counter value for {@code clientErrorType}. */ int getClientErrorCounterForTest(ClientErrorType clientErrorType) { return TypedUtil.mapGet(clientErrorTypes, clientErrorType); }
Example 17
Source File: Statistics.java From 365browser with Apache License 2.0 | 4 votes |
/** Returns the counter value for {@code receivedMessageType}. */ int getReceivedMessageCounterForTest(ReceivedMessageType receivedMessageType) { return TypedUtil.mapGet(receivedMessageTypes, receivedMessageType); }
Example 18
Source File: Statistics.java From 365browser with Apache License 2.0 | 4 votes |
/** Returns the counter value for {@code sentMessageType}. */ int getSentMessageCounterForTest(SentMessageType sentMessageType) { return TypedUtil.mapGet(sentMessageTypes, sentMessageType); }
Example 19
Source File: Statistics.java From 365browser with Apache License 2.0 | 4 votes |
/** Returns the counter value for {@code clientErrorType}. */ int getClientErrorCounterForTest(ClientErrorType clientErrorType) { return TypedUtil.mapGet(clientErrorTypes, clientErrorType); }