use of com.yahoo.messagebus.EmptyReply 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.EmptyReply 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.EmptyReply 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.EmptyReply in project vespa by vespa-engine.
the class CustomPolicy method merge.
public void merge(RoutingContext context) {
List<String> lst = new ArrayList<String>();
Reply ret = new EmptyReply();
for (RoutingNodeIterator it = context.getChildIterator(); it.isValid(); it.next()) {
lst.add(it.getRoute().toString());
Reply reply = it.getReplyRef();
for (int i = 0; i < reply.getNumErrors(); ++i) {
ret.addError(reply.getError(i));
}
}
context.setReply(ret);
context.trace(1, "Merged " + lst + ".");
}
use of com.yahoo.messagebus.EmptyReply in project vespa by vespa-engine.
the class RoundRobinPolicy method select.
// Inherit doc from RoutingPolicy.
public void select(RoutingContext ctx) {
Hop hop = getRecipient(ctx);
if (hop != null) {
Route route = new Route(ctx.getRoute());
route.setHop(0, hop);
ctx.addChild(route);
} else {
Reply reply = new EmptyReply();
reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, "None of the configured recipients are currently available."));
ctx.setReply(reply);
}
}
Aggregations