Search in sources :

Example 1 with DataValue

use of com.yahoo.jrt.DataValue in project vespa by vespa-engine.

the class JRTServerConfigRequestV3 method addOkResponse.

@Override
public void addOkResponse(Payload payload, long generation, String configMd5) {
    boolean changedConfig = !configMd5.equals(getRequestConfigMd5());
    boolean changedConfigAndNewGeneration = changedConfig && ConfigUtils.isGenerationNewer(generation, getRequestGeneration());
    Payload responsePayload = payload.withCompression(getCompressionType());
    ByteArrayOutputStream byteArrayOutputStream = new NoCopyByteArrayOutputStream(4096);
    try {
        JsonGenerator jsonGenerator = createJsonGenerator(byteArrayOutputStream);
        jsonGenerator.writeStartObject();
        addCommonReturnValues(jsonGenerator);
        setResponseField(jsonGenerator, SlimeResponseData.RESPONSE_CONFIG_MD5, configMd5);
        setResponseField(jsonGenerator, SlimeResponseData.RESPONSE_CONFIG_GENERATION, generation);
        jsonGenerator.writeObjectFieldStart(SlimeResponseData.RESPONSE_COMPRESSION_INFO);
        if (responsePayload == null) {
            throw new RuntimeException("Payload is null for ' " + this + ", not able to create response");
        }
        CompressionInfo compressionInfo = responsePayload.getCompressionInfo();
        // If payload is not being sent, we must adjust compression info to avoid client confusion.
        if (!changedConfigAndNewGeneration) {
            compressionInfo = CompressionInfo.create(compressionInfo.getCompressionType(), 0);
        }
        compressionInfo.serialize(jsonGenerator);
        jsonGenerator.writeEndObject();
        if (log.isLoggable(LogLevel.SPAM)) {
            log.log(LogLevel.SPAM, getConfigKey() + ": response dataXXXXX" + payload.withCompression(CompressionType.UNCOMPRESSED) + "XXXXX");
        }
        jsonGenerator.writeEndObject();
        jsonGenerator.close();
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not add OK response for " + this);
    }
    request.returnValues().add(createResponseValue(byteArrayOutputStream));
    if (changedConfigAndNewGeneration) {
        request.returnValues().add(new DataValue(responsePayload.getData().getBytes()));
    } else {
        request.returnValues().add(new DataValue(new byte[0]));
    }
}
Also used : DataValue(com.yahoo.jrt.DataValue) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with DataValue

use of com.yahoo.jrt.DataValue in project vespa by vespa-engine.

the class RPCSendV1 method encodeRequest.

@Override
protected Request encodeRequest(Version version, Route route, RPCServiceAddress address, Message msg, long timeRemaining, byte[] payload, int traceLevel) {
    Request req = new Request(METHOD_NAME);
    Values v = req.parameters();
    v.add(new StringValue(version.toString()));
    v.add(new StringValue(route.toString()));
    v.add(new StringValue(address.getSessionName()));
    v.add(new Int8Value(msg.getRetryEnabled() ? (byte) 1 : (byte) 0));
    v.add(new Int32Value(msg.getRetry()));
    v.add(new Int64Value(timeRemaining));
    v.add(new StringValue(msg.getProtocol()));
    v.add(new DataValue(payload));
    v.add(new Int32Value(traceLevel));
    return req;
}
Also used : Int64Value(com.yahoo.jrt.Int64Value) DataValue(com.yahoo.jrt.DataValue) Request(com.yahoo.jrt.Request) Values(com.yahoo.jrt.Values) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value) StringValue(com.yahoo.jrt.StringValue)

Example 3 with DataValue

use of com.yahoo.jrt.DataValue in project vespa by vespa-engine.

the class RPCSendV2 method encodeRequest.

@Override
protected Request encodeRequest(Version version, Route route, RPCServiceAddress address, Message msg, long timeRemaining, byte[] payload, int traceLevel) {
    Request req = new Request(METHOD_NAME);
    Values v = req.parameters();
    v.add(new Int8Value(CompressionType.NONE.getCode()));
    v.add(new Int32Value(0));
    v.add(new DataValue(new byte[0]));
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString(VERSION_F, version.toString());
    root.setString(ROUTE_F, route.toString());
    root.setString(SESSION_F, address.getSessionName());
    root.setString(PROTOCOL_F, msg.getProtocol().toString());
    root.setBool(USERETRY_F, msg.getRetryEnabled());
    root.setLong(RETRY_F, msg.getRetry());
    root.setLong(TIMEREMAINING_F, msg.getTimeRemaining());
    root.setLong(TRACELEVEL_F, traceLevel);
    root.setData(BLOB_F, payload);
    byte[] serializedSlime = BinaryFormat.encode(slime);
    Compressor.Compression compressionResult = compressor.compress(serializedSlime);
    v.add(new Int8Value(compressionResult.type().getCode()));
    v.add(new Int32Value(compressionResult.uncompressedSize()));
    v.add(new DataValue(compressionResult.data()));
    return req;
}
Also used : DataValue(com.yahoo.jrt.DataValue) Request(com.yahoo.jrt.Request) Values(com.yahoo.jrt.Values) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value) Compressor(com.yahoo.compress.Compressor) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 4 with DataValue

use of com.yahoo.jrt.DataValue in project vespa by vespa-engine.

the class RPCSendV2 method createResponse.

@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
    ret.add(new Int8Value(CompressionType.NONE.getCode()));
    ret.add(new Int32Value(0));
    ret.add(new DataValue(new byte[0]));
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString(VERSION_F, version.toString());
    root.setDouble(RETRYDELAY_F, reply.getRetryDelay());
    root.setString(PROTOCOL_F, reply.getProtocol().toString());
    root.setData(BLOB_F, payload);
    if (reply.getTrace().getLevel() > 0) {
        root.setString(TRACE_F, reply.getTrace().getRoot().encode());
    }
    if (reply.getNumErrors() > 0) {
        Cursor array = root.setArray(ERRORS_F);
        for (int i = 0; i < reply.getNumErrors(); i++) {
            Cursor e = array.addObject();
            Error mbusE = reply.getError(i);
            e.setLong(CODE_F, mbusE.getCode());
            e.setString(MSG_F, mbusE.getMessage());
            if (mbusE.getService() != null) {
                e.setString(SERVICE_F, mbusE.getService());
            }
        }
    }
    byte[] serializedSlime = BinaryFormat.encode(slime);
    Compressor.Compression compressionResult = compressor.compress(serializedSlime);
    ret.add(new Int8Value(compressionResult.type().getCode()));
    ret.add(new Int32Value(compressionResult.uncompressedSize()));
    ret.add(new DataValue(compressionResult.data()));
}
Also used : DataValue(com.yahoo.jrt.DataValue) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value) Error(com.yahoo.messagebus.Error) Compressor(com.yahoo.compress.Compressor) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 5 with DataValue

use of com.yahoo.jrt.DataValue in project vespa by vespa-engine.

the class RpcClient method getDocsums.

@Override
public void getDocsums(List<FastHit> hits, NodeConnection node, CompressionType compression, int uncompressedLength, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
    Request request = new Request("proton.getDocsums");
    request.parameters().add(new Int8Value(compression.getCode()));
    request.parameters().add(new Int32Value(uncompressedLength));
    request.parameters().add(new DataValue(compressedSlime));
    request.setContext(hits);
    RpcNodeConnection rpcNode = ((RpcNodeConnection) node);
    rpcNode.invokeAsync(request, timeoutSeconds, new RpcResponseWaiter(rpcNode, responseReceiver));
}
Also used : DataValue(com.yahoo.jrt.DataValue) Request(com.yahoo.jrt.Request) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value)

Aggregations

DataValue (com.yahoo.jrt.DataValue)6 Int32Value (com.yahoo.jrt.Int32Value)4 Int8Value (com.yahoo.jrt.Int8Value)4 Request (com.yahoo.jrt.Request)3 Compressor (com.yahoo.compress.Compressor)2 StringValue (com.yahoo.jrt.StringValue)2 Values (com.yahoo.jrt.Values)2 Error (com.yahoo.messagebus.Error)2 Cursor (com.yahoo.slime.Cursor)2 Slime (com.yahoo.slime.Slime)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 DoubleValue (com.yahoo.jrt.DoubleValue)1 Int32Array (com.yahoo.jrt.Int32Array)1 Int64Value (com.yahoo.jrt.Int64Value)1 StringArray (com.yahoo.jrt.StringArray)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1