Search in sources :

Example 31 with Reply

use of com.yahoo.messagebus.Reply 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());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) TestDriver(com.yahoo.jdisc.test.TestDriver) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Example 32 with Reply

use of com.yahoo.messagebus.Reply 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();
}
Also used : Message(com.yahoo.messagebus.Message) Hop(com.yahoo.messagebus.routing.Hop) Request(com.yahoo.jrt.Request) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Route(com.yahoo.messagebus.routing.Route) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 33 with Reply

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

Example 34 with Reply

use of com.yahoo.messagebus.Reply 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;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 35 with Reply

use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.

the class RoutingNodeIterator method removeReply.

/**
 * Removes and returns the reply of the current child. This is the correct way of reusing a reply of a child node,
 * the {@link #getReplyRef()} should be used when just inspecting a child reply.
 *
 * @return The reply.
 */
public Reply removeReply() {
    Reply ret = entry.getReply();
    ret.getTrace().setLevel(entry.getTrace().getLevel());
    ret.getTrace().swap(entry.getTrace());
    entry.setReply(null);
    return ret;
}
Also used : Reply(com.yahoo.messagebus.Reply)

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