public final EventHandlerGroup<T> handleEventsWith(final EventHandler<? super T>... handlers)

79 views
Skip to first unread message

Eric Lu

unread,
Dec 21, 2018, 7:12:22 AM12/21/18
to Disruptor
Hi,

I am trying to figure out how to do parallel event processing. 

I see the example code in the Pipeliner:

        disruptor.handleEventsWith(
            new ParallelHandler(0, 3),
            new ParallelHandler(1, 3),
            new ParallelHandler(2, 3)
        ).then(new JoiningHandler());


However, I would like to pass in an array of ParallelHandlers, which I can config using a config file instead of hard coding as the Pipeliner demos.

I found an github project which fits what I need, it uses spring config xml to config the event handlers, then inject them into a simple data structure (EventHandlerChain, which contains two simple arrays of EventHandlers ) which then be used pragmatically registering all the event handlers.  


private void disruptorEventHandlerChain() {
for(int i=0;i<eventHandlerChain.length;i++){
EventHandlerChain<T> eventHandlersChain = eventHandlerChain[i];
EventHandlerGroup<T> eventHandlerGroup = null;
if(i == 0){
eventHandlerGroup = getDisruptor().handleEventsWith(eventHandlersChain.getCurrentEventHandlers());
}else{
eventHandlerGroup = getDisruptor().after(eventHandlersChain.getCurrentEventHandlers());
}
if(! ArrayUtils.isEmpty(eventHandlersChain.getNextEventHandlers())){
eventHandlerGroup.then(eventHandlersChain.getNextEventHandlers());
}
}
getEventProcessorGraph();
}


I tried to follow the similar approach; however,  my project's maven build is throwing the warning below due to some of the quality check plugins configured. My understanding is that due to the limitation of Java Varargs is a simple array, and simple array does not support generics, so this warning is complaining that.


Warning:(93, 83) java: unchecked conversion
  required: com.test.controller.EventHandlerChain<com.test.controller.EventContext>
  found:    com.test.controller.EventHandlerChain 

I wonder if there is another API on the Disruptor I can use which I can pass a list of EventHandlers with the Event type I specify, which can avoid this compiler check warning.

Thanks a lot!

Eric
Reply all
Reply to author
Forward
0 new messages