Class EventBusBundle
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.context.unique.item.UniqueGuiceyBundle
-
- ru.vyarus.guicey.eventbus.EventBusBundle
-
- All Implemented Interfaces:
ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle
public class EventBusBundle extends ru.vyarus.dropwizard.guice.module.context.unique.item.UniqueGuiceyBundleBinds support for single (!) event bus.EventBusavailable for injection (to publish events). All guice beans with methods annotated withSubscribeare 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:
- eventbus documentation,
for subscribers info access
-
-
Constructor Summary
Constructors Constructor Description EventBusBundle()Register default event bus.EventBusBundle(com.google.common.eventbus.EventBus eventbus)Registers custom event bus.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventBusBundlenoReport()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)EventBusBundlewithMatcher(com.google.inject.matcher.Matcher<? super java.lang.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, hashCode
-
-
-
-
Constructor Detail
-
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 Detail
-
withMatcher
public EventBusBundle withMatcher(com.google.inject.matcher.Matcher<? super java.lang.Class<?>> classMatcher)
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
public EventBusBundle 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)
-
-