现在我们第一步吧Disruptor实例化好了,下面我们看看handlerEventWith(添加消费者的监听)内部都做了些什么
public EventHandlerGroup<T> handleEventsWith(final EventHandler<? super T>... handlers)
{
return createEventProcessors(new Sequence[0], handlers);
}
继续追:
EventHandlerGroup<T> createEventProcessors(final Sequence[] barrierSequences,
final EventHandler<? super T>[] eventHandlers)
{
checkNotStarted();
//创建一个handler数组
final Sequence[] processorSequences = new Sequence[eventHandlers.length];
//创建一个SequenceBarrier屏障
final SequenceBarrier barrier = ringBuffer.newBarrier(barrierSequences);
//循环遍历传入的handlers
for (int i = 0, eventHandlersLength = eventHandlers.length; i < eventHandlersLength; i++)
{
final EventHandler<? super T> eventHandler = eventHandlers[i];
//把遍历的handler用于实例化一个batchEventProcessor
final BatchEventProcessor<T> batchEventProcessor = new BatchEventProcessor<T>(ringBuffer, barrier, eventHandler);