Search in sources :

Example 1 with WorkHandler

use of com.lmax.disruptor.WorkHandler 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

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 FatalExceptionHandler (com.lmax.disruptor.FatalExceptionHandler)1 WorkHandler (com.lmax.disruptor.WorkHandler)1 Executor (java.util.concurrent.Executor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1