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