Top Description Inners Fields Constructors Methods
org.newsclub.net.unix.pool

public final Class ConcurrentQueueObjectPool<O>

extends Object
implements ObjectPool<O>
Class Inheritance
All Implemented Interfaces
org.newsclub.net.unix.pool.ObjectPool
Type Parameters
<O>
The object type.
Imports
java.util.Objects, .Queue, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicInteger, org.eclipse.jdt.annotation.NonNull, .Nullable

An ObjectPool implemented using ConcurrentLinkedQueue.
Author
Christian Kohlschütter

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final AtomicInteger
private final int
private final Queue<O>
private final ObjectPool.ObjectSanitizer<O>
private final ObjectPool.ObjectSupplier<O>

Constructor Summary

AccessConstructor and Description
public
ConcurrentQueueObjectPool(ObjectPool.ObjectSupplier<@NonNull O>
The supplier.
supplier
,
ObjectPool.ObjectSanitizer<@NonNull O>
The sanitizer.
sanitizer
,
final int
The maximum capacity.
maxCapacity
)

Constructs a ConcurrentQueueObjectPool with the given capacity, supplier and sanitizer.

Method Summary

Modifier and TypeMethod and Description
public ObjectPool.Lease<O>
take()

Implements org.newsclub.net.unix.pool.ObjectPool.take.

Takes an exclusive lease of an object from the pool.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private final AtomicInteger count
maxCapacityback to summary
private final int maxCapacity
queueback to summary
private final Queue<O> queue
sanitizerback to summary
private final ObjectPool.ObjectSanitizer<O> sanitizer
supplierback to summary
private final ObjectPool.ObjectSupplier<O> supplier

Constructor Detail

ConcurrentQueueObjectPoolback to summary
public ConcurrentQueueObjectPool(ObjectPool.ObjectSupplier<@NonNull O> supplier, ObjectPool.ObjectSanitizer<@NonNull O> sanitizer, final int maxCapacity)

Constructs a ConcurrentQueueObjectPool with the given capacity, supplier and sanitizer.

Parameters
supplier:ObjectPool.ObjectSupplier<@NonNull O>

The supplier.

sanitizer:ObjectPool.ObjectSanitizer<@NonNull O>

The sanitizer.

maxCapacity:int

The maximum capacity.

Method Detail

takeback to summary
public ObjectPool.Lease<O> take()

Implements org.newsclub.net.unix.pool.ObjectPool.take.

Doc from org.newsclub.net.unix.pool.ObjectPool.take.

Takes an exclusive lease of an object from the pool. If no existing object is available from the pool, a new one may be provided.

Returns:ObjectPool.Lease<O>

The object.

Annotations
@Override
org.newsclub.net.unix.pool back to summary

private final Class ConcurrentQueueObjectPool.LeaseImpl

extends Object
implements ObjectPool.Lease<O>
Class Inheritance
  • java.lang.Object
  • org.newsclub.net.unix.pool.ConcurrentQueueObjectPool.LeaseImpl
All Implemented Interfaces
org.newsclub.net.unix.pool.ObjectPool.Lease, java.io.Closeable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private @Nullable O

Constructor Summary

AccessConstructor and Description
public
LeaseImpl(O obj)

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Implements org.newsclub.net.unix.pool.ObjectPool.Lease.close.

Terminates the validity of this lease.

public void
discard()

Implements org.newsclub.net.unix.pool.ObjectPool.Lease.discard.

Marks the leased object as discarded, potentially preventing it from being reused in the object pool.

public O
get()

Implements org.newsclub.net.unix.pool.ObjectPool.Lease.get.

Returns the leased object, potentially null when discarded/closed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

objback to summary
private @Nullable O obj

Constructor Detail

LeaseImplback to summary
public LeaseImpl(O obj)

Method Detail

closeback to summary
public synchronized void close()

Implements org.newsclub.net.unix.pool.ObjectPool.Lease.close.

Doc from org.newsclub.net.unix.pool.ObjectPool.Lease.close.

Terminates the validity of this lease. Unless discarded via discard(), the object may end up back in the object pool it was leased from; however that is decided by the pool.

Annotations
@Override
discardback to summary
public void discard()

Implements org.newsclub.net.unix.pool.ObjectPool.Lease.discard.

Doc from org.newsclub.net.unix.pool.ObjectPool.Lease.discard.

Marks the leased object as discarded, potentially preventing it from being reused in the object pool.

Annotations
@Override
getback to summary
public O get()

Implements org.newsclub.net.unix.pool.ObjectPool.Lease.get.

Doc from org.newsclub.net.unix.pool.ObjectPool.Lease.get.

Returns the leased object, potentially null when discarded/closed.

Returns:O

The object, or null.

Annotations
@SuppressWarnings:null
@Override