use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class MbusRequestHandlerTestCase method requireThatHandlerCanRespondInOtherThread.
@Test
public void requireThatHandlerCanRespondInOtherThread() throws Exception {
TestDriver driver = newTestDriver(ThreadedReplier.INSTANCE);
Response response = dispatchMessage(driver, new SimpleMessage("msg")).get(60, TimeUnit.SECONDS);
assertTrue(response instanceof MbusResponse);
assertEquals(Response.Status.OK, response.getStatus());
Reply reply = ((MbusResponse) response).getReply();
assertTrue(reply instanceof EmptyReply);
assertFalse(reply.hasErrors());
assertTrue(driver.close());
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCSend method send.
@Override
public final void send(RoutingNode recipient, Version version, byte[] payload, long timeRemaining) {
SendContext ctx = new SendContext(recipient, timeRemaining);
RPCServiceAddress address = (RPCServiceAddress) recipient.getServiceAddress();
Message msg = recipient.getMessage();
Route route = new Route(recipient.getRoute());
Hop hop = route.removeHop(0);
Request req = encodeRequest(version, route, address, msg, timeRemaining, payload, ctx.trace.getLevel());
if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Sending message (version " + version + ") from " + clientIdent + " to '" + address.getServiceName() + "' with " + ctx.timeout + " seconds timeout.");
}
if (hop.getIgnoreResult()) {
address.getTarget().getJRTTarget().invokeVoid(req);
if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Not waiting for a reply from '" + address.getServiceName() + "'.");
}
Reply reply = new EmptyReply();
reply.getTrace().swap(ctx.trace);
net.getOwner().deliverReply(reply, recipient);
} else {
req.setContext(ctx);
address.getTarget().getJRTTarget().invokeAsync(req, ctx.timeout, this);
}
// allow garbage collection of request parameters
req.discardParameters();
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCSend method doInvoke.
private void doInvoke(Request request) {
Params p = toParams(request.parameters());
// allow garbage collection of request parameters
request.discardParameters();
// Make sure that the owner understands the protocol.
Protocol protocol = net.getOwner().getProtocol(p.protocolName);
if (protocol == null) {
replyError(request, p.version, p.traceLevel, new Error(ErrorCode.UNKNOWN_PROTOCOL, "Protocol '" + p.protocolName + "' is not known by " + serverIdent + "."));
return;
}
Routable routable = protocol.decode(p.version, p.payload);
if (routable == null) {
replyError(request, p.version, p.traceLevel, new Error(ErrorCode.DECODE_ERROR, "Protocol '" + protocol.getName() + "' failed to decode routable."));
return;
}
if (routable instanceof Reply) {
replyError(request, p.version, p.traceLevel, new Error(ErrorCode.DECODE_ERROR, "Payload decoded to a reply when expecting a message."));
return;
}
Message msg = (Message) routable;
if (p.route != null && p.route.length() > 0) {
msg.setRoute(net.getRoute(p.route));
}
msg.setContext(new ReplyContext(request, p.version));
msg.pushHandler(this);
msg.setRetryEnabled(p.retryEnabled);
msg.setRetry(p.retry);
msg.setTimeReceivedNow();
msg.setTimeRemaining(p.timeRemaining);
msg.getTrace().setLevel(p.traceLevel);
if (msg.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) {
msg.getTrace().trace(TraceLevel.SEND_RECEIVE, "Message (type " + msg.getType() + ") received at " + serverIdent + " for session '" + p.session + "'.");
}
net.getOwner().deliverMessage(msg, p.session);
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCSendV2 method createReply.
@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
CompressionType compression = CompressionType.valueOf(ret.get(3).asInt8());
byte[] slimeBytes = compressor.decompress(ret.get(5).asData(), compression, ret.get(4).asInt32());
Slime slime = BinaryFormat.decode(slimeBytes);
Inspector root = slime.get();
Version version = new Version(root.field(VERSION_F).asString());
byte[] payload = root.field(BLOB_F).asData();
// Make sure that the owner understands the protocol.
Reply reply = null;
Error error = null;
if (payload.length > 0) {
Object retval = decode(new Utf8Array(root.field(PROTOCOL_F).asUtf8()), version, payload);
if (retval instanceof Reply) {
reply = (Reply) retval;
} else {
error = (Error) retval;
}
}
if (reply == null) {
reply = new EmptyReply();
}
if (error != null) {
reply.addError(error);
}
reply.setRetryDelay(root.field(RETRYDELAY_F).asDouble());
Inspector errors = root.field(ERRORS_F);
for (int i = 0; i < errors.entries(); i++) {
Inspector e = errors.entry(i);
String service = e.field(SERVICE_F).asString();
reply.addError(new Error((int) e.field(CODE_F).asLong(), e.field(MSG_F).asString(), (service != null && service.length() > 0) ? service : serviceName));
}
if (trace.getLevel() > 0) {
trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
}
return reply;
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RoutingNodeIterator method removeReply.
/**
* Removes and returns the reply of the current child. This is the correct way of reusing a reply of a child node,
* the {@link #getReplyRef()} should be used when just inspecting a child reply.
*
* @return The reply.
*/
public Reply removeReply() {
Reply ret = entry.getReply();
ret.getTrace().setLevel(entry.getTrace().getLevel());
ret.getTrace().swap(entry.getTrace());
entry.setReply(null);
return ret;
}
Aggregations