public VanillaChronicleQueueBuilder cycleLength(int cycleLength, boolean check) { if (check && cycleLength < VanillaChronicle.MIN_CYCLE_LENGTH) { throw new IllegalArgumentException( "Cycle length can't be less than " + VanillaChronicle.MIN_CYCLE_LENGTH + " ms!"); } this.cycleLength = cycleLength; entriesPerCycle(VanillaChronicle.Cycle.forLength(this.cycleLength).entries()); return this; }
VanillaChronicle(ChronicleQueueBuilder.VanillaChronicleQueueBuilder builder) { this.builder = builder.clone(); this.lifecycleListener = this.builder.fileLifecycleListener(); this.marshallersCache = new ThreadLocal<>(); this.tailerCache = new ThreadLocal<>(); this.appenderCache = new ThreadLocal<>(); this.name = builder.path().getName(); this.dateCache = new VanillaDateCache( builder.path(), builder.cycleFormat(), builder.cycleLength(), builder.cycleTimeZone()); this.indexBlockSizeBits = Maths.intLog2(builder.indexBlockSize()); this.indexBlockSizeMask = -1 >>> -indexBlockSizeBits; this.indexBlockLongsBits = indexBlockSizeBits - 3; this.indexBlockLongsMask = indexBlockSizeMask >>> 3; this.indexCache = new VanillaIndexCache(this.builder, dateCache, indexBlockSizeBits, builder.fileLifecycleListener()); this.dataBlockSizeBits = Maths.intLog2(builder.dataBlockSize()); this.dataBlockSizeMask = -1 >>> -dataBlockSizeBits; this.dataCache = new VanillaDataCache(this.builder, dateCache, dataBlockSizeBits); this.entriesForCycleBits = Maths.intLog2(this.builder.entriesPerCycle()); this.entriesForCycleMask = -1L >>> -entriesForCycleBits; if (!VanillaChronicleUtils.exists(builder.path())) { builder.path().mkdirs(); } }
public boolean nextIndex() { checkNotClosed(); if (index < 0) { toStart(); if (index < 0) return false; } long nextIndex = index + 1; while (true) { boolean found = index(nextIndex); if (found) { index = nextIndex; return true; } int cycle = (int) (nextIndex / builder.entriesPerCycle()); if (cycle >= cycle()) { return false; } nextIndex = (cycle + 1) * builder.entriesPerCycle(); } }
public VanillaChronicleQueueBuilder cycle(VanillaChronicle.Cycle cycle) { cycleFormat(cycle.format()); cycleLength(cycle.length(), false); entriesPerCycle(cycle.entries()); return this; }
@NotNull public ExcerptCommon toStart() { int cycle = (int) indexCache.firstCycle(); if (cycle >= 0) { index = (cycle * builder.entriesPerCycle()) - 1; } return this; }