Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util

public Class LockedPool<P>

extends Pool.Wrapper<P>
Class Inheritance
Type Parameters
<P>
the type of the pooled objects
Imports
java.util.Collection, java.util.function.Function, java.util.stream.Collectors, .Stream, org.eclipse.jetty.util.thread.AutoLock

A Pool.Wrapper that tracks the acquire/release/remove pool events.

The acquire/release/remove pool events are forwarded atomically to be handled by a Tracker implementation, so that the pool event and the handling of the event by the tracker are atomic.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
LockedPool.Factory<
the type of pooled objects
F
>

A Pool.Factory that wraps newly created Pool instances with LockedPool.

private class
public static interface
LockedPool.Tracker<
the type of pooled objects
T
>

A receiver of Pool events.

Field Summary

Modifier and TypeField and Description
private final AutoLock
private final LockedPool.Tracker<P>

Constructor Summary

AccessConstructor and Description
public
LockedPool(Pool<P> pool)

public
LockedPool(Pool<P> pool, LockedPool.Tracker<P> tracker)

Method Summary

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

Overrides org.eclipse.jetty.util.Pool.Wrapper.acquire.

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

Acquires an entry from the pool.

public Pool.Entry<P>
acquire(Function<Pool.Entry<P>, P>
a function to create the pooled value for a reserved entry.
creator
)

Overrides org.eclipse.jetty.util.Pool.Wrapper.acquire.

Overrides default org.eclipse.jetty.util.Pool.acquire.

Acquires an entry from the pool, reserving and creating a new entry if necessary.

public int
public boolean
public Pool.Entry<P>
reserve()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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>>
Inherited from org.eclipse.jetty.util.Pool.Wrapper:
getIdleCountgetInUseCountgetReservedCountgetTerminatedCountgetWrapped

Field Detail

lockback to summary
private final AutoLock lock
trackerback to summary
private final LockedPool.Tracker<P> tracker

Constructor Detail

LockedPoolback to summary
public LockedPool(Pool<P> pool)
LockedPoolback to summary
public LockedPool(Pool<P> pool, LockedPool.Tracker<P> tracker)

Method Detail

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

Overrides org.eclipse.jetty.util.Pool.Wrapper.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
acquireback to summary
public Pool.Entry<P> acquire(Function<Pool.Entry<P>, P> creator)

Overrides org.eclipse.jetty.util.Pool.Wrapper.acquire.

Overrides default org.eclipse.jetty.util.Pool.acquire.

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

Acquires an entry from the pool, reserving and creating a new entry if necessary.

Parameters
creator:Function<Pool.Entry<P>, P>

a function to create the pooled value for a reserved entry.

Returns:Pool.Entry<P>

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

Annotations
@Override
getMaxSizeback to summary
public int getMaxSize()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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
reserveback to summary
public Pool.Entry<P> reserve()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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()

Overrides org.eclipse.jetty.util.Pool.Wrapper.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.util back to summary

public Interface LockedPool.Factory<F>

extends Pool.Factory<F>
Type Parameters
<F>
the type of pooled objects

A Pool.Factory that wraps newly created Pool instances with LockedPool.

Method Summary

Modifier and TypeMethod and Description
public default Pool<F>
wrap(Pool<F>
the pool to wrap
pool
)

Overrides default org.eclipse.jetty.util.Pool.Factory.wrap.

Wraps, if necessary, the given pool.

Inherited from org.eclipse.jetty.util.Pool.Factory:
newPool

Method Detail

wrapback to summary
public default Pool<F> wrap(Pool<F> pool)

Overrides default org.eclipse.jetty.util.Pool.Factory.wrap.

Doc from org.eclipse.jetty.util.Pool.Factory.wrap.

Wraps, if necessary, the given pool.

Parameters
pool:Pool<F>

the pool to wrap

Returns:Pool<F>

a possibly wrapped pool

Annotations
@Override
org.eclipse.jetty.util back to summary

private Class LockedPool.LockedEntry

extends Pool.Entry.Wrapper<P>
Class Inheritance

Constructor Summary

AccessConstructor and Description
public
LockedEntry(Pool.Entry<P> wrapped)

Method Summary

Modifier and TypeMethod and Description
public boolean
public boolean
Inherited from org.eclipse.jetty.util.Pool.Entry.Wrapper:
enablegetPooledgetWrappedisIdleisInUseisReservedisTerminated

Constructor Detail

LockedEntryback to summary
public LockedEntry(Pool.Entry<P> wrapped)

Method Detail

releaseback to summary
public boolean release()

Overrides org.eclipse.jetty.util.Pool.Entry.Wrapper.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()

Overrides org.eclipse.jetty.util.Pool.Entry.Wrapper.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
org.eclipse.jetty.util back to summary

public Interface LockedPool.Tracker<T>

Type Parameters
<T>
the type of pooled objects

A receiver of Pool events.

A simple implementations may just count acquire/release/remove pool events via, respectively, acquired(Pool, Entry), released(Pool, Entry) and removed(Pool, Entry), and make sure that the count is 0 when terminated(Pool, Collection) is called.

More advanced implementations may also obtain a stack trace at the time of the event to troubleshoot leaking of pooled entries.

Method Summary

Modifier and TypeMethod and Description
public default void
acquired(Pool<T>
the pool
pool
,
Pool.Entry<T>
the acquired entry
entry
)

Callback method invoked when an entry is acquired.

public static <
the type of pooled objects
S
>
LockedPool.Tracker<S>

Returns:

a no-op implementation of Tracker
noTracker
()

public default void
released(Pool<T>
the pool
pool
,
Pool.Entry<T>
the released entry
entry
)

Callback method invoked when an entry is released.

public default void
removed(Pool<T>
the pool
pool
,
Pool.Entry<T>
the removed entry
entry
)

Callback method invoked when an entry is removed.

public default void
terminated(Pool<T>
the pool
pool
,
Collection<Pool.Entry<T>>
the list of entries at termination
entries
)

Callback method invoked when the Pool is terminated.

Method Detail

acquiredback to summary
public default void acquired(Pool<T> pool, Pool.Entry<T> entry)

Callback method invoked when an entry is acquired.

Parameters
pool:Pool<T>

the pool

entry:Pool.Entry<T>

the acquired entry

noTrackerback to summary
public static <S> LockedPool.Tracker<S> noTracker()
Parameters
<S>
the type of pooled objects
Returns:LockedPool.Tracker<S>

a no-op implementation of Tracker

Annotations
@SuppressWarnings:unchecked
releasedback to summary
public default void released(Pool<T> pool, Pool.Entry<T> entry)

Callback method invoked when an entry is released.

Parameters
pool:Pool<T>

the pool

entry:Pool.Entry<T>

the released entry

removedback to summary
public default void removed(Pool<T> pool, Pool.Entry<T> entry)

Callback method invoked when an entry is removed.

Parameters
pool:Pool<T>

the pool

entry:Pool.Entry<T>

the removed entry

terminatedback to summary
public default void terminated(Pool<T> pool, Collection<Pool.Entry<T>> entries)

Callback method invoked when the Pool is terminated.

Parameters
pool:Pool<T>

the pool

entries:Collection<Pool.Entry<T>>

the list of entries at termination