Search in sources :

Example 11 with PutDocumentMessage

use of com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage in project vespa by vespa-engine.

the class DummyReceiver method handleMessage.

public void handleMessage(Message message) {
    messageCount++;
    if (silentNum == 0) {
        System.out.println("Received message " + message + ". Received " + messageCount + " messages so far. In queue size " + queue.size());
        if (verbose) {
            if (message instanceof PutDocumentMessage) {
                System.out.println("  Document:\n" + ((PutDocumentMessage) message).getDocumentPut().getDocument().toXML("  "));
            } else if (message instanceof RemoveDocumentMessage) {
                System.out.println("  Document id: " + ((RemoveDocumentMessage) message).getDocumentId());
            } else if (message instanceof UpdateDocumentMessage) {
                System.out.println("  Update:\n  " + ((UpdateDocumentMessage) message).getDocumentUpdate().toString());
            }
        }
    } else {
        if ((messageCount % silentNum) == 0) {
            System.out.println("Received " + messageCount + " messages so far. In queue size " + queue.size());
        }
    }
    EmptyReply reply = new EmptyReply();
    message.swapState(reply);
    if (!instant) {
        try {
            executor.execute(new Task(reply));
        } catch (RejectedExecutionException e) {
            reply.addError(new Error(ErrorCode.SESSION_BUSY, "Session " + name + "/default is busy"));
            session.reply(reply);
        }
    } else {
        session.reply(reply);
    }
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Error(com.yahoo.messagebus.Error) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 12 with PutDocumentMessage

use of com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage in project vespa by vespa-engine.

the class DocumentProcessingHandlerAllMessageTypesTestCase method put.

private void put() throws InterruptedException {
    Document document = new Document(getType(), "doc:baz:foo");
    document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
    PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));
    assertTrue(sendMessage(FOOBAR, message));
    Message result = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(result);
    remoteServer.ackMessage(result);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat(result, instanceOf(PutDocumentMessage.class));
    PutDocumentMessage outputMsg = (PutDocumentMessage) result;
    assertThat(((StringFieldValue) outputMsg.getDocumentPut().getDocument().getFieldValue("blahblah")).getString(), is("THIS IS A TEST."));
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) BatchDocumentUpdateMessage(com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Reply(com.yahoo.messagebus.Reply)

Example 13 with PutDocumentMessage

use of com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage in project vespa by vespa-engine.

the class DocumentProcessingHandlerForkTestCase method createPutDocumentMessage.

protected PutDocumentMessage createPutDocumentMessage() {
    Document document = new Document(getType(), "doc:baz:bar");
    document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
    return new PutDocumentMessage(new DocumentPut(document));
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue)

Example 14 with PutDocumentMessage

use of com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage in project vespa by vespa-engine.

the class DocumentProcessingHandlerBasicTestCase method testPut.

@Test
public void testPut() throws InterruptedException {
    Document document = new Document(getType(), "doc:yalla:balla");
    document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
    PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));
    assertTrue(sendMessage("foobar", message));
    Message msg = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(msg);
    remoteServer.ackMessage(msg);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat((msg instanceof PutDocumentMessage), is(true));
    PutDocumentMessage put = (PutDocumentMessage) msg;
    Document outDoc = put.getDocumentPut().getDocument();
    assertThat(document, equalTo(outDoc));
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Message(com.yahoo.messagebus.Message) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) Reply(com.yahoo.messagebus.Reply) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 15 with PutDocumentMessage

use of com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage in project vespa by vespa-engine.

the class MessageBusSyncSession method put.

@Override
public void put(DocumentPut documentPut, DocumentProtocol.Priority priority) {
    PutDocumentMessage msg = new PutDocumentMessage(documentPut);
    msg.setPriority(priority);
    syncSendPutDocumentMessage(msg);
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)

Aggregations

PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)16 DocumentPut (com.yahoo.document.DocumentPut)5 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)5 Message (com.yahoo.messagebus.Message)5 Test (org.junit.Test)5 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Reply (com.yahoo.messagebus.Reply)3 Document (com.yahoo.document.Document)2 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)2 Splitter (com.google.common.base.Splitter)1 Tuple2 (com.yahoo.collections.Tuple2)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 SessionCache (com.yahoo.container.jdisc.messagebus.SessionCache)1 AccessLog (com.yahoo.container.logging.AccessLog)1 DataType (com.yahoo.document.DataType)1 DocumentOperation (com.yahoo.document.DocumentOperation)1 DocumentType (com.yahoo.document.DocumentType)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1