com.neeve.util
Class UtlPool.Params

java.lang.Object
  extended by com.neeve.util.UtlPool.Params
All Implemented Interfaces:
Cloneable
Enclosing class:
UtlPool<T extends UtlPool.Item<T>>

public static class UtlPool.Params
extends Object
implements Cloneable

Specifies pool operating parameters.

This class is used to specify the operating parameters of an object. pool. An instance of this class is provided to a pool during pool creation.

Note: Pool operating parameters must be set before pool creation. Changes to a parameters object after pool creation has no effect on the pool.

Threading:
This class is safe for concurrent access by multiple threads.

Method Summary
 Object clone()
          Clone the parameters object.
static UtlPool.Params create()
          Create a parameters object with default values.
 int getInitialCapacity()
          Get the initial pool capacity.
 int getMaxCapacity()
          Get the maximum pool capacity.
 boolean isDetachedWash()
          Get whether pool items will be washed using the detached washer
 boolean isPreallocate()
          Tests whether this pool was set to preallocate items up front.
 boolean isReadOnly()
          Tests whether the pool parameters are read only.
 boolean isThreaded()
          Get whether a pool is operating in a thread safe manner.
 UtlPool.Params load(String propertyPrefix, Map<String,Object> source, boolean override)
          Loads pool parameters from the given source Map.
 UtlPool.Params load(String propertyPrefix, Properties source, boolean override)
          Loads pool parameters from the given source properties.
 UtlPool.Params setDetachedWash(boolean val)
          Set whether pool items should be washed using the detached washer
 UtlPool.Params setInitialCapacity(int val)
          Set the initial pool capacity.
 UtlPool.Params setMaxCapacity(int val)
          Set the maximum pool capacity.
 UtlPool.Params setPreallocate(boolean preallocate)
          Sets whether items in the pool should be preallocated up front to avoid object promotions.
 UtlPool.Params setThreaded(boolean val)
          Set whether a pool will be accessed concurrently using multiple threads.
 String toString()
          Get a string representation of the parameter object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static UtlPool.Params create()
Create a parameters object with default values.

Returns:
Returns the created parameters object
Threading:
This method is safe for concurrent access by multiple threads.

load

public final UtlPool.Params load(String propertyPrefix,
                                 Properties source,
                                 boolean override)
Loads pool parameters from the given source properties.

This method allows loading pool parameters generically. For example, to set pool parameters from the environment, one can call:

 Params params = Params.create();
 params.load("mypooledtype", UtlEnv.getEnv());
 
If the environment has the value "mypooledtype.initCapacity=8192" then the calling getInitialCapacity() on the UtlPool.Params after this call would return 8192.

However, if the value of the override override parameter is set to false values from the source will not be applied. For example:

 Params params = Params.create();
 params.setInitialCapacity(4096);
 params.load("mypooledtype", UtlEnv.getEnv());
 
Would not result in the value of 8192 being applied from the environment.

Parameters:
propertyPrefix - The property prefix to use.
source - The source parameters.
override - If false then the value from the source will not override a value that has already be set.
Returns:
the parameters object for invocation chaining

isReadOnly

public final boolean isReadOnly()
Tests whether the pool parameters are read only.

When a pool is created, the provided parameter are cloned and marked as read only.

Returns:
True if the pool parameters are read only.

load

public final UtlPool.Params load(String propertyPrefix,
                                 Map<String,Object> source,
                                 boolean override)
Loads pool parameters from the given source Map.

This method is equivalent to Params.lo

Parameters:
propertyPrefix - The property prefix to use.
source - The source parameters.
override - If false then the value from the source will not override a value that has already be set.
Returns:
the parameters object for invocation chaining

setThreaded

public final UtlPool.Params setThreaded(boolean val)
Set whether a pool will be accessed concurrently using multiple threads.

Parameters:
val - True signifies multi-threaded access while false signifies single-threaded access.
Returns:
the parameters object for invocation chaining
Threading:
This method is safe for concurrent access by multiple threads.

isThreaded

public final boolean isThreaded()
Get whether a pool is operating in a thread safe manner.

Returns:
true if threaded
Threading:
This method is safe for concurrent access by multiple threads.

setDetachedWash

public final UtlPool.Params setDetachedWash(boolean val)
Set whether pool items should be washed using the detached washer

Parameters:
val - True signifies detached wash while false signifies attached wash.
Returns:
the parameters object for invocation chaining
Threading:
This method is safe for concurrent access by multiple threads.

isDetachedWash

public final boolean isDetachedWash()
Get whether pool items will be washed using the detached washer

Returns:
the parameters object for invocation chaining
Threading:
This method is safe for concurrent access by multiple threads.

setInitialCapacity

public final UtlPool.Params setInitialCapacity(int val)
Set the initial pool capacity.

The initial pool capacity is the capacity with which the pool is created. The pool is dynamically grown when the number of objects in the pool exceeds the initial capacity. The capacity continues to grow until the maximum capacity is reached at which point objects in the pool are released for garbage collection to keep the size of the pool <= thea maximum pool capacity.

Returns:
the parameters object for invocation chaining
Threading:
This method is safe for concurrent access by multiple threads.

getInitialCapacity

public final int getInitialCapacity()
Get the initial pool capacity.

Returns:
the initial capacity.
See Also:
setInitialCapacity(int)
Threading:
This method is safe for concurrent access by multiple threads.

setMaxCapacity

public final UtlPool.Params setMaxCapacity(int val)
Set the maximum pool capacity.

The maximum pool capacity is the maximum size to which a pool can grow beyond which pooled objects are released for garbage collection. Objects are released in a LIFO manner to minimize evicted objects' live age to favor younger generation GCs.

Settting maximum capacity to less than initial capacity, causes the pool to reduce the initial capacity to maximum capacity.

Returns:
the parameters object for invocation chaining
Threading:
This method is safe for concurrent access by multiple threads.

getMaxCapacity

public final int getMaxCapacity()
Get the maximum pool capacity.

Returns:
the maximum pool capacity.
See Also:
setMaxCapacity(int)
Threading:
This method is safe for concurrent access by multiple threads.

setPreallocate

public UtlPool.Params setPreallocate(boolean preallocate)
Sets whether items in the pool should be preallocated up front to avoid object promotions. When preallocate is enabled the number of items specified by setInitialCapacity(int) will be created and seeded into the pool.

Parameters:
preallocate - true to enable object preallocation
Returns:
the parameters object for invocation chaining
Threading:
This method is safe for concurrent access by multiple threads.

isPreallocate

public boolean isPreallocate()
Tests whether this pool was set to preallocate items up front.

When true the pool will create the number of items specified by its initialCapacity when it is created.

Returns:
True if this pool was set to preallocate items.
Threading:
This method is safe for concurrent access by multiple threads.

clone

public Object clone()
Clone the parameters object.

This method creates a clone of the parameters object. The clone will not be readonly even if these UtlPool.Params are.

Overrides:
clone in class Object
Threading:
This method is safe for concurrent access by multiple threads.

toString

public String toString()
Get a string representation of the parameter object.

Overrides:
toString in class Object
Threading:
This method is safe for concurrent access by multiple threads.


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