@SuppressWarnings("deprecation") @Test public void shouldOnlyApplyExceptionsHandlersSpecifiedViaHandleExceptionsWithOnNewEventProcessors() throws Exception { AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>(); ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled); RuntimeException testException = new RuntimeException(); ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException); disruptor.handleExceptionsWith(exceptionHandler); disruptor.handleEventsWith(handler); disruptor.handleExceptionsWith(new FatalExceptionHandler()); publishEvent(); final Throwable actualException = waitFor(eventHandled); assertSame(testException, actualException); }
@SuppressWarnings("deprecation") @Test public void shouldSupportSpecifyingAExceptionHandlerForEventProcessors() throws Exception { AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>(); ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled); RuntimeException testException = new RuntimeException(); ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException); disruptor.handleExceptionsWith(exceptionHandler); disruptor.handleEventsWith(handler); publishEvent(); final Throwable actualException = waitFor(eventHandled); assertSame(testException, actualException); }
@Inject ReplyProcessorImpl(@Named("ReplyStrategy") WaitStrategy strategy, MetricsRegistry metrics, Panicker panicker, ObjectPool<Batch> batchPool) { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("reply-%d"); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory.build()); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, strategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); disruptor.handleEventsWith(this); this.replyRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.batchPool = batchPool; this.nextIDToHandle.set(0); this.futureEvents = new PriorityQueue<>(10, new Comparator<ReplyBatchEvent>() { public int compare(ReplyBatchEvent replyBatchEvent1, ReplyBatchEvent replyBatchEvent2) { return Long.compare(replyBatchEvent1.getBatchSequence(), replyBatchEvent2.getBatchSequence()); } }); // Metrics config this.abortMeter = metrics.meter(name("tso", "aborts")); this.commitMeter = metrics.meter(name("tso", "commits")); this.timestampMeter = metrics.meter(name("tso", "timestampAllocation")); LOG.info("ReplyProcessor initialized"); }
@Inject PersistenceProcessorImpl(TSOServerConfig config, @Named("PersistenceStrategy") WaitStrategy strategy, CommitTable commitTable, ObjectPool<Batch> batchPool, Panicker panicker, PersistenceProcessorHandler[] handlers, MetricsRegistry metrics) throws Exception { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("persist-%d"); this.disruptorExec = Executors.newFixedThreadPool(config.getNumConcurrentCTWriters(), threadFactory.build()); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 20, disruptorExec , SINGLE, strategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWithWorkerPool(handlers); this.persistRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.metrics = metrics; this.batchSequence = 0L; this.batchPool = batchPool; this.currentBatch = batchPool.borrowObject(); LOG.info("PersistentProcessor initialized"); }
public IndexingService(AtomicLong reads, AtomicLong writes) { support = new HashMap<>(); this.reads = reads; this.writes = writes; ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("SGRingBuffer-Thread-%d").build(); executorService = Executors.newFixedThreadPool(numWorkers, namedThreadFactory); disruptor = new Disruptor<>(eventFactory, bufferSize, executorService); ringBuffer = disruptor.getRingBuffer(); ExceptionHandler exceptionHandler = new FatalExceptionHandler(); disruptor.handleExceptionsWith(exceptionHandler); EventHandler<IndexEntryEvent>[] eventHandlers = new EventHandler[numWorkers]; for (int i = 0; i < numWorkers; i++) { eventHandlers[i] = new IndexEventHandler(this, i, numWorkers); } disruptor.handleEventsWith(eventHandlers); disruptor.start(); }
@Inject ReplyProcessorImpl(@Named("ReplyStrategy") WaitStrategy strategy, MetricsRegistry metrics, Panicker panicker, ObjectPool<Batch> batchPool) { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("reply-%d"); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory.build()); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, strategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); disruptor.handleEventsWith(this); this.replyRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.batchPool = batchPool; this.nextIDToHandle.set(0); this.futureEvents = new PriorityQueue<>(10, new Comparator<ReplyBatchEvent>() { public int compare(ReplyBatchEvent replyBatchEvent1, ReplyBatchEvent replyBatchEvent2) { return Long.compare(replyBatchEvent1.getBatchSequence(), replyBatchEvent2.getBatchSequence()); } }); // Metrics config this.abortMeter = metrics.meter(name("tso", "aborts")); this.commitMeter = metrics.meter(name("tso", "commits")); this.timestampMeter = metrics.meter(name("tso", "timestampAllocation")); this.fenceMeter = metrics.meter(name("tso", "fences")); LOG.info("ReplyProcessor initialized"); }
@Inject RetryProcessorImpl(@Named("RetryStrategy") WaitStrategy strategy, MetricsRegistry metrics, CommitTable commitTable, ReplyProcessor replyProc, Panicker panicker, ObjectPool<Batch> batchPool) throws InterruptedException, ExecutionException, IOException { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("retry-%d").build(); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, SINGLE, strategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWith(this); this.retryRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.commitTableClient = commitTable.getClient(); this.replyProc = replyProc; this.batchPool = batchPool; // Metrics configuration this.txAlreadyCommittedMeter = metrics.meter(name("tso", "retries", "commits", "tx-already-committed")); this.invalidTxMeter = metrics.meter(name("tso", "retries", "aborts", "tx-invalid")); this.noCTFoundMeter = metrics.meter(name("tso", "retries", "aborts", "tx-without-commit-timestamp")); LOG.info("RetryProcessor initialized"); }
@Inject RetryProcessorImpl(@Named("RetryStrategy") WaitStrategy strategy, MetricsRegistry metrics, CommitTable commitTable, ReplyProcessor replyProc, Panicker panicker, ObjectPool<Batch> batchPool) throws InterruptedException, ExecutionException, IOException { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("retry-%d").build(); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, SINGLE, strategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWith(this); this.retryRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.commitTableClient = commitTable.getClient(); this.replyProc = replyProc; this.batchPool = batchPool; // Metrics configuration this.txAlreadyCommittedMeter = metrics.meter(name("tso", "retries", "commits", "tx-already-committed")); this.invalidTxMeter = metrics.meter(name("tso", "retries", "aborts", "tx-invalid")); this.noCTFoundMeter = metrics.meter(name("tso", "retries", "aborts", "tx-without-commit-timestamp")); LOG.info("RetryProcessor initialized"); }
disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWithWorkerPool(handlers); this.persistRing = disruptor.start();
AbstractRequestProcessor(MetricsRegistry metrics, TimestampOracle timestampOracle, Panicker panicker, TSOServerConfig config, LowWatermarkWriter lowWatermarkWriter, ReplyProcessor replyProcessor) throws IOException { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ TimeoutBlockingWaitStrategy timeoutStrategy = new TimeoutBlockingWaitStrategy(config.getBatchPersistTimeoutInMs(), MILLISECONDS); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("request-%d").build(); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, timeoutStrategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWith(this); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.metrics = metrics; this.timestampOracle = timestampOracle; this.hashmap = new CommitHashMap(config.getConflictMapSize()); this.tableFences = new HashMap<Long, Long>(); this.lowWatermarkWriter = lowWatermarkWriter; this.replyProcessor = replyProcessor; LOG.info("RequestProcessor initialized"); }
); this.disruptor.handleExceptionsWith(new ExceptionHandler() { @Override public void handleEventException(Throwable ex, long sequence, Object event) {
@Inject RequestProcessorImpl(MetricsRegistry metrics, TimestampOracle timestampOracle, PersistenceProcessor persistProc, Panicker panicker, TSOServerConfig config) throws IOException { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ TimeoutBlockingWaitStrategy timeoutStrategy = new TimeoutBlockingWaitStrategy(config.getBatchPersistTimeoutInMs(), MILLISECONDS); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("request-%d").build(); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, timeoutStrategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWith(this); this.requestRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.metrics = metrics; this.persistProc = persistProc; this.timestampOracle = timestampOracle; this.hashmap = new CommitHashMap(config.getConflictMapSize()); LOG.info("RequestProcessor initialized"); }
@SuppressWarnings("deprecation") @PostConstruct private void start() { // Executor that will be used to construct new threads for consumers Executor executor = Executors.newCachedThreadPool(); // The factory for the event TaskEventFactory factory = new TaskEventFactory(); // Specify the size of the ring buffer, must be power of 2. // Construct the Disruptor // 单线程模式,获取额外的性能 disruptor = new Disruptor<TaskEvent>(factory, bufferSize, executor, ProducerType.SINGLE, new YieldingWaitStrategy()); List<TaskHandler> TaskHandlers = new ArrayList<>(); for (int i = 0; i < handlerCount; i++) { TaskHandlers.add(new TaskHandler()); } disruptor.handleExceptionsWith(new IgnoreExceptionHandler()); // 多个消费者,每个消费者竞争消费不同数据 disruptor.handleEventsWithWorkerPool(TaskHandlers.toArray(new TaskHandler[TaskHandlers.size()])); // Start the Disruptor, starts all threads running disruptor.start(); // Get the ring buffer from the Disruptor to be used for publishing. RingBuffer<TaskEvent> ringBuffer = disruptor.getRingBuffer(); taskEventProducer = new TaskEventProducer(ringBuffer); }
waitStrategy ); disruptor.handleExceptionsWith(new LoggingExceptionHandler(LOG));
ProducerType.MULTI, configuration.getInputBufferWaitStrategy()); disruptor.handleExceptionsWith(new LoggingExceptionHandler(LOG));
); this.disruptor.handleExceptionsWith(new ExceptionHandler() { @Override public void handleEventException(Throwable ex, long sequence, Object event) {
); disruptor.handleExceptionsWith(new ConsumerExceptionHandler(errorConsumers)); disruptor.handleEventsWith(new ConsumerEventHandler<T>(consumer));
bufferSize, executorService, producerType, new BlockingWaitStrategy()); disruptor.handleExceptionsWith(siddhiAppContext.getDisruptorExceptionHandler()); break; disruptor = new Disruptor<Event>(new SiddhiEventFactory(streamDefinition.getAttributeList().size()), bufferSize, executorService); disruptor.handleExceptionsWith(siddhiAppContext.getDisruptorExceptionHandler());
); if(null != errorHandler) { disruptor.handleExceptionsWith(errorHandler);
); this.disruptor.handleExceptionsWith(new ExceptionHandler() { @Override public void handleEventException(Throwable ex, long sequence, Object event) {