本文整理汇总了Java中com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ClientToServerMessage.Builder方法的具体用法?Java ClientToServerMessage.Builder怎么用?Java ClientToServerMessage.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage
的用法示例。
在下文中一共展示了ClientToServerMessage.Builder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessageToServer
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入方法依赖的package包/类
/** Sends pending data to the server (e.g., registrations, acks, registration sync messages). */
void sendMessageToServer() {
Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
if (nextMessageSendTimeMs > internalScheduler.getCurrentTimeMs()) {
logger.warning("In quiet period: not sending message to server: %s > %s",
nextMessageSendTimeMs, internalScheduler.getCurrentTimeMs());
return;
}
// Create the message from the batcher.
ClientToServerMessage.Builder msgBuilder =
batcher.toBuilder(listener.getClientToken() != null);
if (msgBuilder == null) {
// Happens when we don't have a token and are not sending an initialize message. Logged
// in batcher.toBuilder().
return;
}
msgBuilder.setHeader(createClientHeader());
++messageId;
// Validate the message and send it.
ClientToServerMessage message = msgBuilder.build();
if (!msgValidator.isValid(message)) {
logger.severe("Tried to send invalid message: %s", message);
statistics.recordError(ClientErrorType.OUTGOING_MESSAGE_FAILURE);
return;
}
statistics.recordSentMessage(SentMessageType.TOTAL);
logger.fine("Sending message to server: {0}",
CommonProtoStrings2.toLazyCompactString(message, true));
network.sendMessage(message.toByteArray());
// Record that the message was sent. We're invoking the listener directly, rather than
// scheduling a new work unit to do it. It would be safer to do a schedule, but that's hard to
// do in Android, we wrote this listener (it's InvalidationClientCore, so we know what it does),
// and it's the last line of this function.
listener.handleMessageSent();
}
示例2: 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;
}