本文整理汇总了Java中com.lmax.disruptor.dsl.Disruptor.handleExceptionsWith方法的典型用法代码示例。如果您正苦于以下问题:Java Disruptor.handleExceptionsWith方法的具体用法?Java Disruptor.handleExceptionsWith怎么用?Java Disruptor.handleExceptionsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.dsl.Disruptor
的用法示例。
在下文中一共展示了Disruptor.handleExceptionsWith方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inputDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@Provides
@Singleton
@Named("disruptor")
@SuppressWarnings("Unchecked")
protected Disruptor<TwoPhaseEvent<T>> inputDisruptor(Provider<WorkHandler<TwoPhaseEvent<T>>> workHandlerProvider,
Provider<EventHandler<TwoPhaseEvent<T>>> evenHandlerProvider) {
Disruptor<TwoPhaseEvent<T>> disruptor = new Disruptor<>(
TwoPhaseEvent.factory(outputEventFactory()),
options.ringSize(), threadsProvider,
ProducerType.SINGLE, new SleepingWaitStrategy());
WorkHandler<TwoPhaseEvent<T>>[] parsers = new WorkHandler[options.threads()];
for (int i = 0; i < options.threads(); i++) {
parsers[i] = workHandlerProvider.get();
}
disruptor.handleExceptionsWith(new FatalExceptionHandler());
disruptor.handleEventsWithWorkerPool(parsers).then(evenHandlerProvider.get());
return disruptor;
}
示例2: 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;
}
示例3: secondPassDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@Provides
@Singleton
@Named("secondPassDisruptor")
public Disruptor<TwoPhaseEvent<SparseItem>> secondPassDisruptor(
Provider<WorkHandler<TwoPhaseEvent<SparseItem>>> binningHandlerProvider,
Provider<EventHandler<TwoPhaseEvent<SparseItem>>> outputHandlerProvider) {
Disruptor<TwoPhaseEvent<SparseItem>> disruptor = new Disruptor<>(
TwoPhaseEvent.factory(SparseItem::new),
options.ringSize(), threadsProvider,
ProducerType.SINGLE, new SleepingWaitStrategy());
WorkHandler<TwoPhaseEvent<SparseItem>>[] parsers = new WorkHandler[options.threads()];
for (int i = 0; i < options.threads(); i++) {
parsers[i] = binningHandlerProvider.get();
}
disruptor.handleExceptionsWith(new FatalExceptionHandler());
disruptor.handleEventsWithWorkerPool(parsers)
.then(outputHandlerProvider.get());
return disruptor;
}
示例4: initSpecDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* 根据config初始化特殊通道
*
* @param symbol 事件
* @param listeners 对应的监听器集合
*/
private void initSpecDisruptor(String symbol, List<ElectronsListener> listeners) {
ExecutorService specPool = Executors.newFixedThreadPool(conf.getSpecCircuitNum(), new ThreadFactory() {
final AtomicInteger cursor = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "Electrons Thread (from spec channel) : thread" + cursor.incrementAndGet());
}
});
pools.add(specPool);
Disruptor<ElectronsHolder> disruptor = new Disruptor<>(ElectronsHolder::new, conf.getSpecCircuitLen(), specPool, ProducerType.MULTI, new LiteBlockingWaitStrategy());
disruptor.handleExceptionsWith(new ElecExceptionHandler("Spec Disruptor {" + symbol + "}"));
//初始化管道并放入集合中
SpecChannel specChannel = new SpecChannel(disruptor);
if (conf.isBreaker()) {
EventCountCircuitBreaker breaker = new EventCountCircuitBreaker(conf.getErrorNum(), conf.getPerUnit(), conf.getUnit(), conf.getCloseThreshold(), conf.getRest(), conf.getRestUnit());
specChannel.setBreaker(breaker);
}
//构建listener顺序
ListenerChainBuilderNew.buildChain(specChannel, listeners);
channelMap.put(SPEC_CHANNEL_PREFIX + symbol, specChannel);
}
示例5: 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);
}
示例6: buildDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Disruptor<AvroEvent> buildDisruptor() {
Disruptor<AvroEvent> disruptor = new Disruptor<>(avroEventFactory,
ringBufferSize,
consumerExecutor,
producerType,
waitStrategy);
disruptor.handleExceptionsWith(new DisruptorExceptionHandler());
disruptor.handleEventsWith(new AvroEventConsumer(avroFilename, avroSchema, rollingPolicy));
return disruptor;
}
示例7: DisruptorSbeMetricsService
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public DisruptorSbeMetricsService(
TimeSource timeSource,
ConcurrentErrorReporter errorReporter,
TimeUnit timeUnit,
long maxRuntimeDurationAsNano,
ResultsLogWriter resultsLogWriter,
Map<Integer,Class<? extends Operation>> operationTypeToClassMapping,
LoggingServiceFactory loggingServiceFactory ) throws MetricsCollectionException
{
// Specify the size of the ring buffer, must be power of 2
int bufferSize = 1024;
this.executor = Executors.newSingleThreadExecutor();
// Construct the Disruptor
disruptor = new Disruptor(
new MetricsCollectionEventFactory(),
bufferSize,
// Executor that will be used to construct new threads for consumers
this.executor,
ProducerType.MULTI,
new BlockingWaitStrategy()
// new LiteBlockingWaitStrategy()
// new SleepingWaitStrategy()
// new YieldingWaitStrategy()
// new BusySpinWaitStrategy()
// new TimeoutBlockingWaitStrategy()
// new PhasedBackoffWaitStrategy()
);
// Connect the handler
eventHandler = new DisruptorSbeMetricsEventHandler(
errorReporter,
resultsLogWriter,
timeUnit,
timeSource,
maxRuntimeDurationAsNano,
operationTypeToClassMapping,
loggingServiceFactory
);
disruptor.handleEventsWith( eventHandler );
DisruptorExceptionHandler exceptionHandler = new DisruptorExceptionHandler( errorReporter );
disruptor.handleExceptionsFor( eventHandler ).with( exceptionHandler );
disruptor.handleExceptionsWith( exceptionHandler );
// Start the Disruptor, starts all threads running & get the ring buffer from the Disruptor to be used for
// publishing
ringBuffer = disruptor.start();
this.timeSource = timeSource;
metricsServiceWriters = new ConcurrentLinkedQueue<>();
}
示例8: RoundRobinRelatedItemIndexingMessageEventHandler
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public RoundRobinRelatedItemIndexingMessageEventHandler(final Configuration configuration,
RelatedItemIndexingMessageConverter converter,
RelatedItemReferenceMessageFactory messageFactory,
RelatedItemReferenceEventHandlerFactory relatedItemIndexingEventHandlerFactory
) {
this.configuration = configuration;
this.converter = converter;
int numberOfIndexingRequestProcessors = Util.ceilingNextPowerOfTwo(configuration.getNumberOfIndexingRequestProcessors());
disruptors = new Disruptor[numberOfIndexingRequestProcessors];
executors = new ExecutorService[numberOfIndexingRequestProcessors];
handlers = new RelatedItemReferenceEventHandler[numberOfIndexingRequestProcessors];
mask = numberOfIndexingRequestProcessors-1;
final int sizeOfQueue;
if(configuration.getSizeOfBatchIndexingRequestQueue()==-1) {
sizeOfQueue = Util.ceilingNextPowerOfTwo(configuration.getSizeOfIncomingMessageQueue()/numberOfIndexingRequestProcessors);
} else {
sizeOfQueue = Util.ceilingNextPowerOfTwo(configuration.getSizeOfBatchIndexingRequestQueue());
}
int i = numberOfIndexingRequestProcessors;
while(i--!=0) {
ExecutorService executorService = getExecutorService();
executors[i] = executorService;
Disruptor<RelatedItemReference> disruptor = new Disruptor<RelatedItemReference>(
messageFactory,
sizeOfQueue, executorService,
ProducerType.SINGLE, configuration.getWaitStrategyFactory().createWaitStrategy());
disruptors[i] = disruptor;
handlers[i] = relatedItemIndexingEventHandlerFactory.getHandler();
disruptor.handleExceptionsWith(new IgnoreExceptionHandler());
disruptor.handleEventsWith(handlers[i]);
disruptor.start();
}
nextDisruptor[COUNTER_POS] = 1;
batchSize = configuration.getIndexBatchSize();
batchMessages= new ArrayList<RelatedItem>(batchSize + configuration.getMaxNumberOfRelatedItemsPerItem());
}
示例9: createDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
private Disruptor<ProxyMethodInvocation> createDisruptor(final ExecutorService executor, final int ringBufferSize)
{
final Disruptor<ProxyMethodInvocation> disruptor = new Disruptor<ProxyMethodInvocation>(new RingBufferProxyEventFactory(), ringBufferSize, executor);
disruptor.handleExceptionsWith(new FatalExceptionHandler());
return disruptor;
}