當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneratedMessage類代碼示例

本文整理匯總了Java中com.google.protobuf.GeneratedMessage的典型用法代碼示例。如果您正苦於以下問題:Java GeneratedMessage類的具體用法?Java GeneratedMessage怎麽用?Java GeneratedMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GeneratedMessage類屬於com.google.protobuf包,在下文中一共展示了GeneratedMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendCall

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
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;
        }

    }
 
開發者ID:HujiangTechnology,項目名稱:Juice,代碼行數:22,代碼來源:SendUtils.java

示例2: testHostIdentification

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Test
public void testHostIdentification() {
    final GeneratedMessage protobufMessage = Messages.HostIdentification.getDefaultInstance();
    final AggregationMessage message = AggregationMessage.create(protobufMessage);
    Assert.assertNotNull(message);
    Assert.assertSame(protobufMessage, message.getMessage());

    final Buffer vertxBuffer = message.serialize();
    final byte[] messageBuffer = vertxBuffer.getBytes();
    final byte[] protobufBuffer = protobufMessage.toByteArray();
    ByteString.fromArray(vertxBuffer.getBytes());

    // Assert length
    Assert.assertEquals(protobufBuffer.length + 5, messageBuffer.length);
    Assert.assertEquals(protobufBuffer.length + 5, vertxBuffer.getInt(0));
    Assert.assertEquals(protobufBuffer.length + 5, message.getLength());

    // Assert payload type
    Assert.assertEquals(1, messageBuffer[4]);

    // Assert the payload was not corrupted
    for (int i = 0; i < protobufBuffer.length; ++i) {
        Assert.assertEquals(protobufBuffer[i], messageBuffer[i + 5]);
    }
}
 
開發者ID:ArpNetworking,項目名稱:metrics-aggregator-daemon,代碼行數:26,代碼來源:AggregationMessageTest.java

示例3: decode

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public <T> T decode(final Class<T> clazz, byte[] data) throws CodecException {
    try {
        if (data == null || data.length == 0) {
            return null;
        }
        Method m = PROTOBUF_METHOD_CACHE.getComputeResult(clazz.getName() + METHOD_NAME_PARSEFROM,
                new Callable<Method>() {
                    @Override
                    public Method call() throws Exception {
                        return clazz.getMethod(METHOD_NAME_PARSEFROM, byte[].class);
                    }
                });
        GeneratedMessage msg = (GeneratedMessage) m.invoke(clazz, data);
        return (T) msg;
    } catch (Exception e) {
        throw new CodecException("Decode failed due to " + e.getMessage(), e);
    }
}
 
開發者ID:wangchongjie,項目名稱:multi-engine,代碼行數:20,代碼來源:ProtobufCodec.java

示例4: proto0

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Task proto0(GeneratedMessage message) {
    org.apache.mesos.Protos.TaskInfo task = (org.apache.mesos.Protos.TaskInfo) message;

    name = task.getName();
    id = task.getTaskId().getValue();
    slaveId = task.getSlaveId().getValue();

    resources.clear();
    for (org.apache.mesos.Protos.Resource resource : task.getResourcesList())
        resources.add(new Resource().proto0(resource));

    if (task.hasExecutor()) executor = new Executor().proto0(task.getExecutor());
    if (task.hasCommand()) command = new Command().proto0(task.getCommand());

    if (task.hasData()) data = task.getData().toByteArray();
    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:19,代碼來源:Task.java

示例5: proto1

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Task proto1(GeneratedMessage message) {
    org.apache.mesos.v1.Protos.TaskInfo task = (org.apache.mesos.v1.Protos.TaskInfo) message;

    name = task.getName();
    id = task.getTaskId().getValue();
    slaveId = task.getAgentId().getValue();

    resources.clear();
    for (org.apache.mesos.v1.Protos.Resource resource : task.getResourcesList())
        resources.add(new Resource().proto1(resource));

    if (task.hasExecutor()) executor = new Executor().proto1(task.getExecutor());
    if (task.hasCommand()) command = new Command().proto1(task.getCommand());

    if (task.hasData()) data = task.getData().toByteArray();
    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:19,代碼來源:Task.java

示例6: proto0

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Offer proto0(GeneratedMessage message) {
    org.apache.mesos.Protos.Offer offer = (org.apache.mesos.Protos.Offer) message;

    id = offer.getId().getValue();
    frameworkId = offer.getFrameworkId().getValue();
    slaveId = offer.getSlaveId().getValue();
    hostname = offer.getHostname();

    resources.clear();
    for (org.apache.mesos.Protos.Resource resource : offer.getResourcesList())
        resources.add(new Resource().proto0(resource));

    attributes.clear();
    for (org.apache.mesos.Protos.Attribute attribute : offer.getAttributesList())
        attributes.add(new Attribute().proto0(attribute));

    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:20,代碼來源:Offer.java

示例7: proto1

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Offer proto1(GeneratedMessage message) {
    org.apache.mesos.v1.Protos.Offer offer = (org.apache.mesos.v1.Protos.Offer) message;

    id = offer.getId().getValue();
    frameworkId = offer.getFrameworkId().getValue();
    slaveId = offer.getAgentId().getValue();
    hostname = offer.getHostname();

    resources.clear();
    for (org.apache.mesos.v1.Protos.Resource resource : offer.getResourcesList())
        resources.add(new Resource().proto1(resource));

    attributes.clear();
    for (org.apache.mesos.v1.Protos.Attribute attribute : offer.getAttributesList())
        attributes.add(new Attribute().proto1(attribute));

    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:20,代碼來源:Offer.java

示例8: newCall

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
private Call newCall(GeneratedMessage.Builder builder) {
    Message obj = builder.build();

    Call.Builder call = newBuilder();
    call.setExecutorId(org.apache.mesos.v1.Protos.ExecutorID.newBuilder().setValue(System.getenv("MESOS_EXECUTOR_ID")));
    call.setFrameworkId(org.apache.mesos.v1.Protos.FrameworkID.newBuilder().setValue(System.getenv("MESOS_FRAMEWORK_ID")));

    if (obj instanceof Subscribe) {
        call.setSubscribe((Subscribe) obj);
        call.setType(Call.Type.SUBSCRIBE);
    } else if (obj instanceof Call.Message) {
        call.setMessage((Call.Message) obj);
        call.setType(Call.Type.MESSAGE);
    } else if (obj instanceof Update) {
        call.setUpdate((Update) obj);
        call.setType(Call.Type.UPDATE);
    } else
        throw new UnsupportedOperationException("Unsupported object " + obj);

    return call.build();
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:22,代碼來源:ExecutorDriverV1.java

示例9: sendCall

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
protected void sendCall(GeneratedMessage call) {
    try {
        StringWriter body = new StringWriter();
        new JsonFormat().print(call, body);
        logger.debug("[call] " + body);

        Request request = new Request(url)
            .method(Request.Method.POST)
            .contentType("application/json")
            .accept("application/json")
            .body(("" + body).getBytes("utf-8"));

        if (streamId != null) // Mesos 0.25 has no streamId
            request.header("Mesos-Stream-Id", streamId);

        Request.Response response = request.send();
        logger.debug("[response] " + response.code() + " - " + response.message() + (response.body() != null ? ": " + new String(response.body()) : ""));
        if (response.code() != 202)
            throw new DriverException("Response: " + response.code() + " - " + response.message() + (response.body() != null ? ": " + new String(response.body()) : ""));

    } catch (IOException e) {
        throw new DriverException(e);
    }
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:25,代碼來源:AbstractDriverV1.java

示例10: proto0

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Command proto0(GeneratedMessage message) {
    org.apache.mesos.Protos.CommandInfo command = (org.apache.mesos.Protos.CommandInfo) message;
    value = command.getValue();

    uris.clear();
    for (org.apache.mesos.Protos.CommandInfo.URI uri : command.getUrisList())
        uris.add(new URI().proto0(uri));

    if (command.hasEnvironment()) {
        env.clear();
        for (org.apache.mesos.Protos.Environment.Variable var : command.getEnvironment().getVariablesList())
            env.put(var.getName(), var.getValue());
    }

    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:18,代碼來源:Command.java

示例11: proto1

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Command proto1(GeneratedMessage message) {
    org.apache.mesos.v1.Protos.CommandInfo command = (org.apache.mesos.v1.Protos.CommandInfo) message;
    value = command.getValue();

    uris = new ArrayList<>();
    for (org.apache.mesos.v1.Protos.CommandInfo.URI uri : command.getUrisList())
        uris.add(new URI().proto1(uri));

    if (command.hasEnvironment()) {
        env = new LinkedHashMap<>();
        for (org.apache.mesos.v1.Protos.Environment.Variable var : command.getEnvironment().getVariablesList())
            env.put(var.getName(), var.getValue());
    }

    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:18,代碼來源:Command.java

示例12: proto0

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Framework proto0(GeneratedMessage message) {
    org.apache.mesos.Protos.FrameworkInfo framework = (org.apache.mesos.Protos.FrameworkInfo) message;

    if (framework.hasId()) id = framework.getId().getValue();
    if (framework.hasName()) name = framework.getName();

    if (framework.hasUser()) user = framework.getUser();
    if (framework.hasFailoverTimeout()) timeout = new Period((long)framework.getFailoverTimeout() + "s");

    checkpoint = framework.getCheckpoint();
    role = framework.getRole();

    if (framework.hasPrincipal()) principal = framework.getPrincipal();
    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:17,代碼來源:Framework.java

示例13: proto1

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
@Override
public Framework proto1(GeneratedMessage message) {
    org.apache.mesos.v1.Protos.FrameworkInfo framework = (org.apache.mesos.v1.Protos.FrameworkInfo) message;

    if (framework.hasId()) id = framework.getId().getValue();
    if (framework.hasName()) name = framework.getName();

    if (framework.hasUser()) user = framework.getUser();
    if (framework.hasFailoverTimeout()) timeout = new Period((long)framework.getFailoverTimeout() + "s");

    checkpoint = framework.getCheckpoint();
    role = framework.getRole();

    if (framework.hasPrincipal()) principal = framework.getPrincipal();
    return this;
}
 
開發者ID:elodina,項目名稱:java-mesos-util,代碼行數:17,代碼來源:Framework.java

示例14: asyncTransport

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
/**
 * @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);
    }
}
 
開發者ID:neoremind,項目名稱:navi-pbrpc,代碼行數:21,代碼來源:PooledPbrpcClient.java

示例15: asyncTransport

import com.google.protobuf.GeneratedMessage; //導入依賴的package包/類
/**
 * @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);
    }
}
 
開發者ID:neoremind,項目名稱:navi-pbrpc,代碼行數:20,代碼來源:SimplePbrpcClient.java


注:本文中的com.google.protobuf.GeneratedMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。