本文整理汇总了Java中com.lmax.disruptor.dsl.Disruptor.handleEventsWithWorkerPool方法的典型用法代码示例。如果您正苦于以下问题:Java Disruptor.handleEventsWithWorkerPool方法的具体用法?Java Disruptor.handleEventsWithWorkerPool怎么用?Java Disruptor.handleEventsWithWorkerPool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.dsl.Disruptor
的用法示例。
在下文中一共展示了Disruptor.handleEventsWithWorkerPool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: firstPassDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@Provides
@Singleton
@Named("firstPassDisruptor")
public Disruptor<TwoPhaseEvent<Void>> firstPassDisruptor(
Provider<WorkHandler<TwoPhaseEvent<Void>>> statisticsHandlerProvider) {
Disruptor<TwoPhaseEvent<Void>> disruptor = new Disruptor<>(
TwoPhaseEvent.factory(() -> null),
options.ringSize(), threadsProvider,
ProducerType.SINGLE, new SleepingWaitStrategy());
WorkHandler<TwoPhaseEvent<Void>>[] parsers = new WorkHandler[options.threads()];
for (int i = 0; i < options.threads(); i++) {
parsers[i] = statisticsHandlerProvider.get();
}
disruptor.handleExceptionsWith(new FatalExceptionHandler());
disruptor.handleEventsWithWorkerPool(parsers);
return disruptor;
}
示例2: handleEventsWithWorkerPool
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* add some handler to worker pool of the disruptor
*
* @param name
* @param handler
*/
public void handleEventsWithWorkerPool(String name, WorkHandler<DisruptorEvent<ProcessData>>... handler) {
Disruptor disruptor = DISRUPTOR_MAP.get(name);
AssertUtil.canNotEmpty(disruptor, "the disruptor is not exist!name:" + name);
disruptor.handleEventsWithWorkerPool(handler);
}
示例3: initNormalChannel
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* 初始化正常管道,任何情况下都会有
*
* @param pool 线程池
*/
private void initNormalChannel(ExecutorService pool) {
Disruptor<ElectronsHolder> normalDis = new Disruptor<>(ElectronsHolder::new, conf.getCircuitLen(), pool, ProducerType.MULTI, new LiteBlockingWaitStrategy());
WorkHandler[] workHandlers = new WorkHandler[conf.getCircuitNum()];
Arrays.fill(workHandlers, (WorkHandler<ElectronsHolder>) electronsHolder -> electronsHolder.handle());
normalDis.handleEventsWithWorkerPool(workHandlers);
normalDis.handleExceptionsWith(new ElecExceptionHandler("Normal Disruptor"));
//初始化channel
Channel normalChannel = new NormalChannel(normalDis);
//配置限流相关
normalChannel.confLimitRate(conf.isLimitRate(), conf.getPermitsPerSecond(), conf.isWarmup(), conf.getWarmupPeriod(), conf.getWarmPeriodUnit());
channelMap.put(NORMAL_CHANNEL_KEY, normalChannel);
}
示例4: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
final Logger log=LoggerFactory.getLogger("");
// Executor that will be used to construct new threads for consumers
Executor executor = new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),new NamedThreadFactory("disruptor"));
// 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
final Disruptor<LongEvent<Runnable>> disruptor = new Disruptor<>(factory, bufferSize, executor);
//注册消费者
// Connect the handler
// disruptor.handleEventsWith(new LongEventHandler("消费者A"),new LongEventHandler("消费者B"));
disruptor.handleEventsWithWorkerPool(new LongEventWorkHandler("消费者C"),new LongEventWorkHandler("消费者D"));
// Start the Disruptor, starts all threads running
disruptor.start();
final AtomicLong seq=new AtomicLong();
//生产者1
new Thread(new Runnable() {
@Override
public void run() {
// Get the ring buffer from the Disruptor to be used for publishing.
RingBuffer<LongEvent<Runnable>> ringBuffer = disruptor.getRingBuffer();
LongEventProducer producer = new LongEventProducer(ringBuffer);
for (long l = 0; true; l++)
{
producer.publish(new Task("task:"+seq.incrementAndGet()));
try {
Thread.sleep(RandomUtils.nextInt(1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}