use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCNetwork method replyError.
/**
* Deliver an error reply to the recipients of a {@link SendContext} in a way that avoids entanglement.
*
* @param ctx The send context that contains the recipient data.
* @param errCode The error code to return.
* @param errMsg The error string to return.
*/
private void replyError(SendContext ctx, int errCode, String errMsg) {
for (RoutingNode recipient : ctx.recipients) {
Reply reply = new EmptyReply();
reply.getTrace().setLevel(ctx.traceLevel);
reply.addError(new Error(errCode, errMsg));
owner.deliverReply(reply, recipient);
}
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCSend method doRequestDone.
private void doRequestDone(Request req) {
SendContext ctx = (SendContext) req.getContext();
String serviceName = ((RPCServiceAddress) ctx.recipient.getServiceAddress()).getServiceName();
Reply reply = null;
Error error = null;
if (!req.checkReturnTypes(getReturnSpec())) {
// Map all known JRT errors to the appropriate message bus error.
reply = new EmptyReply();
switch(req.errorCode()) {
case com.yahoo.jrt.ErrorCode.TIMEOUT:
error = new Error(ErrorCode.TIMEOUT, "A timeout occured while waiting for '" + serviceName + "' (" + ctx.timeout + " seconds expired); " + req.errorMessage());
break;
case com.yahoo.jrt.ErrorCode.CONNECTION:
error = new Error(ErrorCode.CONNECTION_ERROR, "A connection error occured for '" + serviceName + "'; " + req.errorMessage());
break;
default:
error = new Error(ErrorCode.NETWORK_ERROR, "A network error occured for '" + serviceName + "'; " + req.errorMessage());
}
} else {
reply = createReply(req.returnValues(), serviceName, ctx.trace);
}
if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Reply (type " + reply.getType() + ") received at " + clientIdent + ".");
}
reply.getTrace().swap(ctx.trace);
if (error != null) {
reply.addError(error);
}
net.getOwner().deliverReply(reply, ctx.recipient);
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCSend method replyError.
/**
* Send an error reply for a given request.
*
* @param request The JRT request to reply to.
* @param version The version to serialize for.
* @param traceLevel The trace level to set in the reply.
* @param err The error to reply with.
*/
private void replyError(Request request, Version version, int traceLevel, Error err) {
Reply reply = new EmptyReply();
reply.setContext(new ReplyContext(request, version));
reply.getTrace().setLevel(traceLevel);
reply.addError(err);
handleReply(reply);
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class RPCSendV1 method createReply.
@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
Version version = new Version(ret.get(0).asUtf8Array());
double retryDelay = ret.get(1).asDouble();
int[] errorCodes = ret.get(2).asInt32Array();
String[] errorMessages = ret.get(3).asStringArray();
String[] errorServices = ret.get(4).asStringArray();
Utf8Array protocolName = ret.get(5).asUtf8Array();
byte[] payload = ret.get(6).asData();
String replyTrace = ret.get(7).asString();
// Make sure that the owner understands the protocol.
Reply reply = null;
Error error = null;
if (payload.length > 0) {
Object retval = decode(protocolName, 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(retryDelay);
for (int i = 0; i < errorCodes.length && i < errorMessages.length; i++) {
reply.addError(new Error(errorCodes[i], errorMessages[i], errorServices[i].length() > 0 ? errorServices[i] : serviceName));
}
if (trace.getLevel() > 0) {
trace.getRoot().addChild(TraceNode.decode(replyTrace));
}
return reply;
}
use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.
the class ReceptorTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
Receptor receptor = new Receptor();
assertNull(receptor.getMessage(0));
Message msg = new MyMessage();
receptor.handleMessage(msg);
assertSame(msg, receptor.getMessage(0));
Reply reply = new MyReply();
receptor.handleReply(reply);
assertSame(reply, receptor.getReply(0));
}
Aggregations