use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class RPCNetwork method allocServiceAddress.
@Override
public boolean allocServiceAddress(RoutingNode recipient) {
Hop hop = recipient.getRoute().getHop(0);
String service = hop.getServiceName();
Error error = resolveServiceAddress(recipient, service);
if (error == null) {
// service address resolved
return true;
}
recipient.setError(error);
// service address not resolved
return false;
}
use of com.yahoo.messagebus.Error 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.Error 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.Error 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.Error 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()));
}
Aggregations