Class EventBusBundle
- All Implemented Interfaces:
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 problems with it, simply disable reporting.
Only one bundle instance will be actually used (in case of multiple registrations).
- Since:
- 12.10.2016
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRegister default event bus.EventBusBundle(com.google.common.eventbus.EventBus eventbus) Registers custom event bus. -
Method Summary
Modifier and TypeMethodDescriptionnoReport()If you have a lot of listeners or events or simply don't want console reporting use this method.voidrun(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyEnvironment environment) withMatcher(com.google.inject.matcher.Matcher<? super Class<?>> classMatcher) By default, all registered bean types are checked for listener methods.Methods inherited from class ru.vyarus.dropwizard.guice.module.context.unique.item.UniqueGuiceyBundle
equals, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle
initialize
-
Constructor Details
-
EventBusBundle
public EventBusBundle()Register default event bus. Events processing is synchronous. -
EventBusBundle
public EventBusBundle(com.google.common.eventbus.EventBus eventbus) Registers custom event bus. Use this constructor to customize event bus or to switch toAsyncEventBus.- Parameters:
eventbus- event bus instance
-
-
Method Details
-
withMatcher
By default, all registered bean types are checked for listener methods. Listener check involves all methods in class and subclasses lookup. If you have too much beans which are not using eventbus, then it makes sense to reduce checked beans scope For example, check only beans in some package: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).- Parameters:
classMatcher- class matcher to reduce classes checked for listener methods- Returns:
- bundle instance for chained calls
-
noReport
If you have a lot of listeners or events or simply don't want console reporting use this method.Disabling reporting will also disable reflective access to eventbus internals, so disable it if you have problems (for example, new guava version renamed field).
- Returns:
- bundle instance for chained calls
-
run
public void run(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyEnvironment environment)
-