当前位置: 首页>>代码示例>>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;未经允许,请勿转载。