本文整理匯總了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();
}