ExpiryQueue (Apache ZooKeeper - Server 3.7.0 API)
Date: 2021-03-17

org.apache.zookeeper.server

## Class ExpiryQueue<E>

- java.lang.Object
- - org.apache.zookeeper.server.ExpiryQueue<E>

-     public class ExpiryQueue<E>
      extends Object

  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
    Constructor and Description
    `ExpiryQueue(int expirationInterval)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `dump(PrintWriter pwriter)`
    `Map<Long,Set<E>>` | `getExpiryMap()` Returns an unmodifiable view of the expiration time -> elements mapping.
    `long` | `getWaitTime()`
    `Set<E>` | `poll()` Remove the next expired set of elements from expireMap.
    `Long` | `remove(E elem)` Removes element from the queue.
    `Long` | `update(E elem, int timeout)` Adds or updates expiration time for element in queue, rounding the timeout to the expiry interval bucketed used by this queue.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExpiryQueue

          public ExpiryQueue(int expirationInterval)

  - ### Method Detail

    - #### remove

          public Long remove(E elem)

      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

          public Long update(E elem,
                             int timeout)

      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/update
        `timeout` - 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

          public Set<E> 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

          public void dump(PrintWriter pwriter)

    - #### getExpiryMap

          public Map<Long,Set<E>> getExpiryMap()

      Returns an unmodifiable view of the expiration time -> elements mapping.

Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.