Search code examples
chroniclechronicle-queue

Chronicle Queue - Recieve last index of cycle


I am trying to use chronicle queue to determine the last index of the current cycle. I will use the start index and the last index to do a final check before deleting the single cq4 for the cycle.

I would like to be able to find the last index of a cycle without iterating through every record. Is this possible?

Or

Is there a way to move the tailer to the next index without actually reading the record, and would it work with rolling over multiple cycles?


Solution

    1. you could read backwards from the end and look at the cycle number until you are at the last record of your target cycle. Once you are at your target cycle look at the index and this will tell you the last index of this cycle.

    or

    1. you could use countExcerpts

    net.openhft.chronicle.queue.impl.single.SingleChronicleQueue#countExcerpts(fromIndex,toIndex)

    where:

    fromIndex = the first index of the target cycle

    toIndex= the first index of the next cycle

    This will give you the number of messages in the target cycle, you can consider this to be the sequenceNumber, you then just have to work out its index using queue.rollCycle().toIndex(targetCycle, sequenceNumber);