• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PersistenceUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.ipc.invalidation.ticl.PersistenceUtils的典型用法代码示例。如果您正苦于以下问题:Java PersistenceUtils类的具体用法?Java PersistenceUtils怎么用?Java PersistenceUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PersistenceUtils类属于com.google.ipc.invalidation.ticl包,在下文中一共展示了PersistenceUtils类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decodeTiclState

import com.google.ipc.invalidation.ticl.PersistenceUtils; //导入依赖的package包/类
/**
 * 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;
  }
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:31,代码来源:AndroidInvalidationService.java


示例2: 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


示例3: handleServerMessage

import com.google.ipc.invalidation.ticl.PersistenceUtils; //导入依赖的package包/类
/**
 * Handles a {@code message} for a {@code ticl}. If the {@code ticl} is started, delivers the
 * message. If the {@code ticl} is not started, drops the message and clears the last message send
 * time in the Ticl persistent storage so that the Ticl will send a heartbeat the next time it
 * starts.
 */
private void handleServerMessage(boolean isTiclStarted, byte[] message) {
  if (isTiclStarted) {
    // Normal case -- message for a started Ticl. Deliver the message.
    resources.getNetworkListener().onMessageReceived(message);
    return;
  }

  // Even if the client is stopped, attempt to send invalidations if the client is configured to
  // receive them.
  maybeSendBackgroundInvalidationIntent(message);

  // The Ticl isn't started. Rewrite persistent storage so that the last-send-time is a long
  // time ago. The next time the Ticl starts, it will send a message to the data center, which
  // ensures that it will be marked online and that the dropped message (or an equivalent) will
  // be delivered.
  // Android storage implementations are required to execute callbacks inline, so this code
  // all executes synchronously.
  resources.getLogger().fine("Message for unstarted Ticl; rewrite state");
  resources.getStorage().readKey(InvalidationClientCore.CLIENT_TOKEN_KEY,
      new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(SimplePair<Status, byte[]> result) {
      byte[] stateBytes = result.second;
      if (stateBytes == null) {
        resources.getLogger().info("No persistent state found for client; not rewriting");
        return;
      }
      // Create new state identical to the old state except with a cleared
      // lastMessageSendTimeMs.
      PersistentTiclState state = PersistenceUtils.deserializeState(
          resources.getLogger(), stateBytes, digestFn);
      if (state == null) {
        resources.getLogger().warning("Ignoring invalid Ticl state: %s",
            Bytes.toLazyCompactString(stateBytes));
        return;
      }
      PersistentTiclState.Builder stateBuilder = state.toBuilder();
      stateBuilder.lastMessageSendTimeMs = 0L;
      state = stateBuilder.build();

      // Serialize the new state and write it to storage.
      byte[] newClientState = PersistenceUtils.serializeState(state, digestFn);
      resources.getStorage().writeKey(InvalidationClientCore.CLIENT_TOKEN_KEY, newClientState,
          new Callback<Status>() {
            @Override
            public void accept(Status status) {
              if (status.getCode() != Status.Code.SUCCESS) {
                resources.getLogger().warning(
                    "Failed saving rewritten persistent state to storage");
              }
            }
      });
    }
  });
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:62,代码来源:TiclService.java


示例4: handleServerMessage

import com.google.ipc.invalidation.ticl.PersistenceUtils; //导入依赖的package包/类
/**
 * Handles a {@code message} for a {@code ticl}. If the {@code ticl} is started, delivers the
 * message. If the {@code ticl} is not started, drops the message and clears the last message send
 * time in the Ticl persistent storage so that the Ticl will send a heartbeat the next time it
 * starts.
 */
private void handleServerMessage(boolean isTiclStarted, byte[] message) {
  if (isTiclStarted) {
    // Normal case -- message for a started Ticl. Deliver the message.
    resources.getNetworkListener().onMessageReceived(message);
    return;
  }
  // The Ticl isn't started. Rewrite persistent storage so that the last-send-time is a long
  // time ago. The next time the Ticl starts, it will send a message to the data center, which
  // ensures that it will be marked online and that the dropped message (or an equivalent) will
  // be delivered.
  // Android storage implementations are required to execute callbacks inline, so this code
  // all executes synchronously.
  resources.getLogger().fine("Message for unstarted Ticl; rewrite state");
  resources.getStorage().readKey(InvalidationClientCore.CLIENT_TOKEN_KEY,
      new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(SimplePair<Status, byte[]> result) {
      byte[] stateBytes = result.second;
      if (stateBytes == null) {
        resources.getLogger().info("No persistent state found for client; not rewriting");
        return;
      }
      // Create new state identical to the old state except with a cleared
      // lastMessageSendTimeMs.
      PersistentTiclState state = PersistenceUtils.deserializeState(
          resources.getLogger(), stateBytes, digestFn);
      if (state == null) {
        resources.getLogger().warning("Ignoring invalid Ticl state: %s", stateBytes);
        return;
      }
      PersistentTiclState newState = PersistentTiclState.newBuilder(state)
          .setLastMessageSendTimeMs(0)
          .build();

      // Serialize the new state and write it to storage.
      byte[] newClientState = PersistenceUtils.serializeState(newState, digestFn);
      resources.getStorage().writeKey(InvalidationClientCore.CLIENT_TOKEN_KEY, newClientState,
          new Callback<Status>() {
            @Override
            public void accept(Status status) {
              if (status.getCode() != Status.Code.SUCCESS) {
                resources.getLogger().warning(
                    "Failed saving rewritten persistent state to storage");
              }
            }
      });
    }
  });
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:56,代码来源:TiclService.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ExtendedStringLiteral类代码示例发布时间:2022-05-22
下一篇:
Java SendEmailResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap