public class EventBusImpl extends java.lang.Object implements EventBus
EventBus. This implementation is based on the google eventbus
com.google.common.eventbus.EventBus but the absence of descent extension points forces us to inspire but
not extend that implementation. The critical parts that drove us towards this approach are:
CONSUMER_QUEUE_FULL_RETRY_MAX_DEFAULT, CONSUMER_QUEUE_FULL_RETRY_MAX_PROP_NAME, CONSUMER_QUEUE_SIZE_DEFAULT, CONSUMER_QUEUE_SIZE_DEFAULT_PROP_NAME| Constructor and Description |
|---|
EventBusImpl() |
| Modifier and Type | Method and Description |
|---|---|
void |
addFilterForEvent(EventFilter filter,
java.lang.Class<?> eventClass)
Adds a publisher level filter for the passed event type.
|
void |
addFilterForSubscriber(EventFilter filter,
SubscriberInfo subscriberInfo)
Adds the passed filter for the passed subscriber method.
|
void |
clearFiltersForEvent(java.lang.Class<?> eventClass)
Removes all the filters for the passed event type.
|
void |
clearFiltersForSubscriber(SubscriberInfo subscriberInfo)
Removes all filters for the passed subscriber method.
|
void |
disableCatchAllSubscriber()
Disables the
CatchAllSubscriber for this eventbus. |
boolean |
enableCatchAllSubscriber(java.util.concurrent.BlockingQueue catchAllSink)
Enables the
CatchAllSubscriber for this eventbus with the sink for the subscriber as the passed
BlockingQueue instance. |
java.util.Set<java.lang.Class<?>> |
getAllRegisteredEventTypes()
Returns all the event types which have atleast a subscriber or a filter defined in this event bus.
|
java.util.Set<SubscriberInfo> |
getAllSubscribers()
Returns a set of subscribers that are registered with this event bus.
|
java.util.Set<SubscriberInfo> |
getAllSubscribersForAnEvent(java.lang.Class<?> eventType)
Returns a set of subscribers for that passed event type that are registered with this event bus.
|
java.util.Set<EventFilter> |
getFilterForASubscriber(SubscriberInfo subscriberInfo)
The set of event filters attached to the passed subscriber.
|
java.util.Set<EventFilter> |
getFiltersForAnEvent(java.lang.Class<?> eventType)
The set of event filters attached to the passed event type.
|
void |
publish(java.lang.Object event)
Publishes the passed event object.
|
void |
publishIffNotDead(EventCreator creator,
java.lang.Class<?>... eventTypes)
Publishes events iff there is atleast one listener for any of the passed event types.
|
void |
registerSubscriber(EventFilter filter,
java.lang.Object subscriber)
Registers a subscriber which will be invoked iff the filter passes for the event to be published.
|
void |
registerSubscriber(java.lang.Object subscriber)
Registers a subscriber without any filters.
|
void |
removeFiltersForEvent(java.lang.Class<?> eventClass,
EventFilter... filters)
Removes the passed filters for the passed event type.
|
void |
removeFiltersForSubscriber(SubscriberInfo subscriberInfo,
EventFilter... filters)
Removes the passed filters for the passed subscriber.
|
void |
shutdown() |
java.util.Set<java.lang.Object> |
unregisterSubscriber(java.lang.Class<?> subscriberClass)
Removes the subscriber class (all of its subscriber methods) from the event bus.
|
boolean |
unregisterSubscriber(java.lang.Object subscriber)
Removes the subscriber instance (all of its subscriber methods) from the event bus.
|
public void publish(java.lang.Object event)
EventBusfalse then exit.public void publishIffNotDead(EventCreator creator, java.lang.Class<?>... eventTypes)
EventBusEventBus
javadocs for details about conditional event publishing. EventCreator.createEvent(java.util.Set) with only the event types that have atleast one listener.false then exit.publishIffNotDead in interface EventBuscreator - Event creator to be invoked iff there is atleast one listener for the event types.eventTypes - Event types for which the events are to be published.public void registerSubscriber(@Nullable
EventFilter filter,
java.lang.Object subscriber)
throws InvalidSubscriberException
EventBusEventBus.registerSubscriber(Object) and then register each filter using
EventBus.addFilterForSubscriber(com.netflix.eventbus.spi.EventFilter, com.netflix.eventbus.spi.SubscriberInfo) EventBus javadocs for details about subscribers, filters, event-subscriber association and dispatch
mode.registerSubscriber in interface EventBusfilter - Filter.subscriber - Subscriber to register.InvalidSubscriberException - If the passed subscriber is invalid.public void registerSubscriber(java.lang.Object subscriber)
throws InvalidSubscriberException
EventBusEventBus javadocs for details about subscribers, filters, event-subscriber association and dispatch
mode.registerSubscriber in interface EventBussubscriber - Subscriber to register.InvalidSubscriberException - If the passed subscriber is invalid.public boolean enableCatchAllSubscriber(java.util.concurrent.BlockingQueue catchAllSink)
EventBusCatchAllSubscriber for this eventbus with the sink for the subscriber as the passed
BlockingQueue instance.enableCatchAllSubscriber in interface EventBuscatchAllSink - The sink for the CatchAllSubscribertrue if the passes sink was successfully attached, iff there is no sink already present.public void disableCatchAllSubscriber()
EventBusCatchAllSubscriber for this eventbus.disableCatchAllSubscriber in interface EventBuspublic java.util.Set<java.lang.Object> unregisterSubscriber(java.lang.Class<?> subscriberClass)
EventBusunregisterSubscriber in interface EventBussubscriberClass - Subscriber class to unregister.public boolean unregisterSubscriber(java.lang.Object subscriber)
EventBusunregisterSubscriber in interface EventBussubscriber - Subscriber instance to unregister.true if the subscriber instance was unregistered, false otherwise.public void addFilterForSubscriber(EventFilter filter, SubscriberInfo subscriberInfo)
EventBusEventBus javadocs for details about subscribers & filters.addFilterForSubscriber in interface EventBusfilter - Filter to attach.subscriberInfo - Subscriber info. This can be retrieved by methods EventBus.getAllSubscribersForAnEvent(Class)
or EventBus.getAllSubscribers()public void removeFiltersForSubscriber(SubscriberInfo subscriberInfo, EventFilter... filters)
EventBusEventBus javadocs for details about subscribers & filters.removeFiltersForSubscriber in interface EventBussubscriberInfo - Subscriber info. This can be retrieved by methods EventBus.getAllSubscribersForAnEvent(Class)
or EventBus.getAllSubscribers()filters - Filters to remove.public void clearFiltersForSubscriber(SubscriberInfo subscriberInfo)
EventBusEventBus javadocs for details about subscribers & filters.clearFiltersForSubscriber in interface EventBussubscriberInfo - Subscriber info. This can be retrieved by methods EventBus.getAllSubscribersForAnEvent(Class)
or EventBus.getAllSubscribers()public void addFilterForEvent(EventFilter filter, java.lang.Class<?> eventClass)
EventBusEventBus javadocs for details about publishers & filters.addFilterForEvent in interface EventBusfilter - FiltereventClass - The class of the event for which the filter is to be attached.public void removeFiltersForEvent(java.lang.Class<?> eventClass,
EventFilter... filters)
EventBusEventBus javadocs for details about publishers & filters.removeFiltersForEvent in interface EventBuseventClass - The class of the event for which the filter are to be removed.filters - Filters to be removedpublic void clearFiltersForEvent(java.lang.Class<?> eventClass)
EventBusEventBus javadocs for details about publishers & filters.clearFiltersForEvent in interface EventBuseventClass - The class of the event for which the filter are to be cleared.public java.util.Set<SubscriberInfo> getAllSubscribers()
EventBusEventBus.getFilterForASubscriber(com.netflix.eventbus.spi.SubscriberInfo)getAllSubscribers in interface EventBuspublic java.util.Set<SubscriberInfo> getAllSubscribersForAnEvent(java.lang.Class<?> eventType)
EventBusEventBus.getFilterForASubscriber(SubscriberInfo)getAllSubscribersForAnEvent in interface EventBuseventType - Event for which the subscribers are to be retrieved.public java.util.Set<EventFilter> getFilterForASubscriber(SubscriberInfo subscriberInfo)
EventBusgetFilterForASubscriber in interface EventBussubscriberInfo - Subscriber info. This can be retrieved by methods EventBus.getAllSubscribersForAnEvent(Class)
or EventBus.getAllSubscribers()public java.util.Set<EventFilter> getFiltersForAnEvent(java.lang.Class<?> eventType)
EventBusgetFiltersForAnEvent in interface EventBuseventType - Event type for which the filters are to be retrieved.public java.util.Set<java.lang.Class<?>> getAllRegisteredEventTypes()
EventBusgetAllRegisteredEventTypes in interface EventBuspublic void shutdown()