package com.kiisoo.ic.common;

import com.lmax.disruptor.RingBuffer;

/**
 *  消息生产者
 * Created by hc on 2019/10/22
 */
public class MsgEventProducer {

    private final RingBuffer<MsgEvent> ringBuffer;

    public MsgEventProducer(RingBuffer<MsgEvent> ringBuffer){
        this.ringBuffer = ringBuffer;
    }

    public void onData(DisruptorDataI dataMsg){
        long sequence = ringBuffer.next();
        try{
            MsgEvent event = ringBuffer.get(sequence);
            event.setData(dataMsg);
        }finally{
            ringBuffer.publish(sequence);
        }
    }
}