- java.lang.Object
-
- com.github.robtimus.pool.PoolableObject<None>
-
- com.github.robtimus.pool.ObjectWrapper<T>
-
- Type Parameters:
T
- The type of wrapped objects.
- All Implemented Interfaces:
AutoCloseable
public final class ObjectWrapper<T> extends PoolableObject<None> implements AutoCloseable
A poolable object that wraps a single value. Instances will always be considered valid and have no resources to release. This class implementsAutoCloseable
, which allows instances to be used in try-with-resources blocks; when an instance is closed it is returned to the pool.- Author:
- Rob Spoor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.robtimus.pool.PoolableObject
PoolableObject.Reference<X extends Exception>
-
-
Constructor Summary
Constructors Constructor Description ObjectWrapper(T value)
Creates a new object wrapper.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static <T> Pool<ObjectWrapper<T>,None>
newPool(PoolConfig config, Supplier<T> supplier, PoolLogger logger)
Creates a new pool ofObjectWrapper
instances.protected void
releaseResources()
Releases any resources associated with this object.String
toString()
protected boolean
validate()
Checks whether or not this object is still valid.T
value()
The wrapped value.-
Methods inherited from class com.github.robtimus.pool.PoolableObject
addReference, isEnabled, logEvent, logEvent, logEvent, logEvent, release
-
-
-
-
Constructor Detail
-
ObjectWrapper
public ObjectWrapper(T value)
Creates a new object wrapper.- Parameters:
value
- The value to wrap.
-
-
Method Detail
-
value
public T value()
The wrapped value.- Returns:
- The wrapped value.
-
validate
protected boolean validate()
Description copied from class:PoolableObject
Checks whether or not this object is still valid. Invalid object will be removed from the pool instead of being returned fromPool.acquire()
orPool.acquireNow()
. They will also have their resources released.- Specified by:
validate
in classPoolableObject<None>
- Returns:
true
if this object is still valid, orfalse
otherwise.
-
releaseResources
protected void releaseResources()
Description copied from class:PoolableObject
Releases any resources associated with this object.- Specified by:
releaseResources
in classPoolableObject<None>
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
newPool
public static <T> Pool<ObjectWrapper<T>,None> newPool(PoolConfig config, Supplier<T> supplier, PoolLogger logger)
Creates a new pool ofObjectWrapper
instances.- Type Parameters:
T
- The type of objects wrapped byObjectWrapper
instances in the pool.- Parameters:
config
- The configuration to use.supplier
- A supplier to serve as factory for wrapped objects.logger
- The logger to use to log events triggered by the pool or pooled objects.- Returns:
- The created pool.
- Throws:
NullPointerException
- If the given configuration, supplier or logger isnull
.
-
-