Search in sources :

Example 1 with Reply

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);
    }
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) EmptyReply(com.yahoo.messagebus.EmptyReply) Reply(com.yahoo.messagebus.Reply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 2 with Reply

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);
}
Also used : Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 3 with Reply

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);
}
Also used : Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 4 with 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;
}
Also used : Version(com.yahoo.component.Version) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 5 with 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));
}
Also used : Message(com.yahoo.messagebus.Message) Reply(com.yahoo.messagebus.Reply) Test(org.junit.Test)

Aggregations

Reply (com.yahoo.messagebus.Reply)39 EmptyReply (com.yahoo.messagebus.EmptyReply)18 Message (com.yahoo.messagebus.Message)14 Error (com.yahoo.messagebus.Error)9 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)7 Test (org.junit.Test)7 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)6 BatchDocumentUpdateMessage (com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage)5 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)5 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Response (com.yahoo.jdisc.Response)3 RoutingNode (com.yahoo.messagebus.routing.RoutingNode)3 RoutingNodeIterator (com.yahoo.messagebus.routing.RoutingNodeIterator)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 Version (com.yahoo.component.Version)2 Document (com.yahoo.document.Document)2 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)2 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)2