net.openhft.chronicle.queue.rollcycles.LegacyRollCycles Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chronicle-queue Show documentation
Show all versions of chronicle-queue Show documentation
Java library for persisted low latency messaging (Java 8+)
package net.openhft.chronicle.queue.rollcycles;
import net.openhft.chronicle.queue.RollCycle;
/**
* Old RollCycle definitions kept for historical reasons
*/
public enum LegacyRollCycles implements RollCycle {
/**
* 0x4000000 entries per minute, indexing every 16th entry
*/
MINUTELY(/*--------*/"yyyyMMdd-HHmm", 60 * 1000, 2 << 10, 16),
/**
* 0x10000000 entries per hour, indexing every 16th entry, leave as 4K and 16 for historical reasons.
*/
HOURLY(/*----------*/"yyyyMMdd-HH", 60 * 60 * 1000, 4 << 10, 16),
/**
* 0xffffffff entries per day, indexing every 64th entry, leave as 8K and 64 for historical reasons.
*/
DAILY(/*-----------*/"yyyyMMdd", 24 * 60 * 60 * 1000, 8 << 10, 64),
;
private final String format;
private final int lengthInMillis;
private final RollCycleArithmetic arithmetic;
LegacyRollCycles(String format, int lengthInMillis, int indexCount, int indexSpacing) {
this.format = format;
this.lengthInMillis = lengthInMillis;
this.arithmetic = RollCycleArithmetic.of(indexCount, indexSpacing);
}
public long maxMessagesPerCycle() {
return arithmetic.maxMessagesPerCycle();
}
@Override
public String format() {
return this.format;
}
@Override
public int lengthInMillis() {
return this.lengthInMillis;
}
/**
* @return this is the size of each index array, note: indexCount^2 is the maximum number of index queue entries.
*/
@Override
public int defaultIndexCount() {
return arithmetic.indexCount();
}
@Override
public int defaultIndexSpacing() {
return arithmetic.indexSpacing();
}
@Override
public long toIndex(int cycle, long sequenceNumber) {
return arithmetic.toIndex(cycle, sequenceNumber);
}
@Override
public long toSequenceNumber(long index) {
return arithmetic.toSequenceNumber(index);
}
@Override
public int toCycle(long index) {
return arithmetic.toCycle(index);
}
}