Search in sources :

Example 16 with EmptyReply

use of com.yahoo.messagebus.EmptyReply 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 17 with EmptyReply

use of com.yahoo.messagebus.EmptyReply 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 18 with EmptyReply

use of com.yahoo.messagebus.EmptyReply 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 19 with EmptyReply

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

the class CustomPolicy method merge.

public void merge(RoutingContext context) {
    List<String> lst = new ArrayList<String>();
    Reply ret = new EmptyReply();
    for (RoutingNodeIterator it = context.getChildIterator(); it.isValid(); it.next()) {
        lst.add(it.getRoute().toString());
        Reply reply = it.getReplyRef();
        for (int i = 0; i < reply.getNumErrors(); ++i) {
            ret.addError(reply.getError(i));
        }
    }
    context.setReply(ret);
    context.trace(1, "Merged " + lst + ".");
}
Also used : RoutingNodeIterator(com.yahoo.messagebus.routing.RoutingNodeIterator) ArrayList(java.util.ArrayList) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 20 with EmptyReply

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

the class RoundRobinPolicy method select.

// Inherit doc from RoutingPolicy.
public void select(RoutingContext ctx) {
    Hop hop = getRecipient(ctx);
    if (hop != null) {
        Route route = new Route(ctx.getRoute());
        route.setHop(0, hop);
        ctx.addChild(route);
    } else {
        Reply reply = new EmptyReply();
        reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, "None of the configured recipients are currently available."));
        ctx.setReply(reply);
    }
}
Also used : Hop(com.yahoo.messagebus.routing.Hop) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Route(com.yahoo.messagebus.routing.Route) EmptyReply(com.yahoo.messagebus.EmptyReply)

Aggregations

EmptyReply (com.yahoo.messagebus.EmptyReply)21 Reply (com.yahoo.messagebus.Reply)15 Error (com.yahoo.messagebus.Error)8 Test (org.junit.Test)3 RouteMetricSet (com.yahoo.clientmetrics.RouteMetricSet)2 Version (com.yahoo.component.Version)2 Response (com.yahoo.jdisc.Response)2 TestDriver (com.yahoo.jdisc.test.TestDriver)2 Message (com.yahoo.messagebus.Message)2 Hop (com.yahoo.messagebus.routing.Hop)2 Route (com.yahoo.messagebus.routing.Route)2 RoutingNode (com.yahoo.messagebus.routing.RoutingNode)2 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)2 Utf8Array (com.yahoo.text.Utf8Array)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 CompressionType (com.yahoo.compress.CompressionType)1 DocumentIgnoredReply (com.yahoo.documentapi.messagebus.protocol.DocumentIgnoredReply)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)1