Top Description Inners Fields Constructors Methods
org.eclipse.jetty.io.internal

public Class QueuedPool<P>

extends Object
implements Pool<P>
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Pool
Type Parameters
<P>
the type of the pooled objects
Imports
java.util.ArrayList, .Collection, .Objects, .Queue, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicInteger, .AtomicMarkableReference, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock, java.util.stream.Stream, org.eclipse.jetty.util.Pool

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final int
private final Queue<Pool.Entry<P>>
private final AtomicInteger
private final ReadWriteLock
private boolean

Constructor Summary

AccessConstructor and Description
public
QueuedPool(int maxSize)

Method Summary

Modifier and TypeMethod and Description
public Pool.Entry<P>
acquire()

Implements org.eclipse.jetty.util.Pool.acquire.

Acquires an entry from the pool.

public int
public boolean
private boolean
requeue(Pool.Entry<P> entry)

public Pool.Entry<P>
reserve()

Implements org.eclipse.jetty.util.Pool.reserve.

Creates a new disabled slot into the pool.

public int
public Stream<Pool.Entry<P>>
public Collection<Pool.Entry<P>>
terminate()

Implements org.eclipse.jetty.util.Pool.terminate.

Terminates this Pool.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

maxSizeback to summary
private final int maxSize
queueback to summary
private final Queue<Pool.Entry<P>> queue
queueSizeback to summary
private final AtomicInteger queueSize
rwLockback to summary
private final ReadWriteLock rwLock
terminatedback to summary
private boolean terminated

Constructor Detail

QueuedPoolback to summary
public QueuedPool(int maxSize)

Method Detail

acquireback to summary
public Pool.Entry<P> acquire()

Implements org.eclipse.jetty.util.Pool.acquire.

Doc from org.eclipse.jetty.util.Pool.acquire.

Acquires an entry from the pool.

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

Returns:Pool.Entry<P>

an entry from the pool or null if none is available.

Annotations
@Override
getMaxSizeback to summary
public int getMaxSize()

Implements org.eclipse.jetty.util.Pool.getMaxSize.

Returns:int

Doc from org.eclipse.jetty.util.Pool.getMaxSize.

the maximum number of entries in this Pool

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Implements org.eclipse.jetty.util.Pool.isTerminated.

Returns:boolean

Doc from org.eclipse.jetty.util.Pool.isTerminated.

whether this Pool has been terminated

Annotations
@Override
requeueback to summary
private boolean requeue(Pool.Entry<P> entry)
reserveback to summary
public Pool.Entry<P> reserve()

Implements org.eclipse.jetty.util.Pool.reserve.

Doc from org.eclipse.jetty.util.Pool.reserve.

Creates a new disabled slot into the pool.

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

Returns:Pool.Entry<P>

a disabled entry that is contained in the pool, or null if the pool is terminated or if the pool cannot reserve an entry

Annotations
@Override
sizeback to summary
public int size()

Implements org.eclipse.jetty.util.Pool.size.

Returns:int

Doc from org.eclipse.jetty.util.Pool.size.

the current number of entries in this Pool

Annotations
@Override
streamback to summary
public Stream<Pool.Entry<P>> stream()

Implements org.eclipse.jetty.util.Pool.stream.

Returns:Stream<Pool.Entry<P>>

Doc from org.eclipse.jetty.util.Pool.stream.

a Stream over the entries

Annotations
@Override
terminateback to summary
public Collection<Pool.Entry<P>> terminate()

Implements org.eclipse.jetty.util.Pool.terminate.

Doc from org.eclipse.jetty.util.Pool.terminate.

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.

Returns:Collection<Pool.Entry<P>>

a list of all entries

Annotations
@Override
org.eclipse.jetty.io.internal back to summary

private Class QueuedPool.QueuedEntry<P>

extends Object
implements Pool.Entry<P>
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Pool.Entry

Field Summary

Modifier and TypeField and Description
private final QueuedPool<P>
private final AtomicMarkableReference<P>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public boolean
enable(P
the pooled object for this Entry
pooled
,
boolean
whether this Entry should be atomically enabled and acquired
acquire
)

Implements org.eclipse.jetty.util.Pool.Entry.enable.

Enables this, previously reserved, Entry.

public P
public boolean
public boolean
public boolean
public boolean
public boolean
release()

Implements org.eclipse.jetty.util.Pool.Entry.release.

Releases this Entry to the Pool.

public boolean
remove()

Implements org.eclipse.jetty.util.Pool.Entry.remove.

Removes this Entry from the Pool.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

poolback to summary
private final QueuedPool<P> pool
pooledback to summary
private final AtomicMarkableReference<P> pooled

Constructor Detail

QueuedEntryback to summary
private QueuedEntry(QueuedPool<P> pool)

Method Detail

acquireback to summary
pack-priv void acquire()
enableback to summary
public boolean enable(P pooled, boolean acquire)

Implements org.eclipse.jetty.util.Pool.Entry.enable.

Doc from org.eclipse.jetty.util.Pool.Entry.enable.

Enables this, previously reserved, Entry.

An entry returned from the reserve() method must be enabled with this method, once and only once, before it is usable by the pool.

The entry may be enabled and not acquired, in which case it is immediately available to be acquired, potentially by another thread; or it can be enabled and acquired atomically so that no other thread can acquire it, although the acquire may still fail if the pool has been terminated.

Parameters
pooled:P

the pooled object for this Entry

acquire:boolean

whether this Entry should be atomically enabled and acquired

Returns:boolean

whether this Entry was enabled

Annotations
@Override
getPooledback to summary
public P getPooled()

Implements org.eclipse.jetty.util.Pool.Entry.getPooled.

Returns:P

Doc from org.eclipse.jetty.util.Pool.Entry.getPooled.

the pooled object

Annotations
@Override
isIdleback to summary
public boolean isIdle()

Implements org.eclipse.jetty.util.Pool.Entry.isIdle.

Returns:boolean

Doc from org.eclipse.jetty.util.Pool.Entry.isIdle.

whether this Entry is idle in the Pool

Annotations
@Override
isInUseback to summary
public boolean isInUse()

Implements org.eclipse.jetty.util.Pool.Entry.isInUse.

Returns:boolean

Doc from org.eclipse.jetty.util.Pool.Entry.isInUse.

whether this Entry is in use

Annotations
@Override
isReservedback to summary
public boolean isReserved()

Implements org.eclipse.jetty.util.Pool.Entry.isReserved.

Returns:boolean

Doc from org.eclipse.jetty.util.Pool.Entry.isReserved.

whether this Entry is reserved

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Implements org.eclipse.jetty.util.Pool.Entry.isTerminated.

Returns:boolean

Doc from org.eclipse.jetty.util.Pool.Entry.isTerminated.

whether this Entry is terminated

Annotations
@Override
releaseback to summary
public boolean release()

Implements org.eclipse.jetty.util.Pool.Entry.release.

Doc from org.eclipse.jetty.util.Pool.Entry.release.

Releases this Entry to the Pool.

Returns:boolean

whether this Entry was released

Annotations
@Override
removeback to summary
public boolean remove()

Implements org.eclipse.jetty.util.Pool.Entry.remove.

Doc from org.eclipse.jetty.util.Pool.Entry.remove.

Removes this Entry from the Pool.

Returns:boolean

whether this Entry was removed

Annotations
@Override