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]));
}
}
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;
}
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;
}
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()));
}
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));
}
Aggregations