package com.xplus.commons.thread.disruptor.getting.started;

import java.nio.ByteBuffer;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;

public class LongEventMain {

  public static void main(String[] args) throws InterruptedException {

    // 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<LongEvent>(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);
      Thread.sleep(1000);
    }
    
  }
  
}

@@ -118,25 +118,27 @@
 Executor
-;
+s;%0A
 %0Aimport 
 java.uti
@@ -133,40 +133,86 @@
 ort 
-java.util.concurrent.Executors;%0A
+com.lmax.disruptor.RingBuffer;%0Aimport com.lmax.disruptor.YieldingWaitStrategy;
 %0Aimp
@@ -230,33 +230,36 @@
 x.disruptor.
-RingBuffe
+dsl.Disrupto
 r;%0Aimport co
@@ -279,25 +279,28 @@
 tor.dsl.
-Disruptor
+ProducerType
 ;%0A%0Apubli
@@ -400,139 +400,8 @@
  %7B%0A%0A
-    // Executor that will be used to construct new threads for consumers%0A    Executor executor = Executors.newCachedThreadPool();%0A%0A
     
@@ -717,16 +717,100 @@
     
-e
+E
 xecutor
+s.defaultThreadFactory(), //%0A        ProducerType.SINGLE, new YieldingWaitStrategy()
 );%0A%0A
@@ -887,18 +887,63 @@
 tHandler
-()
+%5B%5D %7B //%0A        new LongEventHandler() //%0A    %7D
 );%0A%0A    
@@ -1391,18 +1391,12 @@
   %7D%0A
-    
 %0A  %7D%0A
-  
 %0A%7D%0A

解决warning问题。