use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class RoutingTestCase method requireThatRetryCanBeDisabled.
@Test
public void requireThatRetryCanBeDisabled() {
retryPolicy.setEnabled(false);
assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
Reply reply = new EmptyReply();
reply.swapState(msg);
reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err"));
dstSession.reply(reply);
assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
System.out.println(reply.getTrace());
assertEquals(1, reply.getNumErrors());
assertEquals(ErrorCode.APP_TRANSIENT_ERROR, reply.getError(0).getCode());
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class RoutingTestCase method requireThatTransientErrorsAreRetried.
@Test
public void requireThatTransientErrorsAreRetried() {
assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
Reply reply = new EmptyReply();
reply.swapState(msg);
reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err1"));
dstSession.reply(reply);
assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
reply = new EmptyReply();
reply.swapState(msg);
reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err2"));
dstSession.reply(reply);
assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
dstSession.acknowledge(msg);
assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
System.out.println(reply.getTrace());
assertFalse(reply.hasErrors());
assertTrace(Arrays.asList("[APP_TRANSIENT_ERROR @ localhost]: err1", "-[APP_TRANSIENT_ERROR @ localhost]: err1", "[APP_TRANSIENT_ERROR @ localhost]: err2", "-[APP_TRANSIENT_ERROR @ localhost]: err2"), reply.getTrace());
}
use of com.yahoo.messagebus.Error 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.Error in project vespa by vespa-engine.
the class RPCSend method handleReply.
@Override
public final void handleReply(Reply reply) {
ReplyContext ctx = (ReplyContext) reply.getContext();
reply.setContext(null);
// Add trace information.
if (reply.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) {
reply.getTrace().trace(TraceLevel.SEND_RECEIVE, "Sending reply (version " + ctx.version + ") from " + serverIdent + ".");
}
// Encode and return the reply through the RPC request.
byte[] payload = new byte[0];
if (reply.getType() != 0) {
Protocol protocol = net.getOwner().getProtocol(reply.getProtocol());
if (protocol != null) {
payload = protocol.encode(ctx.version, reply);
}
if (payload == null || payload.length == 0) {
reply.addError(new Error(ErrorCode.ENCODE_ERROR, "An error occured while encoding the reply."));
}
}
createResponse(ctx.request.returnValues(), reply, ctx.version, payload);
ctx.request.returnRequest();
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class RPCSendV1 method createResponse.
@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
int[] eCodes = new int[reply.getNumErrors()];
String[] eMessages = new String[reply.getNumErrors()];
String[] eServices = new String[reply.getNumErrors()];
for (int i = 0; i < reply.getNumErrors(); ++i) {
Error error = reply.getError(i);
eCodes[i] = error.getCode();
eMessages[i] = error.getMessage();
eServices[i] = error.getService() != null ? error.getService() : "";
}
ret.add(new StringValue(version.toString()));
ret.add(new DoubleValue(reply.getRetryDelay()));
ret.add(new Int32Array(eCodes));
ret.add(new StringArray(eMessages));
ret.add(new StringArray(eServices));
ret.add(new StringValue(reply.getProtocol()));
ret.add(new DataValue(payload));
ret.add(new StringValue(reply.getTrace().getRoot() != null ? reply.getTrace().getRoot().encode() : ""));
}
Aggregations