Package com.io7m.jpuddle.core
Class JPPoolSynchronous<K,T extends U,U,C>
java.lang.Object
com.io7m.jpuddle.core.JPPoolSynchronous<K,T,U,C>
- Type Parameters:
K- The type of keysT- The type of internal pooled valuesU- The type of user-visible pooled valuesC- The type of context values
- All Implemented Interfaces:
JPPoolSynchronousType<K,,T, U, C> JPPoolSynchronousUsableType<K,T, U, C>
public final class JPPoolSynchronous<K,T extends U,U,C>
extends Object
implements JPPoolSynchronousType<K,T,U,C>
The default implementation of the
JPPoolSynchronousType interface.-
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteSafely(C context) Delete all items in the pool and shut the pool down.voiddeleteUnsafely(C context) Delete all items in the pool and shut the pool down.Retrieve an object from the pool, creating it if necessary.booleanstatic <K,T extends U, U, C>
JPPoolSynchronous<K,T, U, C> newPool(JPPoolableListenerType<K, T, C> listener, long soft_limit, long hard_limit) Construct a new pool.voidreturnValue(C context, U value) Return an object to the pool for re-use by later calls toJPPoolSynchronousUsableType.get(Object, Object).longsize()voidTrim free objects within the pool to reduce the pool size.
-
Method Details
-
newPool
public static <K,T extends U, JPPoolSynchronous<K,U, C> T, newPoolU, C> (JPPoolableListenerType<K, T, C> listener, long soft_limit, long hard_limit) Construct a new pool. The size of the pool will never exceedhard_limit, and free (unused) objects within the pool will be frequently trimmed so that the size of the pool stays at (at most)soft_limit.- Type Parameters:
K- The type of keysT- The type of valuesU- The type of user-visible pooled valuesC- The type of contextual values- Parameters:
listener- The listener that will manipulate objects within the poolsoft_limit- The soft size limithard_limit- The hard size limit- Returns:
- A new pool
-
isDeleted
public boolean isDeleted() -
trim
Description copied from interface:JPPoolSynchronousUsableTypeTrim free objects within the pool to reduce the pool size.- Specified by:
trimin interfaceJPPoolSynchronousUsableType<K,T extends U, U, C> - Parameters:
context- A context value- Throws:
JPPoolException- On errors
-
get
Description copied from interface:JPPoolSynchronousUsableTypeRetrieve an object from the pool, creating it if necessary.- Specified by:
getin interfaceJPPoolSynchronousUsableType<K,T extends U, U, C> - Parameters:
context- A context valuekey- The key that will be used to construct or retrieve the object- Returns:
- A new (or reused) object
- Throws:
JPPoolObjectCreationException- On exceptions raised during creation of objectsJPPoolException- On errors
-
returnValue
Description copied from interface:JPPoolSynchronousUsableTypeReturn an object to the pool for re-use by later calls toJPPoolSynchronousUsableType.get(Object, Object).- Specified by:
returnValuein interfaceJPPoolSynchronousUsableType<K,T extends U, U, C> - Parameters:
context- A context valuevalue- A value- Throws:
JPPoolException- On errorsJPPoolObjectReturnException- If the given value is not in the pool, or has already been returned
-
size
public long size() -
deleteSafely
Description copied from interface:JPPoolSynchronousTypeDelete all items in the pool and shut the pool down. The method will refuse to delete the pool if any items are yet to be returned.- Specified by:
deleteSafelyin interfaceJPPoolSynchronousType<K,T extends U, U, C> - Parameters:
context- A context value- Throws:
JPPoolException- Iff any of the items in the pool have yet to be returned
-
deleteUnsafely
Description copied from interface:JPPoolSynchronousTypeDelete all items in the pool and shut the pool down. The method will delete the pool even if there are items yet to be returned.- Specified by:
deleteUnsafelyin interfaceJPPoolSynchronousType<K,T extends U, U, C> - Parameters:
context- A context value- Throws:
JPPoolException- On errors
-