com.google.protobuf.GeneratedMessage Java Examples

The following examples show how to use com.google.protobuf.GeneratedMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeartbeatEndpointTask.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Adds all the available reports to heartbeat.
 *
 * @param requestBuilder builder to which the report has to be added.
 */
private void addReports(SCMHeartbeatRequestProto.Builder requestBuilder) {
  for (GeneratedMessage report :
      context.getAllAvailableReports(rpcEndpoint.getAddress())) {
    String reportName = report.getDescriptorForType().getFullName();
    for (Descriptors.FieldDescriptor descriptor :
        SCMHeartbeatRequestProto.getDescriptor().getFields()) {
      String heartbeatFieldName = descriptor.getMessageType().getFullName();
      if (heartbeatFieldName.equals(reportName)) {
        if (descriptor.isRepeated()) {
          requestBuilder.addRepeatedField(descriptor, report);
        } else {
          requestBuilder.setField(descriptor, report);
        }
      }
    }
  }
}
 
Example #2
Source File: PbrpcClientChannel.java    From navi-pbrpc with Apache License 2.0 6 votes vote down vote up
/**
 * 异步调用
 * 
 * @param responseClazz
 * @param pbrpcMsg
 * @param readTimeout
 *            客户端调用超时时间
 * @return
 * @throws Exception
 */
public <T extends GeneratedMessage> CallFuture<T> asyncTransport(Class<T> responseClazz,
        PbrpcMsg pbrpcMsg, int readTimeout) throws Exception {
    if (channelFuture != null) {
        try {
            int uuid = IdGenerator.genUUID();
            pbrpcMsg.setLogId(uuid);
            CallFuture<T> future = CallFuture.newInstance();
            CallbackPool.put(uuid, readTimeout, false, null, responseClazz, future);
            // long start = System.currentTimeMillis();
            channelFuture.channel().writeAndFlush(pbrpcMsg);
            // LOG.info("Send message " + pbrpcMsg + " done using " + (System.currentTimeMillis() - start) + "ms");
            return future;
        } catch (Exception e) {
            LOG.error(
                    "Failed to transport to " + channelFuture.channel() + " due to "
                            + e.getMessage(), e);
            throw new PbrpcException(e);
        }
    } else {
        LOG.error("Socket channel is not well established, so failed to transport");
        throw new PbrpcException(
                "ChannelFuture is null! Socket channel is not well established, so failed to transport");
    }

}
 
Example #3
Source File: ReportPublisherFactory.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the ReportPublisher for the corresponding report.
 *
 * @param report report
 *
 * @return report publisher
 */
public ReportPublisher getPublisherFor(
    Class<? extends GeneratedMessage> report) {
  Class<? extends ReportPublisher> publisherClass =
      report2publisher.get(report);
  if (publisherClass == null) {
    throw new RuntimeException("No publisher found for report " + report);
  }
  try {
    ReportPublisher reportPublisher = publisherClass.newInstance();
    reportPublisher.setConf(conf);
    return reportPublisher;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #4
Source File: StorageFormatRegistry.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
/** Register a new {@link StorageFormat}.
 * @param protobufExtension the extension field that keys use of this format
 * @param sqlIdentifier the <code>STORAGE_FORMAT</code> identifier that keys use of this format or <code>null</code>
 * @param descriptionClass that specific class used to hold this format
 * @param storageFormat the mapping handler
 */
public <T extends StorageDescription> void registerStorageFormat(GeneratedMessage.GeneratedExtension<Storage,?> protobufExtension, String sqlIdentifier, Class<T> descriptionClass, StorageFormat<T> storageFormat) {
    int fieldNumber = protobufExtension.getDescriptor().getNumber();
    if (formatsByField.containsKey(fieldNumber))
        throw new IllegalArgumentException("there is already a StorageFormat registered for field " + fieldNumber);
    if ((sqlIdentifier != null) &&
            formatsByIdentifier.containsKey(sqlIdentifier))
        throw new IllegalArgumentException("there is already a StorageFormat registered for STORAGE_FORMAT " + sqlIdentifier);
    if (!isDescriptionClassAllowed(descriptionClass)) {
        throw new IllegalArgumentException("description " + descriptionClass + " not allowed for " + getClass().getSimpleName());
    }
    extensionRegistry.add(protobufExtension);
    Format<T> format = new Format<T>(protobufExtension, sqlIdentifier, descriptionClass, storageFormat);
    formatsInOrder.add(format);
    formatsByField.put(fieldNumber, format);
    if (sqlIdentifier != null) {
        formatsByIdentifier.put(sqlIdentifier, format);
    }
}
 
Example #5
Source File: BlockingIOPooledPbrpcClient.java    From navi-pbrpc with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.PbrpcClient#syncTransport(java.lang.Class,
 *      com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
@Override
public <T extends GeneratedMessage> T syncTransport(Class<T> responseClazz, PbrpcMsg pbrpcMsg) {
    BlockingIOPbrpcClient client = socketPool.getResource();
    try {
        T res = client.syncTransport(responseClazz, pbrpcMsg);
        return res;
    } catch (Exception e) {
        LOG.error("asyncTransport failed, " + e.getMessage(), e);
        socketPool.returnBrokenResource(client);
        throw new PbrpcException("Pbrpc invocation failed on " + getInfo() + ", "
                + e.getMessage(), e);
    } finally {
        socketPool.returnResource(client);
    }
}
 
Example #6
Source File: SendUtils.java    From Juice with GNU General Public License v3.0 6 votes vote down vote up
public static void sendCall(GeneratedMessage call, Protocol protocol, String streamId, String url) throws IOException {

        log.debug("[call] " + call);

        Restty restty = Restty.create(url)
                .addAccept(protocol.mediaType())
                .addMediaType(protocol.mediaType())
                .requestBody(protocol.getSendBytes(call));

        if (StringUtils.isNotBlank(streamId)) {
            restty.addHeader("Mesos-Stream-Id", streamId);
        }

        try {
            restty.postNoResponse();
        } catch (IOException e) {
            log.warn("send call to mesos master failed, due to : " + e);
            throw e;
        }

    }
 
Example #7
Source File: REEFMessageCodec.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] encode(final GeneratedMessage msg) {
  final REEFProtocol.REEFMessage.Builder message = REEFProtocol.REEFMessage.newBuilder();

  if (msg instanceof ClientRuntimeProtocol.JobControlProto) {
    message.setJobControl((ClientRuntimeProtocol.JobControlProto) msg);
  } else if (msg instanceof ReefServiceProtos.RuntimeErrorProto) {
    message.setRuntimeError((ReefServiceProtos.RuntimeErrorProto) msg);
  } else if (msg instanceof ReefServiceProtos.JobStatusProto) {
    message.setJobStatus((ReefServiceProtos.JobStatusProto) msg);
  } else if (msg instanceof EvaluatorRuntimeProtocol.EvaluatorControlProto) {
    message.setEvaluatorControl((EvaluatorRuntimeProtocol.EvaluatorControlProto) msg);
  } else if (msg instanceof EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto) {
    message.setEvaluatorHeartBeat((EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto) msg);
  } else if (msg instanceof EvaluatorShimProtocol.EvaluatorShimControlProto) {
    message.setEvaluatorShimCommand((EvaluatorShimProtocol.EvaluatorShimControlProto) msg);
  } else if (msg instanceof EvaluatorShimProtocol.EvaluatorShimStatusProto) {
    message.setEvaluatorShimStatus((EvaluatorShimProtocol.EvaluatorShimStatusProto) msg);
  } else {
    throw new RuntimeException("Unable to serialize: " + msg);
  }

  return message.build().toByteArray();
}
 
Example #8
Source File: SqlResultMessageListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Boolean createFromMessage(XMessage message) {
    GeneratedMessage msg = (GeneratedMessage) message.getMessage();
    Class<? extends GeneratedMessage> msgClass = msg.getClass();
    if (this.resultType == null) {
        if (ColumnMetaData.class.equals(msgClass)) {
            this.resultType = ResultType.DATA;
        } else if (!Error.class.equals(msgClass)) {
            this.resultType = ResultType.UPDATE;
        }
    }

    if (this.resultType == ResultType.DATA) {
        // delegate to the result creation
        return this.resultListener.createFromMessage(message);
    }
    // done
    return this.okListener.createFromMessage(message);
}
 
Example #9
Source File: SimplePbrpcClient.java    From navi-pbrpc with Apache License 2.0 6 votes vote down vote up
/**
 * 使用channel进行数据发送
 * 
 * @param ch
 * @param responseClazz
 * @param pbrpcMsg
 * @return
 */
protected <T extends GeneratedMessage> CallFuture<T> doAsyncTransport(Channel ch,
        Class<T> responseClazz, PbrpcMsg pbrpcMsg) {
    if (ch != null) {
        int uuid = IdGenerator.genUUID();
        pbrpcMsg.setLogId(uuid);
        CallFuture<T> future = CallFuture.newInstance();
        CallbackPool.put(uuid, this.readTimeout, this.isShortAliveConn, ch, responseClazz,
                future);
        ch.writeAndFlush(pbrpcMsg);
        LOG.debug("Send message " + pbrpcMsg + " done");
        return future;
    } else {
        LOG.error("Socket channel is not well established, so failed to transport on "
                + getInfo());
        throw new PbrpcConnectionException(
                "Socket channel is not well established,so failed to transport on " + getInfo());
    }
}
 
Example #10
Source File: SimplePbrpcClient.java    From navi-pbrpc with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.PbrpcClient#asyncTransport(java.lang.Class,
 *      com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
public <T extends GeneratedMessage> CallFuture<T> asyncTransport(Class<T> responseClazz,
        PbrpcMsg pbrpcMsg) {
    try {
        if (isShortAliveConn) {
            ChannelFuture channelFuture = connect().sync();
            Channel ch = channelFuture.channel();
            return doAsyncTransport(ch, responseClazz, pbrpcMsg);
        } else {
            return doAsyncTransport(this.channel, responseClazz, pbrpcMsg);
        }
    } catch (Exception e) {
        LOG.error("Failed to transport to " + getInfo() + " due to " + e.getMessage(), e);
        throw new PbrpcException(e);
    }
}
 
Example #11
Source File: ProtosWithComplexAndRepeatedFieldsTest.java    From gson with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  gson =
      new GsonBuilder()
          .registerTypeHierarchyAdapter(GeneratedMessage.class,
              ProtoTypeAdapter.newBuilder()
                  .setEnumSerialization(EnumSerialization.NUMBER)
                  .build())
          .create();
  upperCamelGson =
      new GsonBuilder()
          .registerTypeHierarchyAdapter(
              GeneratedMessage.class, ProtoTypeAdapter.newBuilder()
                  .setFieldNameSerializationFormat(
                      CaseFormat.LOWER_UNDERSCORE, CaseFormat.UPPER_CAMEL)
                  .build())
          .create();
}
 
Example #12
Source File: PooledPbrpcClient.java    From navi-pbrpc with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.PbrpcClient#asyncTransport(java.lang.Class,
 *      com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
@Override
public <T extends GeneratedMessage> CallFuture<T> asyncTransport(Class<T> responseClazz,
        PbrpcMsg pbrpcMsg) {
    PbrpcClientChannel channel = channelPool.getResource();
    try {
        CallFuture<T> res = channel.asyncTransport(responseClazz, pbrpcMsg, this.readTimeout);
        return res;
    } catch (Exception e) {
        LOG.error("asyncTransport failed, " + e.getMessage(), e);
        channelPool.returnBrokenResource(channel);
        throw new PbrpcException("Pbrpc invocation failed on " + getInfo() + ", "
                + e.getMessage(), e);
    } finally {
        channelPool.returnResource(channel);
    }
}
 
Example #13
Source File: WriteEvents.java    From esj with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public GeneratedMessage getDto(Settings settings) {
    ClientMessageDtos.WriteEvents.Builder web = ClientMessageDtos.WriteEvents.newBuilder();
    web.setEventStreamId(streamId);
    web.setExpectedVersion(expectedVersion);
    web.setRequireMaster(settings.isRequireMaster());

    List<ClientMessageDtos.NewEvent> newEvents = new ArrayList<>();

    for (Event e : events) {
        newEvents.add(e.getMessageEvent());
    }

    web.addAllEvents(newEvents);

    return web.build();
}
 
Example #14
Source File: SyncMessageReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public XMessage readMessage(Optional<XMessage> reuse, int expectedType) throws IOException {
    try {
        Class<? extends GeneratedMessage> messageClass = MessageConstants.getMessageClassForType(readHeader().getMessageType());
        Class<? extends GeneratedMessage> expectedClass = MessageConstants.getMessageClassForType(expectedType);

        // ensure that parsed message class matches incoming tag
        if (expectedClass != messageClass) {
            throw new WrongArgumentException("Unexpected message class. Expected '" + expectedClass.getSimpleName() + "' but actually received '"
                    + messageClass.getSimpleName() + "'");
        }

        return new XMessage(readAndParse(messageClass));
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    }
}
 
Example #15
Source File: ControllableRunner.java    From clarity with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private TreeSet<PacketPosition> getResetPacketsBeforeTick(int wantedTick) throws IOException {
    int backup = source.getPosition();
    PacketPosition wanted = PacketPosition.createPacketPosition(wantedTick, ResetRelevantKind.FULL_PACKET, 0);
    if (resetRelevantPackets.tailSet(wanted, true).size() == 0) {
        PacketPosition basePos = resetRelevantPackets.floor(wanted);
        source.setPosition(basePos.getOffset());
        try {
            while (true) {
                int at = source.getPosition();
                PacketInstance<GeneratedMessage> pi = engineType.getNextPacketInstance(source);
                PacketPosition pp = newResetRelevantPacketPosition(pi.getTick(), pi.getResetRelevantKind(), at);
                if (pp != null) {
                    addResetRelevant(pp);
                }
                if (pi.getTick() >= wantedTick) {
                    break;
                }
                pi.skip();
            }
        } catch (EOFException e) {
        }
    }
    source.setPosition(backup);
    return new TreeSet<>(resetRelevantPackets.headSet(wanted, true));
}
 
Example #16
Source File: RRLoadBalanceStrategy.java    From navi-pbrpc with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.ha.LoadBalanceStrategy#doSyncTransport(java.util.List, java.lang.Class,
 * com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
@SuppressWarnings("unchecked")
@Override
public <T extends GeneratedMessage> T doSyncTransport(List<PbrpcClient> clientList,
                                                      Class<T> responseClazz, PbrpcMsg pbrpcMsg) {
    return (T) transport(clientList, responseClazz, pbrpcMsg, false);
}
 
Example #17
Source File: LogFileV3.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a GeneratedMessage to a temp file, synchronizes it to disk
 * and then renames the file over file.
 * @param msg GeneratedMessage to write to the file
 * @param file destination file
 * @throws IOException if a write error occurs or the File.renameTo
 * method returns false meaning the file could not be overwritten.
 */
public static void writeDelimitedTo(GeneratedMessage msg, File file)
throws IOException {
  File tmp = Serialization.getMetaDataTempFile(file);
  FileOutputStream outputStream = new FileOutputStream(tmp);
  boolean closed = false;
  try {
    msg.writeDelimitedTo(outputStream);
    outputStream.getChannel().force(true);
    outputStream.close();
    closed = true;
    if(!tmp.renameTo(file)) {
      //Some platforms don't support moving over an existing file.
      //So:
      //log.meta -> log.meta.old
      //log.meta.tmp -> log.meta
      //delete log.meta.old
      File oldFile = Serialization.getOldMetaDataFile(file);
      if(!file.renameTo(oldFile)){
        throw new IOException("Unable to rename " + file + " to " + oldFile);
      }
      if(!tmp.renameTo(file)) {
        throw new IOException("Unable to rename " + tmp + " over " + file);
      }
      oldFile.delete();
    }
  } finally {
    if(!closed) {
      try {
        outputStream.close();
      } catch(IOException e) {
        LOGGER.warn("Unable to close " + tmp, e);
      }
    }
  }

}
 
Example #18
Source File: SimplePbrpcClient.java    From navi-pbrpc with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.PbrpcClient#syncTransport(java.lang.Class,
 *      com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
public <T extends GeneratedMessage> T syncTransport(Class<T> responseClazz, PbrpcMsg pbrpcMsg) {
    try {
        return asyncTransport(responseClazz, pbrpcMsg).get();
    } catch (InterruptedException e) {
        throw new PbrpcConnectionException("Transport failed on " + getInfo() + ", "
                + e.getMessage(), e);
    }
}
 
Example #19
Source File: PbrpcClientHandler.java    From navi-pbrpc with Apache License 2.0 5 votes vote down vote up
/**
 * @see io.netty.channel.SimpleChannelInboundHandler#channelRead0(io.netty.channel.ChannelHandlerContext,
 *      java.lang.Object)
 */
@SuppressWarnings("unchecked")
@Override
public void channelRead0(ChannelHandlerContext ctx, PbrpcMsg pbrpcMsg) throws Exception {
    Preconditions
            .checkArgument(pbrpcMsg != null, "Pbrpc msg is null which should never happen");
    try {
        // LOG.info("Got msg from server:" + pbrpcMsg);
        int logId = (int) pbrpcMsg.getLogId();
        CallbackContext context = CallbackPool.getContext(logId);
        if (context == null) {
            LOG.warn("Receive msg from server but no context found, logId=" + logId);
            return;
        }
        Callback<GeneratedMessage> cb = (Callback<GeneratedMessage>) context.getCallback();
        if (pbrpcMsg.getErrorCode() != null) {
            cb.handleError(ExceptionUtil.buildFromErrorCode(pbrpcMsg.getErrorCode()));
        } else {
            GeneratedMessage res = (GeneratedMessage) codec.decode(
                    CallbackPool.getResClass(logId), pbrpcMsg.getData());
            cb.handleResult(res);
        }

        // 短连接则关闭channel
        if (context.isShortAliveConn()) {
            Channel channel = context.getChannel();
            if (channel != null) {
                LOG.info("Close " + channel + ", logId=" + logId);
                channel.close();
            }
        }
        // LOG.info("Decoding and invoking callback " + pbrpcMsg.getLogId() + " total "
        // + (System.currentTimeMillis() - context.getStarttime())
        // + "ms, transport using " + (start - context.getStarttime()) + "ms");
    } finally {
        CallbackPool.remove((int) pbrpcMsg.getLogId());
        ContextHolder.clean();
        // ctx.fireChannelReadComplete();
    }
}
 
Example #20
Source File: LiveSourceTest.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(enabled = false)
@Parameters({"srcFile", "dstFile"})
public void demoLiveSource(final String srcFile, final String dstFile) throws Exception {
    createWriterThread(srcFile, dstFile);

    LiveSource source = new LiveSource(dstFile, 5, TimeUnit.SECONDS);
    new SimpleRunner(source).runWith(new Object() {
        @OnMessage
        public void onMessage(GeneratedMessage msg) {
            System.out.println(msg.getClass().getSimpleName());
        }
    });
}
 
Example #21
Source File: SubscribeToStream.java    From esj with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public GeneratedMessage getDto(Settings settings) {
    ClientMessageDtos.SubscribeToStream.Builder web = ClientMessageDtos.SubscribeToStream.newBuilder();
    web.setEventStreamId(streamId);
    web.setResolveLinkTos(resolveLinkTos);

    return web.build();
}
 
Example #22
Source File: WalletClient.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] serializeProtobuf(final GeneratedMessage msg) {
    final byte[] byteArray = new byte[msg.getSerializedSize()];
    final CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(byteArray);
    try {
        msg.writeTo(codedOutputStream);
    } catch (final IOException e) {
        Log.e(TAG, "failed to serialize message: " + e.toString());
        e.printStackTrace();
        return null;
    }
    return byteArray;
}
 
Example #23
Source File: MesosController.java    From funcatron with Apache License 2.0 5 votes vote down vote up
/**
 * Given a GeneratedMessage object, get a Map of the state. Why? More Clojure-friendly
 *
 * @param status the GeneratedMessage
 * @return a key/value set of the fields
 */
public static Map<String, Object> statusToMap(GeneratedMessage status) {
    return status.getAllFields().entrySet().
            stream().
            collect(Collectors.toMap(e -> e.getKey().getName(),
                    Map.Entry::getValue));

}
 
Example #24
Source File: HAPbrpcClient.java    From navi-pbrpc with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.PbrpcClient#asyncTransport(java.lang.Class,
 * com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
@Override
public <T extends GeneratedMessage> CallFuture<T> asyncTransport(Class<T> responseClazz,
                                                                 PbrpcMsg pbrpcMsg) {
    Preconditions.checkNotNull(loadBalanceStrategy, "Load balance strategy is not init");
    return loadBalanceStrategy.doAsyncTransport(clientList, responseClazz, pbrpcMsg);
}
 
Example #25
Source File: InputSourceProcessor.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Initializer(OnMessageContainer.class)
public void initOnMessageContainerListener(final EventListener<OnMessageContainer> listener) {
    listener.setInvocationPredicate(args -> {
        Class<? extends GeneratedMessage> clazz = (Class<? extends GeneratedMessage>) args[0];
        return listener.getAnnotation().value().isAssignableFrom(clazz);
    });
}
 
Example #26
Source File: ProtobufDatumFactory.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
private ProtobufDatumFactory(String protobufClass) {
  try {
    String messageClassName = protobufClass;
    this.messageClass = (Class<? extends GeneratedMessage>) Class.forName(messageClassName);
    this.getDefaultInstance = messageClass.getMethod("getDefaultInstance");
    defaultInstance = (Message) getDefaultInstance.invoke(null);
  } catch (Throwable t) {
    t.printStackTrace();
    throw new RuntimeException(t);
  }
}
 
Example #27
Source File: ProtoHelpers.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
@Nullable
public static <
        MessageType extends GeneratedMessage.ExtendableMessage<MessageType>,
        Type extends GeneratedMessage>
    List<Type> getRepeatedExtensionObjects(
        GeneratedMessage.ExtendableMessageOrBuilder<MessageType> mob,
        ExtensionLite<MessageType, List<Type>> extension) {
  ImmutableList.Builder extensionList = ImmutableList.builder();
  int extensionCount = mob.getExtensionCount(extension);
  for (int extensionIndex = 0; extensionIndex < extensionCount; ++extensionIndex) {
    extensionList.add(mob.getExtension(extension, extensionIndex));
  }
  return extensionList.build();
}
 
Example #28
Source File: RandomProtobufGenerator.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private GeneratedMessage getRandomMessage(FieldDescriptor field, double p) {
  GeneratedMessage instance = moreInstances.get(field.getMessageType());
  if (instance == null) {
    throw new IllegalArgumentException("Couldn't find instance for message "
        + field.getMessageType().getFullName());
  }
  return new RandomProtobufGenerator<GeneratedMessage>(random, instance, moreInstances)
      .generate(p);
}
 
Example #29
Source File: ProtoHelpers.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
@Nullable
public static <
        MessageType extends GeneratedMessage.ExtendableMessage<MessageType>,
        Type extends GeneratedMessage>
    Type getExtensionObject(
        GeneratedMessage.ExtendableMessageOrBuilder<MessageType> mob,
        ExtensionLite<MessageType, Type> extension) {
  if (mob.hasExtension(extension)) {
    return mob.getExtension(extension);
  }
  return null;
}
 
Example #30
Source File: RRLoadBalanceStrategy.java    From navi-pbrpc with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.baidu.beidou.navi.pbrpc.client.ha.LoadBalanceStrategy#doAsyncTransport(java.util.List, java.lang.Class,
 * com.baidu.beidou.navi.pbrpc.transport.PbrpcMsg)
 */
@SuppressWarnings("unchecked")
@Override
public <T extends GeneratedMessage> CallFuture<T> doAsyncTransport(
        List<PbrpcClient> clientList, Class<T> responseClazz, PbrpcMsg pbrpcMsg)
        throws HAPbrpcException {
    return (CallFuture<T>) transport(clientList, responseClazz, pbrpcMsg, true);
}