Search in sources :

Example 11 with Message

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

the class DocumentOperationMessageV3 method newRemoveMessage.

static DocumentOperationMessageV3 newRemoveMessage(VespaXMLFeedReader.Operation op, String operationId) {
    DocumentRemove remove = new DocumentRemove(op.getRemove());
    remove.setCondition(op.getCondition());
    Message msg = new RemoveDocumentMessage(remove);
    String id = (operationId == null) ? remove.getId().toString() : operationId;
    return new DocumentOperationMessageV3(id, msg);
}
Also used : RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) DocumentRemove(com.yahoo.document.DocumentRemove) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)

Example 12 with Message

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

the class Feeder method feed.

void feed() throws InterruptedException {
    while (true) {
        Result result;
        String operationId;
        try {
            operationId = getNextOperationId();
        } catch (IOException ioe) {
            if (log.isLoggable(LogLevel.DEBUG)) {
                log.log(LogLevel.DEBUG, Exceptions.toMessageString(ioe), ioe);
            }
            break;
        }
        // noinspection StringEquality
        if (operationId == EOF) {
            break;
        }
        Tuple2<String, Message> msg;
        try {
            msg = getNextMessage(operationId);
            setRoute(msg);
        } catch (Exception e) {
            if (log.isLoggable(LogLevel.DEBUG)) {
                log.log(LogLevel.DEBUG, Exceptions.toMessageString(e), e);
            }
            // noinspection StringEquality
            if (operationId != null) {
                // v1 always returns null, all others return something useful, or throw an exception above
                msg = newErrorMessage(operationId, e);
            } else {
                break;
            }
        }
        if (msg == null) {
            break;
        }
        setMessageParameters(msg);
        while (true) {
            try {
                msg.second.pushHandler(feedReplyHandler);
                if (settings.denyIfBusy) {
                    result = sourceSession.getResource().sendMessage(msg.second);
                } else {
                    result = sourceSession.getResource().sendMessageBlocking(msg.second);
                }
            } catch (RuntimeException e) {
                enqueue(msg.first, Exceptions.toMessageString(e), ErrorCode.ERROR, false, msg.second);
                return;
            }
            if (result.isAccepted() || result.getError().getCode() != SEND_QUEUE_FULL) {
                break;
            }
            if (settings.denyIfBusy) {
                break;
            } else {
                // This will never happen
                Thread.sleep(100);
            }
        }
        if (result.isAccepted()) {
            ++numPending;
            updateMetrics(msg.second);
            updateOpsPerSec();
            log(LogLevel.DEBUG, "Sent message successfully, document id: ", msg.first);
        } else if (!result.getError().isFatal()) {
            enqueue(msg.first, result.getError().getMessage(), ErrorCode.TRANSIENT_ERROR, false, msg.second);
            break;
        } else {
            // should probably not happen, but everybody knows stuff that
            // shouldn't happen, happens all the time
            boolean isConditionNotMet = result.getError().getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED;
            enqueue(msg.first, result.getError().getMessage(), ErrorCode.ERROR, isConditionNotMet, msg.second);
            break;
        }
    }
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Utf8String(com.yahoo.text.Utf8String) IOException(java.io.IOException) IOException(java.io.IOException) Result(com.yahoo.messagebus.Result)

Example 13 with Message

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

the class Feeder method newRemoveMessage.

private Tuple2<String, Message> newRemoveMessage(Operation op, String operationId) {
    DocumentRemove remove = new DocumentRemove(op.getRemove());
    remove.setCondition(op.getCondition());
    Message msg = new RemoveDocumentMessage(remove);
    String id = (operationId == null) ? remove.getId().toString() : operationId;
    return new Tuple2<>(id, msg);
}
Also used : RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) DocumentRemove(com.yahoo.document.DocumentRemove) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Tuple2(com.yahoo.collections.Tuple2) Utf8String(com.yahoo.text.Utf8String)

Example 14 with Message

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

the class DocumentRouteSelectorPolicy method select.

/**
 * This method runs the selector associated with the given location on the content of the message. If the selector
 * validates the location, this method returns true.
 *
 * @param context   The routing context that contains the necessary data.
 * @param routeName The candidate route whose selector to run.
 * @return Whether or not to send to the given recipient.
 */
private boolean select(RoutingContext context, String routeName) {
    if (config == null) {
        return true;
    }
    DocumentSelector selector = config.get(routeName);
    if (selector == null) {
        return true;
    }
    // Select based on message content.
    Message msg = context.getMessage();
    switch(msg.getType()) {
        case DocumentProtocol.MESSAGE_PUTDOCUMENT:
            return selector.accepts(((PutDocumentMessage) msg).getDocumentPut()) == Result.TRUE;
        case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
            return selector.accepts(((UpdateDocumentMessage) msg).getDocumentUpdate()) != Result.FALSE;
        case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
            {
                RemoveDocumentMessage removeMsg = (RemoveDocumentMessage) msg;
                if (removeMsg.getDocumentId().hasDocType()) {
                    return selector.accepts(removeMsg.getDocumentRemove()) != Result.FALSE;
                } else {
                    return true;
                }
            }
        case DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE:
            BatchDocumentUpdateMessage bdu = (BatchDocumentUpdateMessage) msg;
            for (int i = 0; i < bdu.getUpdates().size(); i++) {
                if (selector.accepts(bdu.getUpdates().get(i)) == Result.FALSE) {
                    return false;
                }
            }
            return true;
        default:
            return true;
    }
}
Also used : DocumentSelector(com.yahoo.document.select.DocumentSelector) Message(com.yahoo.messagebus.Message)

Example 15 with Message

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

the class ServerThreadingTestCase method requireThatServerIsThreadSafe.

@Test
public void requireThatServerIsThreadSafe() throws Exception {
    final LocalWire wire = new LocalWire();
    final Client client = new Client(wire);
    final Server server = new Server(wire);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        final Message msg = new SimpleMessage("foo");
        msg.setRoute(Route.parse(server.delegate.connectionSpec()));
        msg.pushHandler(client);
        assertThat(client.session.send(msg).isAccepted(), is(true));
    }
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        final Reply reply = client.replies.poll(600, TimeUnit.SECONDS);
        assertThat(reply, instanceOf(EmptyReply.class));
        assertThat(reply.hasErrors(), is(false));
    }
    assertThat(client.close(), is(true));
    assertThat(server.close(), is(true));
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Message(com.yahoo.messagebus.Message) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) EmptyReply(com.yahoo.messagebus.EmptyReply) Reply(com.yahoo.messagebus.Reply) LocalWire(com.yahoo.messagebus.network.local.LocalWire) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Aggregations

Message (com.yahoo.messagebus.Message)39 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)17 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)15 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)15 Reply (com.yahoo.messagebus.Reply)14 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)13 Test (org.junit.Test)13 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)9 Chain (com.yahoo.component.chain.Chain)7 FeedContext (com.yahoo.feedapi.FeedContext)7 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)7 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)7 Searcher (com.yahoo.search.Searcher)7 Execution (com.yahoo.search.searchchain.Execution)7 ClusterList (com.yahoo.vespaclient.ClusterList)7 Result (com.yahoo.search.Result)6 Utf8String (com.yahoo.text.Utf8String)6 BatchDocumentUpdateMessage (com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage)5 Tuple2 (com.yahoo.collections.Tuple2)4 EmptyReply (com.yahoo.messagebus.EmptyReply)4