com.neeve.util
Class UtlPool<T extends UtlPool.Item<T>>

java.lang.Object
  extended by com.neeve.util.UtlPool<T>

public final class UtlPool<T extends UtlPool.Item<T>>
extends Object

Implements a pool to recycle objects.

This class implements a pool used to recycle objects.

This class IS NOT intended to be used by end users.


Nested Class Summary
static interface UtlPool.Factory<T extends UtlPool.Item<T>>
          Defines the factory used by the pool to create new objects
static interface UtlPool.FlushedItemReceiver<T extends UtlPool.Item<T>>
          Interface through which flushed items are dispatched to the user
static interface UtlPool.Item<T extends UtlPool.Item<T>>
          Defines a 'poolable' item.
static class UtlPool.Params
          Specifies pool operating parameters.
 class UtlPool.Stats
          Stores pool statistics
 
Field Summary
static boolean POOL_LEAK_TYPE_TRACKING_ENABLED
           
 
Method Summary
 int capacity()
          Return the current pool capacity
 void close()
          Close the pool
static
<T extends UtlPool.Item<T>>
UtlPool<T>
create(String type, String name, UtlPool.Factory<T> factory, UtlPool.Params params)
          Create a new object pool.
static
<T extends UtlPool.Item<T>>
UtlPool<T>[]
createPoolArray(int size)
          Creates an empty UtlPool array of the give size.
 void flush(UtlPool.FlushedItemReceiver<T> receiver)
          Flush the pool
 T get(Object object)
          Get an item from an object pool.
 boolean isClosed()
           
static boolean isDetachedWashEnabled()
          Get whether detached wash is enabled
static boolean isLockFreeConcurrencyEnabled()
          Get whether lock free concurrency is enabled or not
 String key()
          Get a pool's systemwide unique key
 String name()
          Get a pool's name
 UtlPool.Params params()
          Gets the creation UtlPool.Params for the pool.
 void put(T item)
          Release an item back into the pool
 void setSingleThreaded()
          Switch off threaded operation
 int size()
          Return the number of items in the pool
 UtlPool.Stats stats()
          Get the pool's statistics object
 String type()
          Get a pool's type
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POOL_LEAK_TYPE_TRACKING_ENABLED

public static final boolean POOL_LEAK_TYPE_TRACKING_ENABLED
Method Detail

create

public static <T extends UtlPool.Item<T>> UtlPool<T> create(String type,
                                                            String name,
                                                            UtlPool.Factory<T> factory,
                                                            UtlPool.Params params)
Create a new object pool.

Parameters:
type - The pool's type
name - The pool's unique name within its type. The pool's type and name together serve as a pool's unique system-wide key.
factory - The factory to be used to create objects stored by the pool being created.
params - Specifies pool operating parameters.

createPoolArray

public static final <T extends UtlPool.Item<T>> UtlPool<T>[] createPoolArray(int size)
Creates an empty UtlPool array of the give size.

Parameters:
size - The size of the array.
Returns:
an empty UtlPool array of the give size.

isLockFreeConcurrencyEnabled

public static final boolean isLockFreeConcurrencyEnabled()
Get whether lock free concurrency is enabled or not


isDetachedWashEnabled

public static final boolean isDetachedWashEnabled()
Get whether detached wash is enabled


type

public final String type()
Get a pool's type


name

public final String name()
Get a pool's name


key

public final String key()
Get a pool's systemwide unique key


setSingleThreaded

public final void setSingleThreaded()
Switch off threaded operation


get

public final T get(Object object)
Get an item from an object pool.

Parameters:
object - A user object passed to the item factory in case the pool is empty and an item needs to be created fresh.
Returns:
an item from an object pool.

put

public final void put(T item)
Release an item back into the pool


size

public final int size()
Return the number of items in the pool


capacity

public final int capacity()
Return the current pool capacity


stats

public final UtlPool.Stats stats()
Get the pool's statistics object


params

public final UtlPool.Params params()
Gets the creation UtlPool.Params for the pool.

When a pool is created its UtlPool.Params are cloned and marked as read only. This method allows the caller to determine the UtlPool.Params with which the pool was created.

Returns:
the pool's creation UtlPool.Params.

flush

public final void flush(UtlPool.FlushedItemReceiver<T> receiver)
Flush the pool

Parameters:
receiver - Receives the flushed items. This parameter can be null.

This method flushes all pool entries.


isClosed

public final boolean isClosed()

close

public final void close()
Close the pool



Copyright © 2016 Neeve Research, LLC. All Rights Reserved.