3

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?

  • Likely not the best way...but I used Long IndexOfNextCycle = RollCycle.toIndex(queue.nextCycle(tailer.cycle(),TailerDirection.FORWARD), 0); this found the first index of the next cycle.... Then I reversed the tailer and went back and read another value. This would give me the last index of the cycle. – InspectorNel Nov 06 '19 at 23:32

1 Answers1

4
  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);

Rob Austin
  • 620
  • 3
  • 5
  • 1
    Thanks for the help Rob. I initially figured out the first way, but I think the second is much more succinct. Going to update. – InspectorNel Nov 07 '19 at 16:46