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

public Interface ObjectPool<O>

Known Direct Implementers
org.newsclub.net.unix.pool.ThreadLocalObjectPool, org.newsclub.net.unix.pool.VirtualAwareThreadLocalObjectPool, org.newsclub.net.unix.pool.ConcurrentQueueObjectPool
Type Parameters
<O>
The object type.
Imports
java.io.Closeable, org.eclipse.jdt.annotation.NonNull, org.newsclub.net.unix.ThreadUtil

A pool of objects.
Author
Christian Kohlschütter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ObjectPool.Lease<
The object type.
O
>

A lease for an object (obtained via get()); working with the object is only permitted before close().

public static interface
ObjectPool.ObjectSanitizer<
The object type.
T
>

Sanitizes a previously leased object so it can be reused by the pool.

public static interface
ObjectPool.ObjectSupplier<
The object type.
T
>

Supplies a leased object.

Method Summary

Modifier and TypeMethod and Description
public static <
The object type.
O
>
ObjectPool<O>

Returns:

The object pool.
newThreadLocalPool
(ObjectPool.ObjectSupplier<@NonNull O>
The object supplier.
supplier
,
ObjectPool.ObjectSanitizer<@NonNull O>
The object sanitizer.
sanitizer
)

Creates a new ObjectPool that is used within a single thread; this may or may not be implemented using ThreadLocal, however the behavior should be comparable.

public ObjectPool.Lease<O>

Returns:

The object.
take
()

Takes an exclusive lease of an object from the pool.

public static <
The object type.
O
>
ObjectPool.Lease<O>

Returns:

The lease; closing/discarding has no effect.
unpooledLease
(O
The object.
obj
)

Returns a Lease that is not backed by any object pool.

Method Detail

newThreadLocalPoolback to summary
public static <O> ObjectPool<O> newThreadLocalPool(ObjectPool.ObjectSupplier<@NonNull O> supplier, ObjectPool.ObjectSanitizer<@NonNull O> sanitizer)

Creates a new ObjectPool that is used within a single thread; this may or may not be implemented using ThreadLocal, however the behavior should be comparable.

Parameters
<O>
The object type.
supplier:ObjectPool.ObjectSupplier<@NonNull O>

The object supplier.

sanitizer:ObjectPool.ObjectSanitizer<@NonNull O>

The object sanitizer.

Returns:ObjectPool<O>

The object pool.

takeback to summary
public ObjectPool.Lease<O> 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.

unpooledLeaseback to summary
public static <O> ObjectPool.Lease<O> unpooledLease(O obj)

Returns a Lease that is not backed by any object pool.

Parameters
<O>
The object type.
obj:O

The object.

Returns:ObjectPool.Lease<O>

The lease; closing/discarding has no effect.

org.newsclub.net.unix.pool back to summary

public Interface ObjectPool.Lease<O>

extends Closeable
Known Direct Implementers
org.newsclub.net.unix.pool.ConcurrentQueueObjectPool.LeaseImpl
Type Parameters
<O>
The object type.

A lease for an object (obtained via get()); working with the object is only permitted before close().

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares java.io.Closeable.close.

Terminates the validity of this lease.

public void
discard()

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

public O

Returns:

The object, or null.
get
()

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

Method Detail

closeback to summary
public void close()

Redeclares java.io.Closeable.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()

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

getback to summary
public O get()

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

Returns:O

The object, or null.

org.newsclub.net.unix.pool back to summary

public Interface ObjectPool.ObjectSanitizer<T>

Annotations
@FunctionalInterface
Type Parameters
<T>
The object type.

Sanitizes a previously leased object so it can be reused by the pool.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if sanitization was successful, false if the object should not be reused.
sanitize
(T
The object to sanitize.
obj
)

Sanitizes a previously leased object so it can be reused by the pool; if the object should not be reused, false is returned.

Method Detail

sanitizeback to summary
public boolean sanitize(T obj)

Sanitizes a previously leased object so it can be reused by the pool; if the object should not be reused, false is returned.

Parameters
obj:T

The object to sanitize.

Returns:boolean

true if sanitization was successful, false if the object should not be reused.

org.newsclub.net.unix.pool back to summary

public Interface ObjectPool.ObjectSupplier<T>

Annotations
@FunctionalInterface
Type Parameters
<T>
The object type.

Supplies a leased object.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

a result
get
()

Gets a result.

Method Detail

getback to summary
public T get()

Gets a result.

Returns:T

a result