本文整理汇总了Java中com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage类的典型用法代码示例。如果您正苦于以下问题:Java ClientToServerMessage类的具体用法?Java ClientToServerMessage怎么用?Java ClientToServerMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientToServerMessage类属于com.google.protos.ipc.invalidation.ClientProtocol包,在下文中一共展示了ClientToServerMessage类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: hasField
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入依赖的package包/类
/** Returns whether {@code field} is present in {@code message}. */
@Override
@SuppressWarnings("unchecked")
public boolean hasField(MessageLite rawMessage, Descriptor field) {
Preconditions.checkNotNull(rawMessage);
Preconditions.checkNotNull(field);
ClientToServerMessage message = (ClientToServerMessage) rawMessage;
if (field == HEADER) {
return message.hasHeader();
}
if (field == INITIALIZE_MESSAGE) {
return message.hasInitializeMessage();
}
if (field == REGISTRATION_MESSAGE) {
return message.hasRegistrationMessage();
}
if (field == REGISTRATION_SYNC_MESSAGE) {
return message.hasRegistrationSyncMessage();
}
if (field == INVALIDATION_ACK_MESSAGE) {
return message.hasInvalidationAckMessage();
}
if (field == INFO_MESSAGE) {
return message.hasInfoMessage();
}
throw new IllegalArgumentException("Bad descriptor: " + field);
}
示例3: getField
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入依赖的package包/类
/** Returns the {@code field} from {@code message}. */
@Override
@SuppressWarnings("unchecked")
public Object getField(MessageLite rawMessage, Descriptor field) {
Preconditions.checkNotNull(rawMessage);
Preconditions.checkNotNull(field);
ClientToServerMessage message = (ClientToServerMessage) rawMessage;
if (field == HEADER) {
return message.getHeader();
}
if (field == INITIALIZE_MESSAGE) {
return message.getInitializeMessage();
}
if (field == REGISTRATION_MESSAGE) {
return message.getRegistrationMessage();
}
if (field == REGISTRATION_SYNC_MESSAGE) {
return message.getRegistrationSyncMessage();
}
if (field == INVALIDATION_ACK_MESSAGE) {
return message.getInvalidationAckMessage();
}
if (field == INFO_MESSAGE) {
return message.getInfoMessage();
}
throw new IllegalArgumentException("Bad descriptor: " + field);
}
示例4: toLazyCompactString
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入依赖的package包/类
/** See spec in implementation notes and toCompactString for ClientToServerMessage. */
public static Object toLazyCompactString(final ClientToServerMessage message,
final boolean printHighFrequencyMessages) {
return LazyString.toLazyCompactString(message, new Receiver<TextBuilder>() {
@Override
public void accept(TextBuilder builder) {
toCompactString(builder, message, printHighFrequencyMessages);
}
});
}
示例5: toCompactString
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入依赖的package包/类
/**
* If {@code printHighFrequencyMessages} is true, logs sub-messages that are exchanged at a high
* frequency between the client and the registrar, e.g., invalidation ack message, heartbeat
* message.
*/
public static TextBuilder toCompactString(TextBuilder builder,
ClientToServerMessage msg, boolean printHighFrequencyMessages) {
// Print the header and any sub-messages in the message.
toCompactString(builder, msg.getHeader());
builder.append(',');
if (msg.hasInitializeMessage()) {
toCompactString(builder, msg.getInitializeMessage());
builder.append(',');
}
if (msg.hasRegistrationMessage()) {
toCompactString(builder, msg.getRegistrationMessage());
builder.append(',');
}
if (msg.hasRegistrationSyncMessage()) {
toCompactString(builder, msg.getRegistrationSyncMessage());
builder.append(',');
}
if (printHighFrequencyMessages && msg.hasInvalidationAckMessage()) {
toCompactString(builder, msg.getInvalidationAckMessage());
builder.append(',');
}
if (printHighFrequencyMessages && msg.hasInfoMessage()) {
toCompactString(builder, msg.getInfoMessage());
builder.append(',');
}
return builder;
}
示例6: 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;
}
示例7: postValidate
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入依赖的package包/类
@Override
public boolean postValidate(MessageLite message) {
ClientToServerMessage parsedMessage = (ClientToServerMessage) message;
// The message either has an initialize request from the client or it has the client token.
return (parsedMessage.hasInitializeMessage() ^ parsedMessage.getHeader().hasClientToken());
}
示例8: isValid
import com.google.protos.ipc.invalidation.ClientProtocol.ClientToServerMessage; //导入依赖的package包/类
/** Returns whether {@code clientMessage} is valid. */
public boolean isValid(ClientToServerMessage clientMessage) {
return checkMessage(clientMessage, clientMsgInfos.CLIENT_MSG);
}