本文整理汇总了Java中com.google.ipc.invalidation.util.TypedUtil.equals方法的典型用法代码示例。如果您正苦于以下问题:Java TypedUtil.equals方法的具体用法?Java TypedUtil.equals怎么用?Java TypedUtil.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.ipc.invalidation.util.TypedUtil
的用法示例。
在下文中一共展示了TypedUtil.equals方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeState
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* 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;
}
示例2: equals
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Overridden for tests which compare listener states to verify that they have been correctly
* (un)marshalled. We implement equals rather than exposing private data.
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof AndroidListenerState)) {
return false;
}
AndroidListenerState that = (AndroidListenerState) object;
return (this.isDirty == that.isDirty)
&& (this.requestCodeSeqNum == that.requestCodeSeqNum)
&& (this.desiredRegistrations.size() == that.desiredRegistrations.size())
&& (this.desiredRegistrations.containsAll(that.desiredRegistrations))
&& TypedUtil.<Bytes>equals(this.clientId, that.clientId)
&& equals(this.delayGenerators, that.delayGenerators)
&& equals(this.registrationRetries, that.registrationRetries);
}
示例3: deserializeState
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* 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;
}
示例4: deserializeStatistics
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* 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;
}
示例5: isDigestValid
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/** 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;
}
示例6: handleTokenChanged
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Handles a token-control message.
* @param headerToken token in the server message
* @param newToken the new token provided, or {@code null} if this is a destroy message.
*/
private void handleTokenChanged(Bytes headerToken, final Bytes newToken) {
Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
// The server is either supplying a new token in response to an InitializeMessage, spontaneously
// destroying a token we hold, or spontaneously upgrading a token we hold.
if (newToken != null) {
// Note: headerToken cannot be null, so a null nonce or clientToken will always be non-equal.
boolean headerTokenMatchesNonce = TypedUtil.<Bytes>equals(headerToken, nonce);
boolean headerTokenMatchesExistingToken = TypedUtil.<Bytes>equals(headerToken, clientToken);
boolean shouldAcceptToken = headerTokenMatchesNonce || headerTokenMatchesExistingToken;
if (!shouldAcceptToken) {
logger.info("Ignoring new token; %s does not match nonce = %s or existing token = %s",
newToken, nonce, clientToken);
return;
}
logger.info("New token being assigned at client: %s, Old = %s", newToken, clientToken);
// Start the regular heartbeats now.
heartbeatTask.ensureScheduled("Heartbeat-after-new-token");
setNonce(null);
setClientToken(newToken);
persistentWriteTask.ensureScheduled("Write-after-new-token");
} else {
logger.info("Destroying existing token: %s", clientToken);
acquireToken("Destroy");
}
}
示例7: validateToken
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Returns whether the token in the header of {@code parsedMessage} matches either the
* client token or nonce of this Ticl (depending on which is non-{@code null}).
*/
private boolean validateToken(ParsedMessage parsedMessage) {
if (clientToken != null) {
// Client token case.
if (!TypedUtil.<Bytes>equals(clientToken, parsedMessage.header.token)) {
logger.info("Incoming message has bad token: server = %s, client = %s",
parsedMessage.header.token, clientToken);
statistics.recordError(ClientErrorType.TOKEN_MISMATCH);
return false;
}
return true;
} else if (nonce != null) {
// Nonce case.
if (!TypedUtil.<Bytes>equals(nonce, parsedMessage.header.token)) {
statistics.recordError(ClientErrorType.NONCE_MISMATCH);
logger.info("Rejecting server message with mismatched nonce: Client = %s, Server = %s",
nonce, parsedMessage.header.token);
return false;
} else {
logger.info("Accepting server message with matching nonce: %s", nonce);
return true;
}
}
// Neither token nor nonce; ignore message.
logger.warning("Neither token nor nonce was set in validateToken: %s, %s", clientToken, nonce);
return false;
}
示例8: handleTokenChanged
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Handles a token-control message.
* @param headerToken token in the server message
* @param newToken the new token provided, or {@code null} if this is a destroy message.
*/
private void handleTokenChanged(ByteString headerToken, final ByteString newToken) {
Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
// The server is either supplying a new token in response to an InitializeMessage, spontaneously
// destroying a token we hold, or spontaneously upgrading a token we hold.
if (newToken != null) {
// Note: headerToken cannot be null, so a null nonce or clientToken will always be non-equal.
boolean headerTokenMatchesNonce = TypedUtil.<ByteString>equals(headerToken, nonce);
boolean headerTokenMatchesExistingToken =
TypedUtil.<ByteString>equals(headerToken, clientToken);
boolean shouldAcceptToken = headerTokenMatchesNonce || headerTokenMatchesExistingToken;
if (!shouldAcceptToken) {
logger.info("Ignoring new token; %s does not match nonce = %s or existing token = %s",
newToken, nonce, clientToken);
return;
}
logger.info("New token being assigned at client: %s, Old = %s",
CommonProtoStrings2.toLazyCompactString(newToken),
CommonProtoStrings2.toLazyCompactString(clientToken));
// Start the regular heartbeats now.
heartbeatTask.ensureScheduled("Heartbeat-after-new-token");
setNonce(null);
setClientToken(newToken);
persistentWriteTask.ensureScheduled("Write-after-new-token");
} else {
logger.info("Destroying existing token: %s",
CommonProtoStrings2.toLazyCompactString(clientToken));
acquireToken("Destroy");
}
}
示例9: validateToken
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Returns whether the token in the header of {@code parsedMessage} matches either the
* client token or nonce of this Ticl (depending on which is non-{@code null}).
*/
private boolean validateToken(ParsedMessage parsedMessage) {
if (clientToken != null) {
// Client token case.
if (!TypedUtil.<ByteString>equals(clientToken, parsedMessage.header.token)) {
logger.info("Incoming message has bad token: server = %s, client = %s",
CommonProtoStrings2.toLazyCompactString(parsedMessage.header.token),
CommonProtoStrings2.toLazyCompactString(clientToken));
statistics.recordError(ClientErrorType.TOKEN_MISMATCH);
return false;
}
return true;
} else if (nonce != null) {
// Nonce case.
if (!TypedUtil.<ByteString>equals(nonce, parsedMessage.header.token)) {
statistics.recordError(ClientErrorType.NONCE_MISMATCH);
logger.info("Rejecting server message with mismatched nonce: Client = %s, Server = %s",
CommonProtoStrings2.toLazyCompactString(nonce),
CommonProtoStrings2.toLazyCompactString(parsedMessage.header.token));
return false;
} else {
logger.info("Accepting server message with matching nonce: %s",
CommonProtoStrings2.toLazyCompactString(nonce));
return true;
}
}
// Neither token nor nonce; ignore message.
logger.warning("Neither token nor nonce was set in validateToken: %s, %s", clientToken, nonce);
return false;
}
示例10: runTask
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
@Override
public boolean runTask() {
if (clientToken == null) {
// We cannot write without a token. We must do this check before creating the
// PersistentTiclState because newPersistentTiclState cannot handle null tokens.
return false;
}
// Compute the state that we will write if we decide to go ahead with the write.
final PersistentTiclState state =
PersistentTiclState.create(clientToken, lastMessageSendTimeMs);
byte[] serializedState = PersistenceUtils.serializeState(state, digestFn);
// Decide whether or not to do the write. The decision varies depending on whether or
// not the channel supports offline delivery. If we decide not to do the write, then
// that means the in-memory and stored state match semantically, and the train stops.
if (config.getChannelSupportsOfflineDelivery()) {
// For offline delivery, we want the entire state to match, since we write the last
// send time for every message.
if (state.equals(lastWrittenState.get())) {
return false;
}
} else {
// If we do not support offline delivery, we avoid writing the state on each message, and
// we avoid checking the last-sent time (we check only the client token).
if (TypedUtil.<Bytes>equals(
state.getClientToken(), lastWrittenState.get().getClientToken())) {
return false;
}
}
// We decided to do the write.
storage.writeKey(CLIENT_TOKEN_KEY, serializedState, new Callback<Status>() {
@Override
public void accept(Status status) {
logger.info("Write state completed: %s for %s", status, state);
Preconditions.checkState(resources.getInternalScheduler().isRunningOnThread());
if (status.isSuccess()) {
// Set lastWrittenToken to be the token that was written (NOT clientToken - which
// could have changed while the write was happening).
lastWrittenState.set(state);
} else {
statistics.recordError(ClientErrorType.PERSISTENT_WRITE_FAILURE);
}
}
});
return true; // Reschedule after timeout to make sure that write does happen.
}
示例11: isStateInSyncWithServer
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Returns whether the local registration state and server state agree, based on the last
* received server summary (from {@link #informServerRegistrationSummary}).
*/
boolean isStateInSyncWithServer() {
return TypedUtil.<RegistrationSummary>equals(lastKnownServerSummary, getRegistrationSummary());
}
示例12: isStateInSyncWithServer
import com.google.ipc.invalidation.util.TypedUtil; //导入方法依赖的package包/类
/**
* Returns whether the local registration state and server state agree, based on the last
* received server summary (from {@link #informServerRegistrationSummary}).
*/
boolean isStateInSyncWithServer() {
return TypedUtil.equals(lastKnownServerSummary, ProtoWrapper.of(getRegistrationSummary()));
}