1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| public class LongEventMain {
public static void main(String[] args) { // Executor that will be used to construct new threads for consumers Executor executor = Executors.newCachedThreadPool();
// The factory for the event LongEventFactory factory = new LongEventFactory();
// Specify the size of the ring buffer, must be power of 2. int bufferSize = 1024;
// Construct the Disruptor Disruptor<LongEvent> disruptor = new Disruptor<>(factory, bufferSize, executor);
// Connect the handler disruptor.handleEventsWith(new LongEventHandler());
// Start the Disruptor, starts all threads running disruptor.start();
// Get the ring buffer from the Disruptor to be used for publishing. RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();
LongEventProducer producer = new LongEventProducer(ringBuffer);
ByteBuffer bb = ByteBuffer.allocate(8); for (long l = 0; true; l++) { bb.putLong(0, l); producer.onData(bb); } } }
|