Class QueuedPool<P>

java.lang.Object
org.eclipse.jetty.io.internal.QueuedPool<P>
Type Parameters:
P - the type of the pooled objects
All Implemented Interfaces:
Pool<P>

public class QueuedPool<P> extends Object implements Pool<P>

A Queue based implementation of Pool.

Entries are taken out of the pool when they are acquired and they are added back when they are released which means acquired and reserved entries do not account for the maxSize calculation. This also means QueuedPool is resistant to "release leaks".

This implementation does not support multiplexing.

  • Constructor Details

    • QueuedPool

      public QueuedPool(int maxSize)
  • Method Details

    • reserve

      public Pool.Entry<P> reserve()
      Description copied from interface: Pool

      Creates a new disabled slot into the pool.

      The returned entry must ultimately have the Pool.Entry.enable(Object, boolean) method called or be removed via Pool.Entry.remove().

      Specified by:
      reserve in interface Pool<P>
      Returns:
      a disabled entry that is contained in the pool, or null if the pool is terminated or if the pool cannot reserve an entry
    • acquire

      public Pool.Entry<P> acquire()
      Description copied from interface: Pool

      Acquires an entry from the pool.

      Only enabled entries will be returned from this method and their Pool.Entry.enable(Object, boolean) method must not be called.

      Specified by:
      acquire in interface Pool<P>
      Returns:
      an entry from the pool or null if none is available.
    • isTerminated

      public boolean isTerminated()
      Specified by:
      isTerminated in interface Pool<P>
      Returns:
      whether this Pool has been terminated
      See Also:
    • terminate

      public Collection<Pool.Entry<P>> terminate()
      Description copied from interface: Pool

      Terminates this Pool.

      All the entries are marked as terminated and cannot be acquired nor released, but only removed.

      The returned list of all entries may be iterated to perform additional operations on the pooled objects.

      The pool cannot be used anymore after it is terminated.

      Specified by:
      terminate in interface Pool<P>
      Returns:
      a list of all entries
    • size

      public int size()
      Specified by:
      size in interface Pool<P>
      Returns:
      the current number of entries in this Pool
    • getMaxSize

      public int getMaxSize()
      Specified by:
      getMaxSize in interface Pool<P>
      Returns:
      the maximum number of entries in this Pool
    • stream

      public Stream<Pool.Entry<P>> stream()
      Specified by:
      stream in interface Pool<P>
      Returns:
      a Stream over the entries
    • getReservedCount

      public int getReservedCount()
      Specified by:
      getReservedCount in interface Pool<P>
      Returns:
      the number of reserved entries
    • getIdleCount

      public int getIdleCount()
      Specified by:
      getIdleCount in interface Pool<P>
      Returns:
      the number of idle entries
    • getInUseCount

      public int getInUseCount()
      Specified by:
      getInUseCount in interface Pool<P>
      Returns:
      the number of in-use entries
    • getTerminatedCount

      public int getTerminatedCount()
      Specified by:
      getTerminatedCount in interface Pool<P>
      Returns:
      the number of terminated entries