Class TickRingBuffer
java.lang.Object
com.quantfinlib.marketdata.TickRingBuffer
Zero-allocation single-producer / single-consumer ring buffer for market
data ticks, in the style of the LMAX Disruptor:
- Preallocated primitive slots — ticks live in parallel
int[]/double[]/long[]arrays; nothing is allocated per tick on either side, so the steady-state GC load is zero. - Cache-line-padded sequences — head and tail counters are padded to avoid false sharing between the producer and consumer cores.
- Acquire/release ordering — slot writes are published with a single release store of the tail; no CAS, no locks on the hot path.
- Sequence caching — each side caches the other's sequence and only re-reads the volatile counter when it appears blocked, removing most cross-core traffic.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()intdrainTo(TickListener sink, int limit) Consumer side; single consumer thread only.booleanisEmpty()booleanpublish(int symbolId, double price, double size, long timestampNanos) Producer side; single producer thread only.
-
Constructor Details
-
TickRingBuffer
public TickRingBuffer(int requestedCapacity) - Parameters:
requestedCapacity- rounded up to the next power of two
-
-
Method Details
-
publish
public boolean publish(int symbolId, double price, double size, long timestampNanos) Producer side; single producer thread only. Returns false when full — the caller chooses the backpressure policy (spin, drop, or count). -
drainTo
Consumer side; single consumer thread only. Drains up tolimitticks into the sink and returns how many were delivered. -
isEmpty
public boolean isEmpty() -
capacity
public int capacity()
-