com.netflix.eventbus.spi

Interface EventBus

    • Field Detail

      • CONSUMER_QUEUE_FULL_RETRY_MAX_PROP_NAME

        static final java.lang.String CONSUMER_QUEUE_FULL_RETRY_MAX_PROP_NAME
        See Also:
        Constant Field Values
      • CONSUMER_QUEUE_FULL_RETRY_MAX_DEFAULT

        static final int CONSUMER_QUEUE_FULL_RETRY_MAX_DEFAULT
        See Also:
        Constant Field Values
      • CONSUMER_QUEUE_SIZE_DEFAULT_PROP_NAME

        static final java.lang.String CONSUMER_QUEUE_SIZE_DEFAULT_PROP_NAME
        See Also:
        Constant Field Values
      • CONSUMER_QUEUE_SIZE_DEFAULT

        static final int CONSUMER_QUEUE_SIZE_DEFAULT
        See Also:
        Constant Field Values
    • Method Detail

      • publish

        void publish(java.lang.Object event)
        Publishes the passed event object. The following is done on receiving this call:
        • Apply all publisher level filters for this event. If any of the filter returns false then exit.
        • Find all interested subscribers.
        • Apply filters per interested subscriber.
        • For the subscribers that pass the filtering criterion, enqueue the event to the subscriber's queue (async dispatch)
        Parameters:
        event - Event to publish.
      • publishIffNotDead

        void publishIffNotDead(EventCreator creator,
                             java.lang.Class<?>... eventTypes)
        Publishes events iff there is atleast one listener for any of the passed event types. See EventBus javadocs for details about conditional event publishing.
        The following is done on receiving this call:
        • Find all interested subscribers.
        • Invoke EventCreator.createEvent(java.util.Set) with only the event types that have atleast one listener.
        • Apply all publisher level filters for this event. If any of the filter returns false then exit.
        • Find all subscribers corresponding to the events created by the above call.
        • For all subscribers, invoke the filters.
        • For the subscribers that pass the filtering criterion, enqueue the event(s) to the subscriber's queue (async dispatch)
        This style of publishing must only be used if creating an event object is costly (either due to the size of the object or work required to create such an object) otherwise, the complexity is not worth the effort.
        Parameters:
        creator - 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.
      • registerSubscriber

        void registerSubscriber(java.lang.Object subscriber)
                                throws InvalidSubscriberException
        Registers a subscriber without any filters. See EventBus javadocs for details about subscribers, filters, event-subscriber association and dispatch mode.
        Parameters:
        subscriber - Subscriber to register.
        Throws:
        InvalidSubscriberException - If the passed subscriber is invalid.
      • enableCatchAllSubscriber

        boolean enableCatchAllSubscriber(java.util.concurrent.BlockingQueue<?> catchAllSink)
        Enables the CatchAllSubscriber for this eventbus with the sink for the subscriber as the passed BlockingQueue instance.
        Parameters:
        catchAllSink - The sink for the CatchAllSubscriber
        Returns:
        true if the passes sink was successfully attached, iff there is no sink already present.
      • disableCatchAllSubscriber

        void disableCatchAllSubscriber()
        Disables the CatchAllSubscriber for this eventbus.
      • unregisterSubscriber

        java.util.Set<java.lang.Object> unregisterSubscriber(java.lang.Class<?> subscriberClass)
        Removes the subscriber class (all of its subscriber methods) from the event bus.
        If there are more than one instance of the passed class registered with this event bus, all of them are removed. All unconsumed events are rejected.
        Parameters:
        subscriberClass - Subscriber class to unregister.
        Returns:
        Set of subscriber instances that were removed by this unregister. More than one subscriber instances can be registered with this bus for the same subscriber class. In such a case, there will be more than one instances in the list.
      • unregisterSubscriber

        boolean unregisterSubscriber(java.lang.Object subscriber)
        Removes the subscriber instance (all of its subscriber methods) from the event bus.
        If there are other subscriber instances associated with the class of the passed subscriber, they are left untouched. This should be the preferred mode of unregistration when more than one instances of the same subscriber class are registered and only one is to be removed. All unconsumed events are rejected.
        Parameters:
        subscriber - Subscriber instance to unregister.
        Returns:
        true if the subscriber instance was unregistered, false otherwise.
      • addFilterForEvent

        void addFilterForEvent(EventFilter filter,
                             java.lang.Class<?> eventClass)
        Adds a publisher level filter for the passed event type. See EventBus javadocs for details about publishers & filters.
        Parameters:
        filter - Filter
        eventClass - The class of the event for which the filter is to be attached.
      • removeFiltersForEvent

        void removeFiltersForEvent(java.lang.Class<?> eventClass,
                                 EventFilter... filters)
        Removes the passed filters for the passed event type. See EventBus javadocs for details about publishers & filters.
        Parameters:
        eventClass - The class of the event for which the filter are to be removed.
        filters - Filters to be removed
      • clearFiltersForEvent

        void clearFiltersForEvent(java.lang.Class<?> eventClass)
        Removes all the filters for the passed event type. See EventBus javadocs for details about publishers & filters.
        Parameters:
        eventClass - The class of the event for which the filter are to be cleared.
      • getAllSubscribersForAnEvent

        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.
        The details of the filter attached (if any) can be retrieved by the method getFilterForASubscriber(SubscriberInfo)
        Parameters:
        eventType - Event for which the subscribers are to be retrieved.
        Returns:
        An immutable set of currently registered subscribers.
      • getFiltersForAnEvent

        java.util.Set<EventFilter> getFiltersForAnEvent(java.lang.Class<?> eventType)
        The set of event filters attached to the passed event type.
        Parameters:
        eventType - Event type for which the filters are to be retrieved.
        Returns:
        Immutable set of attached filters. Empty list if none exists.
      • getAllRegisteredEventTypes

        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.
        Returns:
        Unmodifiable set of all event types registered with this event bus.