package com.bcxin.identify.components.ringbuffers;

import com.bcxin.identify.components.ringbuffers.events.ObjectEvent;
import com.lmax.disruptor.RingBuffer;

public class RingBufferProducer {
    private final RingBuffer<ObjectEvent<?>> ringBuffer;

    public RingBufferProducer(RingBuffer<ObjectEvent<?>> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public <T> void publish(T data) {
        long sequence = ringBuffer.next();
        ObjectEvent ringBufferEvent = ringBuffer.get(sequence);
        ringBufferEvent.setData(data);

        ringBuffer.publish(sequence);
    }
}
