Class Subscription<T>

  • Type Parameters:
    T - the type of messages of the Channel
    All Implemented Interfaces:
    Action<T>

    public final class Subscription<T>
    extends Object
    implements Action<T>
    A Subscription object manages a list of Subscribers. Each message is distributed to each Subscriber, if no exception occurred.
    See Also:
    EventMaid Documentation
    • Constructor Detail

      • Subscription

        public Subscription()
    • Method Detail

      • subscription

        public static <T> Subscription<T> subscription()
        Creates a new Subscription object.
        Type Parameters:
        T - the type of messages of the Channel
        Returns:
        a new Subscription object
      • addSubscriber

        public SubscriptionId addSubscriber​(Consumer<T> consumer)
        Adds a the consumer wrapped in a Subscriber object.
        Parameters:
        consumer - the consuming Subscriber to be added
        Returns:
        the wrapping Subscriber's SubscriptionId
      • addSubscriber

        public SubscriptionId addSubscriber​(Subscriber<T> subscriber)
        Adds a Subscriber.
        Parameters:
        subscriber - the Subscriber to be added
        Returns:
        the wrapping Subscriber's SubscriptionId
      • addRawSubscriber

        public SubscriptionId addRawSubscriber​(Consumer<ProcessingContext<T>> consumer)
        Adds a the consumer wrapped in a Subscriber object, that gets access to the underlying ProcessingContext object.
        Parameters:
        consumer - the consuming Subscriber to be added
        Returns:
        the wrapping Subscriber's SubscriptionId
      • addRawSubscriber

        public SubscriptionId addRawSubscriber​(Subscriber<ProcessingContext<T>> subscriber)
        Adds a Subscriber, that gets access to the underlying ProcessingContext object.
        Parameters:
        subscriber - the Subscriber to be added
        Returns:
        the wrapping Subscriber's SubscriptionId
      • hasSubscribers

        public boolean hasSubscribers()
        Returns if at least one subscriber exists.
        Returns:
        true if at least one Subscriber exists, false otherwise
      • removeSubscriber

        public void removeSubscriber​(Subscriber<?> subscriber)
        Removes the given Subscriber.
        Parameters:
        subscriber - the Subscriber to be removed
      • removeSubscriber

        public void removeSubscriber​(SubscriptionId subscriptionId)
        Removes all Subscribers that match the given SubscriptionId.
        Parameters:
        subscriptionId - the SubscriptionId, for which all Subscribers should be removed.