Class ListenerSet<T>

  • Type Parameters:
    T - The listener type.

    public final class ListenerSet<T>
    extends Object
    A set of listeners.

    Events are guaranteed to arrive in the order in which they happened even if a new event is triggered recursively from another listener.

    Events are also guaranteed to be only sent to the listeners registered at the time the event was enqueued and haven't been removed since.

    • Method Detail

      • add

        public void add​(T listener)
        Adds a listener to the set.

        If a listener is already present, it will not be added again.

        Parameters:
        listener - The listener to be added.
      • remove

        public void remove​(T listener)
        Removes a listener from the set.

        If the listener is not present, nothing happens.

        Parameters:
        listener - The listener to be removed.
      • queueEvent

        public void queueEvent​(int eventFlag,
                               ListenerSet.Event<T> event)
        Adds an event that is sent to the listeners when flushEvents() is called.
        Parameters:
        eventFlag - An integer indicating the type of the event, or C.INDEX_UNSET to report this event without flag.
        event - The event.
      • flushEvents

        public void flushEvents()
        Notifies listeners of events previously enqueued with queueEvent(int, Event).
      • sendEvent

        public void sendEvent​(int eventFlag,
                              ListenerSet.Event<T> event)
        Queues a single event and immediately flushes the event queue to notify all listeners.
        Parameters:
        eventFlag - An integer flag indicating the type of the event, or C.INDEX_UNSET to report this event without flag.
        event - The event.
      • release

        public void release()
        Releases the set of listeners immediately.

        This will ensure no events are sent to any listener after this method has been called.

      • lazyRelease

        public void lazyRelease​(int releaseEventFlag,
                                ListenerSet.Event<T> releaseEvent)
        Releases the set of listeners after all already scheduled Looper messages were able to trigger final events.

        After the specified released callback event, no other events are sent to a listener.

        Parameters:
        releaseEventFlag - An integer flag indicating the type of the release event, or C.INDEX_UNSET to report this event without a flag.
        releaseEvent - The release event.