Package org.apache.zookeeper.server
Class ExpiryQueue<E>
java.lang.Object
org.apache.zookeeper.server.ExpiryQueue<E>
ExpiryQueue tracks elements in time sorted fixed duration buckets.
It's used by SessionTrackerImpl to expire sessions and NIOServerCnxnFactory
to expire connections.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
dump
(PrintWriter pwriter) Returns an unmodifiable view of the expiration time -> elements mapping.long
poll()
Remove the next expired set of elements from expireMap.Removes element from the queue.Adds or updates expiration time for element in queue, rounding the timeout to the expiry interval bucketed used by this queue.
-
Constructor Details
-
ExpiryQueue
public ExpiryQueue(int expirationInterval)
-
-
Method Details
-
remove
Removes element from the queue.- Parameters:
elem
- element to remove- Returns:
- time at which the element was set to expire, or null if it wasn't present
-
update
Adds or updates expiration time for element in queue, rounding the timeout to the expiry interval bucketed used by this queue.- Parameters:
elem
- element to add/updatetimeout
- timout in milliseconds- Returns:
- time at which the element is now set to expire if changed, or null if unchanged
-
getWaitTime
public long getWaitTime()- Returns:
- milliseconds until next expiration time, or 0 if has already past
-
poll
Remove the next expired set of elements from expireMap. This method needs to be called frequently enough by checking getWaitTime(), otherwise there will be a backlog of empty sets queued up in expiryMap.- Returns:
- next set of expired elements, or an empty set if none are ready
-
dump
-
getExpiryMap
Returns an unmodifiable view of the expiration time -> elements mapping.
-