当前位置: 首页>>代码示例>>Java>>正文


Java PersistenceUtils.serializeState方法代码示例

本文整理汇总了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();
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:46,代码来源:AndroidInvalidationService.java


注:本文中的com.google.ipc.invalidation.ticl.PersistenceUtils.serializeState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。