public class EventBusBundle
extends java.lang.Object
implements ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle
EventBus available for injection (to publish events).
All guice beans with methods annotated with Subscribe are
automatically registered. All listeners subscribed before startup are reported to logs (may be disabled).
If you want to customize default event bus, configure instance manually and provide instance in constructor:
new EventBusBundle(myCustomBus)
You can reduce amount of classes checked for listener methods by providing custom types matcher. For example,
new EventBusBundle()
.withMatcher(Matchers.inSubpackage("some.package"))
Reflection is used for registered listeners printing (no way otherwise to get registered subscribers). If there will be any probelms with it, simply disable reporting.
for subscribers info access| Constructor and Description |
|---|
EventBusBundle()
Register default event bus.
|
EventBusBundle(com.google.common.eventbus.EventBus eventbus)
Registers custom event bus.
|
| Modifier and Type | Method and Description |
|---|---|
void |
initialize(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap) |
EventBusBundle |
noReport()
If you have a lot of listeners or events or simply don't want console reporting use this method.
|
EventBusBundle |
withMatcher(com.google.inject.matcher.Matcher<? super java.lang.Class<?>> classMatcher)
By default, all registered bean types are checked for listener methods.
|
public EventBusBundle()
public EventBusBundle(com.google.common.eventbus.EventBus eventbus)
AsyncEventBus.eventbus - event bus instancepublic EventBusBundle withMatcher(com.google.inject.matcher.Matcher<? super java.lang.Class<?>> classMatcher)
Matchers.inSubpackage("some.pacjage").
The most restrictive (and faster) approach would be to introduce your annotation (e.g. @EventListener)
and search for listeners only inside annotated classes (Matchers.annotatedWith(EventListener.class).
classMatcher - class matcher to reduce classes checked for listener methodspublic EventBusBundle noReport()
Disabling reporting will also disable reflective access to eventbus internals, so disable it if you have problems (for example, new guava version renamed field).
public void initialize(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap)
initialize in interface ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle