public abstract class AbstractResourcePool<T extends PooledObject> extends Object implements ResourcePool<T>
ResourcePool that relies on an internal queue to maintain the collection of resources.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractResourcePool(Queue<T> resources,
int initialCapacity) |
| Modifier and Type | Method and Description |
|---|---|
int |
count()
Counts the number of idle elements in the pool.
|
protected abstract T |
createResource() |
boolean |
isEmpty()
Checks whether the pool contains at least one element.
|
void |
offer(T resource)
Offers an object to be placed into the pool.
|
T |
poll()
Polls an object from the pool.
If the pool is empty, a new object shall be created. |
protected void |
populate()
Populates the pool with new objects until the initial capacity is reached.
|
void |
release()
Releases all resources held by the pool.
|
int |
size()
Gets the maximum size of the pool.
|
protected void populate()
IMPORTANT: This method should be manually invoked by the constructor of each implementation.
The reason is that some more complex objects require dependencies or factories.
public T poll()
ResourcePoolpoll in interface ResourcePool<T extends PooledObject>public void offer(T resource)
ResourcePooloffer in interface ResourcePool<T extends PooledObject>resource - The object to be placed into the pool.public void release()
ResourcePoolrelease in interface ResourcePool<T extends PooledObject>public int count()
ResourcePoolcount in interface ResourcePool<T extends PooledObject>public int size()
ResourcePoolsize in interface ResourcePool<T extends PooledObject>public boolean isEmpty()
ResourcePoolisEmpty in interface ResourcePool<T extends PooledObject>true is empty, false otherwise.protected abstract T createResource()
Copyright © 2017 TeleStax, Inc.. All Rights Reserved.