Class SubscriptionHolder
- java.lang.Object
-
- org.ovirt.vdsm.jsonrpc.client.events.SubscriptionHolder
-
public class SubscriptionHolder extends java.lang.ObjectHolds subscription information such as amount of messages requested byEventSubscriber. When events are not processed immediately they are queued in here. This holder contains instance of subscription itself.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicLongcountstatic java.util.function.LongUnaryOperatorDECREMENT_ONLY_POSITIVEprivate java.util.Deque<JsonRpcEvent>eventsprivate java.util.List<java.lang.String>filteredIdprivate java.util.concurrent.locks.Locklockprivate java.lang.String[]parsedIdprivate EventSubscribersubscriber
-
Constructor Summary
Constructors Constructor Description SubscriptionHolder(EventSubscriber subscriber)Creates a holder which subscriber instance and count and it prepares subscription id representation for event matching.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanProcess()JsonRpcEventcanProcessMore()voidclean()Clean event queue.private voidfilter()java.util.List<java.lang.String>getFilteredId()java.lang.StringgetId()intgetNumberOfEvents()java.lang.String[]getParsedId()EventSubscribergetSubscriber()longincrementCount(long n)voidpurgeOldEventsIfNotConsumed(int eventTimeoutInHours)Purge old events if they have not been consumed in a specified amount of time.voidputEvent(JsonRpcEvent event)Queues not processed event for later processing.
-
-
-
Field Detail
-
DECREMENT_ONLY_POSITIVE
public static final java.util.function.LongUnaryOperator DECREMENT_ONLY_POSITIVE
-
subscriber
private final EventSubscriber subscriber
-
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 @linkEventSubscriber.
-
-
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)
-
-