Java 类com.google.protobuf.AbstractMessage 实例源码

项目:grain    文件:WSCodeUtil.java   
public static WsPacket decodeJson(String stringResult) {
    try {

        JSONObject jsObj = JSONObject.fromObject(stringResult);
        String wsOpCode = jsObj.getString(WSOPCODE);
        if (wsOpCode == null) {
            if (WSManager.log != null) {
                WSManager.log.warn("数据为:" + stringResult + ",无wsOpCode");
            }
            return null;
        }
        if (!WSManager.wsOpCodeMap.containsKey(wsOpCode)) {
            if (WSManager.log != null) {
                WSManager.log.warn("wsOpCode为:" + wsOpCode + "无对应解析,请及时解决");
            }
            return null;
        }
        Class<?> className = WSManager.wsOpCodeMap.get(wsOpCode);

        Method buildM = className.getDeclaredMethod("newBuilder");
        AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
        Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
        WsPacket wsPacket = new WsPacket(wsOpCode, data);
        return wsPacket;
    } catch (Exception e) {
        if (WSManager.log != null) {
            WSManager.log.error("json转换成protobuf异常", e);
        }
        return null;
    }
}
项目:ServerCore    文件:MessageDecoder.java   
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    // int占4个字节
    int messageId = in.readInt();
    // 消息体的长度(假设长度为20)
    byte[] bytes = new byte[in.readableBytes()];
    in.readBytes(bytes);
    // 4+20 =24
    AbstractMessage message = msgPool.getMessage(messageId);
    if (message == null) {
        LOGGER.error("未注册的消息id{}", messageId);
        return;
    }

    out.add(message.getParserForType().parseFrom(bytes));
}
项目:ServerCore    文件:MessageEncoder.java   
@Override
protected void encode(ChannelHandlerContext ctx, AbstractMessage msg, ByteBuf out) throws Exception {
    int messageId = msgPool.getMessageId(msg);
    if (messageId == 0) {
        LOGGER.error("编码到未知的消息{}", messageId);
    }
    byte[] bytes = msg.toByteArray();
    int length = Integer.BYTES + bytes.length;
    boolean writeAble = out.isWritable(length);
    if (!writeAble) {
        LOGGER.error("消息过大,编码失败 {} -> {}", messageId, length);
        return;
    }
    // int->4
    out.writeInt(messageId);
    // ->20(假设)
    out.writeBytes(bytes);

}
项目:sql-layer    文件:ProtobufReader.java   
private static void requireAllFieldsExcept(AbstractMessage message, int... fieldNumbersNotRequired) {
    Collection<Descriptors.FieldDescriptor> required = new ArrayList<>(message.getDescriptorForType().getFields());
    Collection<Descriptors.FieldDescriptor> actual = message.getAllFields().keySet();
    required.removeAll(actual);
    if(fieldNumbersNotRequired != null) {
        for(int fieldNumber : fieldNumbersNotRequired) {
            required.remove(message.getDescriptorForType().findFieldByNumber(fieldNumber));
        }
    }
    if(!required.isEmpty()) {
        Collection<String> names = new ArrayList<>(required.size());
        for(Descriptors.FieldDescriptor desc : required) {
            names.add(desc.getName());
        }
        throw new ProtobufReadException(message.getDescriptorForType().getFullName(),
                                        "Missing required fields: " + names.toString());
    }
}
项目:glowroot    文件:Messages.java   
public static <T extends /*@NonNull*/ AbstractMessage> List<T> parseDelimitedFrom(
        @Nullable ByteBuffer byteBuf, Parser<T> parser) throws IOException {
    if (byteBuf == null) {
        return ImmutableList.of();
    }
    SizeLimitBypassingParser<T> sizeLimitBypassingParser =
            new SizeLimitBypassingParser<>(parser);
    List<T> messages = Lists.newArrayList();
    try (InputStream input = new ByteBufferInputStream(byteBuf)) {
        T message;
        while ((message = sizeLimitBypassingParser.parseDelimitedFrom(input)) != null) {
            messages.add(message);
        }
    }
    return messages;
}
项目:elasticservices    文件:HttpTransportClient.java   
@Override
public void send(final MessageController messageController, final AbstractMessage message) {
    final AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    try {
        final Map<String, Collection<String>> headers = buildHeaders(messageController);
        final AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(url);
        requestBuilder.setHeaders(headers);
        requestBuilder.setBody(messagePayload(messageController, message));
        final Future<Response> f = requestBuilder.execute();
        final Response r = f.get();
        final String responseBody = r.getResponseBody();
        if (!"OK".equals(responseBody)) {
            LOGGER.warn("Non-OK response received for HTTP transport client request.");
        }
    } catch (final IOException | ExecutionException | InterruptedException e) {
        LOGGER.error("Could not execute HTTP request.", e);
    }
}
项目:elasticservices    文件:RabbitMqTransportClient.java   
@Override
public void send(final MessageController messageController, final AbstractMessage message) {
    sendCount.increment();
    final ServiceProto.ContentType contentType = getContentType(messageController);
    if (contentType == null) {
        sendFailureCount.increment();
        throw new RuntimeException("Could not get content type of message.");
    }
    try {
        final byte[] messageBytes = rawMessageBytes(contentType, message);
        final AMQP.BasicProperties basicProperties = buildBasicProperties(messageController, contentType);
        channel.basicPublish(
                transportRef.getExchange(),
                "fanout".equals(transportRef.getType()) ? "" : transportRef.getRoutingKey(),
                basicProperties,
                messageBytes);
    } catch (final Exception e) {
        sendFailureCount.increment();
        LOGGER.error("Exception caught publishing message:", e);
    }
}
项目:elasticservices    文件:DefaultResponseManager.java   
@Override
public Future<Message> sendAndReceive(
        final ServiceProto.ServiceRef destination,
        final AbstractMessage message,
        final Class messageClass,
        final Optional<Expiration> expirationOptional) {
    final SettableFuture<Message> resultsFuture = SettableFuture.create();
    final byte[] messageId = MessageUtils.randomMessageId(24);
    final MessageController controller =
            new DefaultMessageController(
                    serviceRef,
                    destination,
                    ContentTypes.fromClass(messageClass),
                    Optional.of(messageId),
                    Optional.<byte[]> absent(),
                    expirationOptional.isPresent() ? Optional.of(expirationOptional.get().getExpiration()) : Optional
                            .<DateTime> absent());
    resultsFutures.putIfAbsent(Arrays.hashCode(messageId), new Pair<>(resultsFuture, DateTime.now()));
    serviceRegistry.sendMessage(controller, message);
    return resultsFuture;
}
项目:TakinRPC    文件:NettyRpcProto.java   
public NettyRpcProto.RpcRequest build() {
    NettyRpcProto.RpcRequest result = buildPartial();
    if (!result.isInitialized()) {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
项目:TakinRPC    文件:NettyRpcProto.java   
public NettyRpcProto.RpcResponse build() {
    NettyRpcProto.RpcResponse result = buildPartial();
    if (!result.isInitialized()) {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
项目:TakinRPC    文件:NettyRpcProto.java   
public NettyRpcProto.RpcCancelRequest build() {
    NettyRpcProto.RpcCancelRequest result = buildPartial();
    if (!result.isInitialized()) {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
项目:TakinRPC    文件:NettyRpcProto.java   
public NettyRpcProto.RpcContainer build() {
    NettyRpcProto.RpcContainer result = buildPartial();
    if (!result.isInitialized()) {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
项目:grain    文件:CodeUtils.java   
/**
 * 将字符串转换成HttpPacket
 * 
 * @param stringResult
 *            字符串
 * @param isServer
 *            是不是服务器一般传true
 * @param httpPacket
 *            消息包
 * @return
 */
public static boolean decodeJson(String stringResult, boolean isServer, HttpPacket httpPacket) {
    try {
        // 转换成json获取hOpCode,如果没有看看头消息有没有
        JSONObject jsObj = JSONObject.fromObject(stringResult);
        String hOpCode;
        if (jsObj.containsKey(AllowParam.HOPCODE)) {
            hOpCode = jsObj.getString(AllowParam.HOPCODE);
        } else if (httpPacket.hSession.headParam.hOpCode != null && !httpPacket.hSession.headParam.hOpCode.equals("")) {
            hOpCode = httpPacket.hSession.headParam.hOpCode;
        } else {
            return false;
        }
        // 是否设定相应解析
        if (!HttpManager.hOpCodeMap.containsKey(hOpCode)) {
            if (HttpConfig.log != null) {
                HttpConfig.log.warn("hOpCode为:" + hOpCode + "无对应解析,请及时解决");
            }
            return false;
        }
        // 解析
        Class<?>[] classNames = HttpManager.hOpCodeMap.get(hOpCode);
        Class<?> className;
        if (isServer) {
            className = classNames[0];
        } else {
            className = classNames[1];
        }
        Method buildM = className.getDeclaredMethod("newBuilder");
        AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
        Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
        if (data == null) {
            return false;
        }
        // 设置hOpCode和消息体
        httpPacket.sethOpCode(hOpCode);
        httpPacket.setData(data);
        return true;
    } catch (Exception e) {
        if (HttpConfig.log != null) {
            HttpConfig.log.error("json转换成protobuf异常", e);
        }
        return false;
    }
}
项目:ServerCore    文件:MessageRouter.java   
@SuppressWarnings("unchecked")
@Override
public void consume(AbstractMessage msg, Channel channel) {

    //将消息分发到指定的队列中,该队列有可能在同一个进程,也有可能不在同一个进程

    int queueId = 1;

    IProcessor processor = processors.get(queueId);
    if (processor == null) {
        log.error("找不到可用的消息处理器[{}]", queueId);
        return;
    }

    Session session = AttributeUtil.get(channel, SessionKey.SESSION);

    if (session == null) {
        return;
    }

    AbstractHandler handler = msgPool.getHandler(msg.getClass().getName());
    handler.setMessage(msg);
    handler.setParam(session);
    log.debug("收到消息:" + msg);

    processor.process(handler);

}
项目:hbase-connect-kafka    文件:HRowProtos.java   
public Row build() {
  Row result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:hbase-connect-kafka    文件:HColumnProtos.java   
public HColumn build() {
  HColumn result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:ChessGameServer    文件:MessageRouter.java   
@SuppressWarnings("unchecked")
@Override
public void consume(AbstractMessage msg, Channel channel) {

    //将消息分发到指定的队列中,该队列有可能在同一个进程,也有可能不在同一个进程

    int queueId = 1;

    IProcessor processor = processors.get(queueId);
    if (processor == null) {
        LOGGER.error("找不到可用的消息处理器[{}]", queueId);
        return;
    }

    Session session = AttributeUtil.get(channel, SessionKey.SESSION);

    if (session == null) {
        return;
    }

    AbstractHandler handler = msgPool.getHandler(msg.getClass().getName());
    handler.setMessage(msg);
    handler.setParam(session);
    LOGGER.debug("收到消息:" + msg);

    processor.process(handler);

}
项目:ChessGameServer    文件:MessageUtil.java   
public static void sendMsg(AbstractMessage msg, long id) {
    Session session = SessionManager.getInstance().getSession(id);
    if (session == null) {
        return;
    }
    session.sendMessage(msg);
}
项目:ChessGameServer    文件:MessageUtil.java   
public static void sendMsgToRids(AbstractMessage msg, Collection<Long> rids) {
    for (Long rid : rids) {
        if (rid != null) {
            sendMsg(msg, rid);
        }
    }
}
项目:ChessGameServer    文件:MessageUtil.java   
public static void sendMsgToRids(AbstractMessage msg, Collection<Long> rids, Long exceptRoleId) {
    for (Long rid : rids) {
        if (rid != null && (!rid.equals(exceptRoleId))) {
            sendMsg(msg, rid);
        }
    }
}
项目:fountain    文件:DataUnitDef.java   
public DataUnitDef.ColumnValue build() {
  DataUnitDef.ColumnValue result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:fountain    文件:DataUnitDef.java   
public DataUnitDef.ColumnMeta build() {
  DataUnitDef.ColumnMeta result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:fountain    文件:DataUnitDef.java   
public DataUnitDef.RowData build() {
  DataUnitDef.RowData result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:fountain    文件:DataUnitDef.java   
public DataUnitDef.TableData build() {
  DataUnitDef.TableData result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:fountain    文件:DataUnitDef.java   
public DataUnitDef.DataSet build() {
  DataUnitDef.DataSet result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:SerializationProtocolsBenchMark    文件:AddressBookProtos.java   
public AddressBookProtos.Person build() {
  AddressBookProtos.Person result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:SerializationProtocolsBenchMark    文件:AddressBookProtos.java   
public AddressBookProtos.AddressBook build() {
  AddressBookProtos.AddressBook result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:core-java    文件:ColumnTypeRegistryShould.java   
@Test
public void find_closest_superclass_column_type() {
    final ColumnTypeRegistry<?> registry =
            ColumnTypeRegistry.newBuilder()
                              .put(GeneratedMessageV3.class, new GeneratedMessageType())
                              .put(AbstractMessage.class, new AbstractMessageType())
                              .build();
    final EntityColumn column = mockProperty(Any.class);
    final ColumnType type = registry.get(column);
    assertNotNull(type);
    assertThat(type, instanceOf(GeneratedMessageType.class));
}
项目:glowroot    文件:Messages.java   
public static ByteBuffer toByteBuffer(List<? extends AbstractMessage> messages)
        throws IOException {
    // TODO optimize byte copying
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    for (AbstractMessage message : messages) {
        message.writeDelimitedTo(output);
    }
    return ByteBuffer.wrap(output.toByteArray());
}
项目:glowroot    文件:AggregateInsert.java   
private static byte /*@Nullable*/ [] toByteArray(List<? extends AbstractMessage> messages)
        throws IOException {
    if (messages.isEmpty()) {
        return null;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (AbstractMessage message : messages) {
        message.writeDelimitedTo(baos);
    }
    return baos.toByteArray();
}
项目:glowroot    文件:CappedDatabase.java   
public long writeMessage(final AbstractMessage message, String type) throws IOException {
    return write(type, new Copier() {
        @Override
        public void copyTo(OutputStream writer) throws IOException {
            message.writeTo(writer);
        }
    });
}
项目:glowroot    文件:CappedDatabase.java   
public long writeMessages(final List<? extends AbstractMessage> messages, String type)
        throws IOException {
    return write(type, new Copier() {
        @Override
        public void copyTo(OutputStream writer) throws IOException {
            for (AbstractMessage message : messages) {
                message.writeDelimitedTo(writer);
            }
        }
    });
}
项目:glowroot    文件:CappedDatabase.java   
public <T extends /*@NonNull*/ AbstractMessage> /*@Nullable*/ T readMessage(long cappedId,
        Parser<T> parser) throws IOException {
    boolean overwritten;
    boolean inTheFuture;
    synchronized (lock) {
        overwritten = out.isOverwritten(cappedId);
        inTheFuture = cappedId >= out.getCurrIndex();
    }
    if (overwritten) {
        return null;
    }
    if (inTheFuture) {
        // this can happen when the glowroot folder is copied for analysis without shutting down
        // the JVM and glowroot.capped.db is copied first, then new data is written to
        // glowroot.capped.db and the new capped ids are written to glowroot.h2.db and then
        // glowroot.h2.db is copied with capped ids that do not exist in the copied
        // glowroot.capped.db
        return null;
    }
    // it's important to wrap CappedBlockInputStream in a BufferedInputStream to prevent
    // lots of small reads from the underlying RandomAccessFile
    final int bufferSize = 32768;
    InputStream input = newLZFInputStream(
            new BufferedInputStream(new CappedBlockInputStream(cappedId), bufferSize));
    try {
        return parser.parseFrom(input);
    } catch (Exception e) {
        if (!out.isOverwritten(cappedId)) {
            logger.error(e.getMessage(), e);
        }
        return null;
    } finally {
        input.close();
    }
}
项目:jus    文件:PhoneProtos.java   
public PhoneProtos.Phone build() {
  PhoneProtos.Phone result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:test-load    文件:Entity.java   
public Entity.PlayerBlob build() {
  Entity.PlayerBlob result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
项目:test-load    文件:Entity.java   
private Entity.PlayerBlob buildParsed()
    throws com.google.protobuf.InvalidProtocolBufferException {
  Entity.PlayerBlob result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result).asInvalidProtocolBufferException();
  }
  return result;
}
项目:test-load    文件:Entity.java   
public Entity.PlayerBagStoreBlob build()
{
    Entity.PlayerBagStoreBlob result = buildPartial();
                  if (!result.isInitialized())
    {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
项目:test-load    文件:Entity.java   
private Entity.PlayerBagStoreBlob buildParsed() throws com.google.protobuf.InvalidProtocolBufferException
{
    Entity.PlayerBagStoreBlob result = buildPartial();
    if (!result.isInitialized())
    {
        throw AbstractMessage.Builder.newUninitializedMessageException(result).asInvalidProtocolBufferException();
    }
    return result;
}
项目:test-load    文件:Entity.java   
public Entity.PlayerEventSysStoreBlob build()
{
    Entity.PlayerEventSysStoreBlob result = buildPartial();
    if (!result.isInitialized())
    {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
项目:test-load    文件:Entity.java   
private Entity.PlayerEventSysStoreBlob buildParsed() throws com.google.protobuf.InvalidProtocolBufferException
{
    Entity.PlayerEventSysStoreBlob result = buildPartial();
    if (!result.isInitialized())
    {
        throw AbstractMessage.Builder.newUninitializedMessageException(result).asInvalidProtocolBufferException();
    }
    return result;
}