Search in sources :

Example 1 with FatalExceptionHandler

use of com.lmax.disruptor.FatalExceptionHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldOnlyApplyExceptionsHandlersSpecifiedViaHandleExceptionsWithOnNewEventProcessors.

@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);
}
Also used : FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) ExceptionHandler(com.lmax.disruptor.ExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) ExceptionThrowingEventHandler(com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) Test(org.junit.Test)

Example 2 with FatalExceptionHandler

use of com.lmax.disruptor.FatalExceptionHandler in project opennms by OpenNMS.

the class NewtsWriter method setUpWorkerPool.

private void setUpWorkerPool() {
    // Executor that will be used to construct new threads for consumers
    final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("NewtsWriter-Consumer-%d").build();
    final Executor executor = Executors.newCachedThreadPool(namedThreadFactory);
    @SuppressWarnings("unchecked") final WorkHandler<SampleBatchEvent>[] handlers = new WorkHandler[m_numWriterThreads];
    for (int i = 0; i < m_numWriterThreads; i++) {
        handlers[i] = this;
    }
    m_ringBuffer = RingBuffer.createMultiProducer(SampleBatchEvent::new, m_ringBufferSize);
    m_workerPool = new WorkerPool<SampleBatchEvent>(m_ringBuffer, m_ringBuffer.newBarrier(), new FatalExceptionHandler(), handlers);
    m_ringBuffer.addGatingSequences(m_workerPool.getWorkerSequences());
    m_workerPool.start(executor);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) WorkHandler(com.lmax.disruptor.WorkHandler) Executor(java.util.concurrent.Executor) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler)

Aggregations

FatalExceptionHandler (com.lmax.disruptor.FatalExceptionHandler)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ExceptionHandler (com.lmax.disruptor.ExceptionHandler)1 WorkHandler (com.lmax.disruptor.WorkHandler)1 ExceptionThrowingEventHandler (com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler)1 StubExceptionHandler (com.lmax.disruptor.dsl.stubs.StubExceptionHandler)1 Executor (java.util.concurrent.Executor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1