package com.cbooy.cakes.disruptor.simple;

import com.lmax.disruptor.YieldingWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * Created by haoc.
 */
public class Main {
    public static void main(String[] args) {
        ThreadFactory threadFactory = Executors.defaultThreadFactory();

        Disruptor<UserEvent> disruptor = new Disruptor<>(new UserEventFactory(), 1024, threadFactory, ProducerType.SINGLE, new YieldingWaitStrategy());

        disruptor.handleEventsWith(new UserEventConsumer());

        disruptor.start();

        new UserEventProducer(disruptor.getRingBuffer()).doProcess();

        disruptor.shutdown();
    }
}