Package org.greenrobot.eventbus
Class EventBusBuilder
- java.lang.Object
-
- org.greenrobot.eventbus.EventBusBuilder
-
public class EventBusBuilder extends java.lang.Object
Creates EventBus instances with custom parameters and also allows to install a custom default EventBus instance. Create a new builder usingEventBus.builder()
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventBusBuilder
addIndex(SubscriberInfoIndex index)
Adds an index generated by EventBus' annotation preprocessor.EventBus
build()
Builds an EventBus based on the current configuration.EventBusBuilder
eventInheritance(boolean eventInheritance)
By default, EventBus considers the event class hierarchy (subscribers to super classes will be notified).EventBusBuilder
executorService(java.util.concurrent.ExecutorService executorService)
Provide a custom thread pool to EventBus used for async and background event delivery.EventBusBuilder
ignoreGeneratedIndex(boolean ignoreGeneratedIndex)
Forces the use of reflection even if there's a generated index (default: false).EventBus
installDefaultEventBus()
Installs the default EventBus returned byEventBus.getDefault()
using this builders' values.EventBusBuilder
logger(Logger logger)
Set a specific log handler for all EventBus logging.EventBusBuilder
logNoSubscriberMessages(boolean logNoSubscriberMessages)
Default: trueEventBusBuilder
logSubscriberExceptions(boolean logSubscriberExceptions)
Default: trueEventBusBuilder
sendNoSubscriberEvent(boolean sendNoSubscriberEvent)
Default: trueEventBusBuilder
sendSubscriberExceptionEvent(boolean sendSubscriberExceptionEvent)
Default: trueEventBusBuilder
skipMethodVerificationFor(java.lang.Class<?> clazz)
Method name verification is done for methods starting with onEvent to avoid typos; using this method you can exclude subscriber classes from this check.EventBusBuilder
strictMethodVerification(boolean strictMethodVerification)
Enables strict method verification (default: false).EventBusBuilder
throwSubscriberException(boolean throwSubscriberException)
Fails if an subscriber throws an exception (default: false).
-
-
-
Method Detail
-
logSubscriberExceptions
public EventBusBuilder logSubscriberExceptions(boolean logSubscriberExceptions)
Default: true
-
logNoSubscriberMessages
public EventBusBuilder logNoSubscriberMessages(boolean logNoSubscriberMessages)
Default: true
-
sendSubscriberExceptionEvent
public EventBusBuilder sendSubscriberExceptionEvent(boolean sendSubscriberExceptionEvent)
Default: true
-
sendNoSubscriberEvent
public EventBusBuilder sendNoSubscriberEvent(boolean sendNoSubscriberEvent)
Default: true
-
throwSubscriberException
public EventBusBuilder throwSubscriberException(boolean throwSubscriberException)
Fails if an subscriber throws an exception (default: false). Tip: Use this with BuildConfig.DEBUG to let the app crash in DEBUG mode (only). This way, you won't miss exceptions during development.
-
eventInheritance
public EventBusBuilder eventInheritance(boolean eventInheritance)
By default, EventBus considers the event class hierarchy (subscribers to super classes will be notified). Switching this feature off will improve posting of events. For simple event classes extending Object directly, we measured a speed up of 20% for event posting. For more complex event hierarchies, the speed up should be greater than 20%. However, keep in mind that event posting usually consumes just a small proportion of CPU time inside an app, unless it is posting at high rates, e.g. hundreds/thousands of events per second.
-
executorService
public EventBusBuilder executorService(java.util.concurrent.ExecutorService executorService)
Provide a custom thread pool to EventBus used for async and background event delivery. This is an advanced setting to that can break things: ensure the given ExecutorService won't get stuck to avoid undefined behavior.
-
skipMethodVerificationFor
public EventBusBuilder skipMethodVerificationFor(java.lang.Class<?> clazz)
Method name verification is done for methods starting with onEvent to avoid typos; using this method you can exclude subscriber classes from this check. Also disables checks for method modifiers (public, not static nor abstract).
-
ignoreGeneratedIndex
public EventBusBuilder ignoreGeneratedIndex(boolean ignoreGeneratedIndex)
Forces the use of reflection even if there's a generated index (default: false).
-
strictMethodVerification
public EventBusBuilder strictMethodVerification(boolean strictMethodVerification)
Enables strict method verification (default: false).
-
addIndex
public EventBusBuilder addIndex(SubscriberInfoIndex index)
Adds an index generated by EventBus' annotation preprocessor.
-
logger
public EventBusBuilder logger(Logger logger)
Set a specific log handler for all EventBus logging. By default, all logging is viaandroid.util.Log
on Android or System.out on JVM.
-
installDefaultEventBus
public EventBus installDefaultEventBus()
Installs the default EventBus returned byEventBus.getDefault()
using this builders' values. Must be done only once before the first usage of the default EventBus.- Throws:
EventBusException
- if there's already a default EventBus instance in place
-
build
public EventBus build()
Builds an EventBus based on the current configuration.
-
-