本文整理汇总了Java中com.google.ipc.invalidation.ticl.PersistenceUtils.serializeState方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceUtils.serializeState方法的具体用法?Java PersistenceUtils.serializeState怎么用?Java PersistenceUtils.serializeState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.ipc.invalidation.ticl.PersistenceUtils
的用法示例。
在下文中一共展示了PersistenceUtils.serializeState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGcmMessageForUnstartedClient
import com.google.ipc.invalidation.ticl.PersistenceUtils; //导入方法依赖的package包/类
/**
* Handles receipt of a GCM message for a client that was unknown or not started. If the client
* was unknown, drops the message. If the client was not started, rewrites the client's
* persistent state to have a last-message-sent-time of 0, ensuring that the client will
* send a heartbeat to the server when restarted. Since we drop the received GCM message,
* the client will be disconnected by the invalidation pusher; this heartbeat ensures a
* timely reconnection.
*/
private void handleGcmMessageForUnstartedClient(AndroidClientProxy proxy) {
if (proxy == null) {
// Unknown client; nothing to do.
return;
}
// Client is not started. Open its storage. We are going to use unsafe calls here that
// bypass the normal storage API. This is safe in this context because we hold a lock
// that prevents anyone else from starting this client or accessing its storage. We
// really should not be holding a lock across I/O, but at least this is only local
// file I/O, and we're only writing a few bytes. Additionally, since we currently only
// have one Ticl, we should only ever enter this function if we're not being used for
// anything else.
final String clientKey = proxy.getClientKey();
logger.info("Received message for unloaded client; rewriting state file: %s", clientKey);
// This storage must have been loaded, because we got this proxy from the client manager,
// which always ensures that its entries have that property.
AndroidStorage storageForClient = proxy.getStorage();
PersistentTiclState clientState = decodeTiclState(clientKey, storageForClient);
if (clientState == null) {
// Logging done in decodeTiclState.
return;
}
// Rewrite the last message sent time.
PersistentTiclState newState = PersistentTiclState.newBuilder(clientState)
.setLastMessageSendTimeMs(0).build();
// Serialize the new state.
byte[] newClientState = PersistenceUtils.serializeState(newState, digestFn);
// Write it out.
storageForClient.getPropertiesUnsafe().put(InvalidationClientCore.CLIENT_TOKEN_KEY,
newClientState);
storageForClient.storeUnsafe();
}