tailer.nextIndex()

86 views
Skip to first unread message

Deepesh Mehta

unread,
Dec 9, 2016, 8:52:14 AM12/9/16
to Chronicle
Hi

We currently use CQ Version 3 and trying to migrate to CQ Version 4. I have noticed that tailer.nextIndex() method is no longer supported.
This was extremely useful method for us to navigate the queue for presence of more data without actually reading the data.

I see in CQ Version 4 you can set the direction of the navigation using TailerDirection but which method will be called to navigate the queue?

Thanks & Regards
Deepesh Mehta

Peter Lawrey

unread,
Dec 9, 2016, 9:20:18 AM12/9/16
to java-ch...@googlegroups.com
Hi. 
   How is this used? Why don't you want to read the excerpt if it is there?
  We could ado a method to do this but first I would like to understand what it is used for.

Best Regards, Peter. 

--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicle+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deepesh Mehta

unread,
Dec 9, 2016, 11:23:22 AM12/9/16
to Chronicle
Hi Peter

We have use cases where in client wants to iterate the CQ from last known valid index.

In that situation we run a loop on presence of tailer.nextIndex() which returns back true if more data is present and also changes the tailer to point to next valid index.

During cycle roll over which by default was daily in Vanilla CQ this method proved very efficient instead of incrementing index by 1 and checking if it is valid.

 Something like below code.


protected static void searchForwards(Visitor visitor, long indexStart,

ExcerptTailer tailer) {

boolean keepGoing = true;

long index = AtsReadWriteUtil.findFirstDataAfterIndexStart(tailer,

indexStart);

if (index > NOT_FOUND) {

keepGoing = visitor.visit(index, tailer);

}

while (tailer.nextIndex() && keepGoing) {

keepGoing = visitor.visit(tailer.index(), tailer);

}

}

To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.

Peter Lawrey

unread,
Dec 9, 2016, 1:19:50 PM12/9/16
to java-ch...@googlegroups.com
Hi,
   You can now use the ExcerptTailer.toEnd() method to wind to the end of the queue. (And toStart to wind to the start if you need to) If you change the direction to BACKWARD you can read backwards from the end.

Regards,
   Peter.

To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicle+unsubscribe@googlegroups.com.

Deepesh Mehta

unread,
Dec 12, 2016, 6:05:41 AM12/12/16
to Chronicle
Hi Peter

Post setting of direction which method will allow me to move the tailer to read the index (backward or forward)? . Will by calling index() method on tailer move the index to its next or previous value based on direction?

Thanks & Regards
Deepesh Mehta

Rob Austin

unread,
Dec 12, 2016, 6:39:26 AM12/12/16
to java-ch...@googlegroups.com

this will read the next document based on direction, 
try (DocumentContext dc = tailer.readingDocument()) {

}
please look at the test cases, net.openhft.chronicle.queue.impl.single.SingleChronicleQueueTest for further examples

Peter Lawrey

unread,
Dec 12, 2016, 11:08:28 AM12/12/16
to java-ch...@googlegroups.com
When you call index(N) the next message you read should N regardless of the direction of reading.

To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicle+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicle+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages