bennidi / mbassador

Powerful event-bus optimized for high throughput in multi-threaded applications. Features: Sync and Async event publication, weak/strong references, event filtering, annotation driven
MIT License
955 stars 146 forks source link

Don't use dispatcher thread #151

Open techyourchance opened 7 years ago

techyourchance commented 7 years ago

Hi, First of all thanks for this great project.

I'd like to configure MBassador such that the messages are being dispatched by the thread that publishes them, but processed by background threads supplied by AsynchronousHandlerInvocation.

I thought that this could work:

    private final MBassador<BaseEvent> mEventBus = new MBassador<>();

    public void publishEvent(BaseEvent event) {
        mEventBus.publish(event);
    }

But then javadoc of publish(Object) states:

Synchronously publish a message to all registered listeners (this includes listeners defined for super types) The call blocks until every messageHandler has processed the message.

The part about "blocks until every messageHandler has processed the message" is unacceptable for me, so I thought that this is not the right solution.

However, having spent some time in the source code, it looks like the call to publish(Object) will block only until the processing have been delegated to messageHandlers, not until processing is actually done.

This looks like an incorrectly (or ambiguously) documented feature, but, before I build my system around it, I'd like to make sure that I got it right and the above code will indeed perform dispatching on the calling thread, and the calling thread will not wait for all processing to complete.

bennidi commented 7 years ago

The JavaDoc is clearly misleading here. Your statement is correct

call to publish(Object) will block only until the processing have been delegated to messageHandlers, not until processing is actually done.

I would greatly appreciate if you would take a bit of time to look through the docs and update them accordingly. It seems you have dug into the source code already and I believe that the docs can benefit from a "users" view. I will review a PR quickly then. Thanks.

techyourchance commented 6 years ago

Just noticed I forgot to reply on this one. I'm currently not confident that I have enough experience and understand all the intricate details in order to contribute, but, since I decided to use mbassador in my system, I will get to that point and gladly submit a PR. Therefore, you can keep this issue open as a reminder for me.

techyourchance commented 6 years ago

And you can even assign it to me.