Class SubscriptionHolder


  • public class SubscriptionHolder
    extends java.lang.Object
    Holds subscription information such as amount of messages requested by EventSubscriber. When events are not processed immediately they are queued in here. This holder contains instance of subscription itself.
    • Field Detail

      • DECREMENT_ONLY_POSITIVE

        public static final java.util.function.LongUnaryOperator DECREMENT_ONLY_POSITIVE
      • events

        private final java.util.Deque<JsonRpcEvent> events
      • count

        private final java.util.concurrent.atomic.AtomicLong count
      • parsedId

        private final java.lang.String[] parsedId
      • filteredId

        private java.util.List<java.lang.String> filteredId
      • lock

        private final java.util.concurrent.locks.Lock lock
    • Constructor Detail

      • SubscriptionHolder

        public SubscriptionHolder​(EventSubscriber subscriber)
        Creates a holder which subscriber instance and count and it prepares subscription id representation for event matching.
        Parameters:
        subscriber - Instance of @link EventSubscriber.
    • Method Detail

      • getId

        public java.lang.String getId()
        Returns:
        subscription id as complete string e.q. <receiver>.<component>.<operation_id>.<unique_id>.
      • getParsedId

        public java.lang.String[] getParsedId()
        Returns:
        parsed subscription id as string array. Each entry represents subscription type.
      • filter

        private void filter()
      • getFilteredId

        public java.util.List<java.lang.String> getFilteredId()
        Returns:
        Filtered subscription id which do not contains all filter '*'
      • canProcess

        public boolean canProcess()
        Returns:
        Checks and return information whether subscriber can process events based on count defined.
      • canProcessMore

        public JsonRpcEvent canProcessMore()
        Returns:
        An event for processing if there is any and if subscriber is willing to process more events.
      • putEvent

        public void putEvent​(JsonRpcEvent event)
        Queues not processed event for later processing. When adding an event to the queue, set the arrival time of the event.
        Parameters:
        event - An event to be queued.
      • getNumberOfEvents

        public int getNumberOfEvents()
      • purgeOldEventsIfNotConsumed

        public void purgeOldEventsIfNotConsumed​(int eventTimeoutInHours)
        Purge old events if they have not been consumed in a specified amount of time.
        Parameters:
        eventTimeoutInHours - the timeout after which the events are purged from the queue.
      • getSubscriber

        public EventSubscriber getSubscriber()
        Returns:
        Subscribed hold by this instance.
      • clean

        public void clean()
        Clean event queue.
      • incrementCount

        public long incrementCount​(long n)