0

When reading a document from chronicle queue, what is the best way to skip the current document when I am not interested in it?

I.e. given the following code, what do I put instead of the comment?

try (DocumentContext context = getTailer().readingDocument(false)) {
    if (context.isPresent()) {
        // How do I skip the document here?
    }
}
Jochen
  • 7,270
  • 5
  • 24
  • 32

1 Answers1

2

Well I'd assume you at least need to put some code that will prove that you are indeed not interested in this particular document. Otherwise - you just put nothing, when the document context is closed - the document is skipped.

However if you know that you just read a document which tells you that next document should be skipped, and you feel adventurous, you can do this:

@Test
public void testSkip() {
    final SingleChronicleQueue q = SingleChronicleQueueBuilder.binary("test").build();

    final ExcerptAppender appender = q.acquireAppender();
    appender.writeText("Hello");
    appender.writeText("Cruel");
    appender.writeText("World");

    final ExcerptTailer tailer = q.createTailer().toStart();

    boolean skip = false;
    while (true) {
        if (skip)
            tailer.moveToIndex(tailer.index() + 1);
        final String text = tailer.readText();
        if (text == null)
            break;
        System.err.println(text);
        skip = text.equals("Hello");
    }
}
Dmitry Pisklov
  • 1,196
  • 1
  • 6
  • 16