disruptor怎么用 ,demo引进总是报错

Muching小冰块 发布于 2016/12/12 17:20
阅读 127
收藏 0

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


import com.lmax.disruptor.ExceptionHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.Sequence;
import com.lmax.disruptor.SequenceBarrier;
import com.lmax.disruptor.SleepingWaitStrategy;
import com.lmax.disruptor.WorkerPool;


public class DisruptorTest {  
 
    public static void main(String[] args) throws InterruptedException {  
        //创建一个RingBuffer对象  
        RingBuffer<IntEvent> ringBuffer = new RingBuffer<IntEvent>(IntEvent.INT_ENEVT_FACTORY,  new SingleThreadedClaimStrategy(16),new SleepingWaitStrategy());  
  
        SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();  
        IntEventProducer[] producers = new IntEventProducer[1];  
        for (int i = 0; i < producers.length; i++) {  
            producers[i] = new IntEventProducer();  
        }  
        WorkerPool<IntEvent> crawler = new WorkerPool<IntEvent>(ringBuffer,  sequenceBarrier,new IntEventExceptionHandler(),producers);  
        SequenceBarrier sb = ringBuffer.newBarrier(crawler.getWorkerSequences());  
        IntEventProcessor[] processors = new IntEventProcessor[1];  
        for (int i = 0; i < processors.length; i++) {  
            processors[i] = new IntEventProcessor();  
        }  
  
        WorkerPool<IntEvent> applier = new WorkerPool<IntEvent>(ringBuffer,sb,new IntEventExceptionHandler(),processors);  
        List<Sequence> gatingSequences = new ArrayList<Sequence>();  
        for(Sequence s : crawler.getWorkerSequences()) {  
            gatingSequences.add(s);  
        }  
        for(Sequence s : applier.getWorkerSequences()) {  
            gatingSequences.add(s);  
        }  
        ringBuffer.setGatingSequences(gatingSequences.toArray(new Sequence[gatingSequences.size()]));  
        ThreadPoolExecutor executor = new ThreadPoolExecutor(7,7,10,TimeUnit.MINUTES,new LinkedBlockingQueue<Runnable>(5));  
        crawler.start(executor);  
        applier.start(executor);  
  
        while (true) {  
            Thread.sleep(1000);  
            long lastSeq = ringBuffer.next();  
            ringBuffer.publish(lastSeq);  
        }  
    }  
}  
  
class IntEventExceptionHandler implements ExceptionHandler {  
    public void handleEventException(Throwable ex, long sequence, Object event) {}  
    public void handleOnStartException(Throwable ex) {}  
    public void handleOnShutdownException(Throwable ex) {}  

}  红色处报错,第一个类引不进来


加载中
返回顶部
顶部