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


Java ClientToServerMessage.newBuilder方法代码示例

本文整理汇总了Java中com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java ClientToServerMessage.newBuilder方法的具体用法?Java ClientToServerMessage.newBuilder怎么用?Java ClientToServerMessage.newBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage的用法示例。


在下文中一共展示了ClientToServerMessage.newBuilder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toBuilder

import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入方法依赖的package包/类
/**
 * Returns a builder for a {@link ClientToServerMessage} to be sent to the server. Crucially,
 * the builder does <b>NOT</b> include the message header.
 * @param hasClientToken whether the client currently holds a token
 */
ClientToServerMessage.Builder toBuilder(boolean hasClientToken) {
  ClientToServerMessage.Builder builder = ClientToServerMessage.newBuilder();
  if (pendingInitializeMessage != null) {
    statistics.recordSentMessage(SentMessageType.INITIALIZE);
    builder.setInitializeMessage(pendingInitializeMessage);
    pendingInitializeMessage = null;
  }

  // Note: Even if an initialize message is being sent, we can send additional
  // messages such as regisration messages, etc to the server. But if there is no token
  // and an initialize message is not being sent, we cannot send any other message.

  if (!hasClientToken && !builder.hasInitializeMessage()) {
    // Cannot send any message
    resources.getLogger().warning(
        "Cannot send message since no token and no initialize msg: %s", builder);
    statistics.recordError(ClientErrorType.TOKEN_MISSING_FAILURE);
    return null;
  }

  // Check for pending batched operations and add to message builder if needed.

  // Add reg, acks, reg subtrees - clear them after adding.
  if (!pendingAckedInvalidations.isEmpty()) {
    builder.setInvalidationAckMessage(createInvalidationAckMessage());
    statistics.recordSentMessage(SentMessageType.INVALIDATION_ACK);
  }

  // Check regs.
  if (!pendingRegistrations.isEmpty()) {
    builder.setRegistrationMessage(createRegistrationMessage());
    statistics.recordSentMessage(SentMessageType.REGISTRATION);
  }

  // Check reg substrees.
  if (!pendingRegSubtrees.isEmpty()) {
    for (ProtoWrapper<RegistrationSubtree> subtree : pendingRegSubtrees) {
      builder.setRegistrationSyncMessage(RegistrationSyncMessage.newBuilder()
          .addSubtree(subtree.getProto()));
    }
    pendingRegSubtrees.clear();
    statistics.recordSentMessage(SentMessageType.REGISTRATION_SYNC);
  }

  // Check if an info message has to be sent.
  if (pendingInfoMessage != null) {
    statistics.recordSentMessage(SentMessageType.INFO);
    builder.setInfoMessage(pendingInfoMessage);
    pendingInfoMessage = null;
  }
  return builder;
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:58,代码来源:ProtocolHandler.java


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