Poolable objects that a Pool based
on this `PoolBuilder` will produce.
build() method.
Pool builder instances are obtained by calling one of the `from*`
methods on Pool, such as Pool#fromThreaded(Allocator).
This class is made thread-safe by having the fields be protected by the
intrinsic object lock on the `PoolBuilder` object itself. This way, pools
can `synchronize` on the builder object to read the values out atomically.
The various set* methods are made to return the `PoolBuilder` instance
itself, so that the method calls may be chained if so desired.
| Modifier and Type | Field and Description |
|---|---|
| private final AllocationProcess | |
| private Allocator | |
| private int | |
| private boolean | |
| pack-priv static final Map | |
| private Expiration | |
| private MetricsRecorder | |
| pack-priv static final Map | |
| private final PoolBuilderPermissions | |
| private boolean | |
| private int | |
| private ThreadFactory |
| Access | Constructor and Description |
|---|---|
| pack-priv | PoolBuilder(AllocationProcess allocationProcess, Allocator<T> allocator)
Build a new empty `PoolBuilder` object. |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized Pool | |
| private void | |
| public final synchronized PoolBuilder | Returns: A new `PoolBuilder` object of the exact same type as this one, with identical values in all its fields.Overrides java. |
| pack-priv synchronized Reallocator | getAdaptedReallocator()
Returns a `Reallocator`, possibly by adapting the configured `Allocator` if need be. |
| public synchronized Allocator | |
| public synchronized int | Returns: the delay, in milliseconds, between background maintenance tasks.Return the default approximate delay, in milliseconds, between background maintenance tasks, such as the background expiration checks and retrying failed allocations. |
| public synchronized Expiration | |
| public synchronized MetricsRecorder | Returns: The configured MetricsRecorder.Get the configured |
| public synchronized Reallocator | Returns: A configured or adapted Reallocator.Get the configured |
| public synchronized int | |
| public synchronized ThreadFactory | Returns: The configured thread factory.Get the ThreadFactory that has been configured, and will be used to create the background allocation threads for the pools. |
| public synchronized boolean | Returns: `true` if background expiration is enabled.Return whether or not background expiration is enabled. |
| public synchronized boolean | Returns: `true` if precise object leak detection is enabled.Return whether or not precise object leak detection is enabled, which is the case by default. |
| public synchronized < The type of X extends Poolable> PoolBuilderPoolable that is created by the allocator,
and the type of objects that the configured pools will contain. | Returns: This `PoolBuilder` instance, but with a generic type parameter that matches that of the allocator.The allocator we want our pools to use.
This cannot be `null`. allocator)Set the |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.the desired delay, in milliseconds, between background maintenance tasks. delay)Set the approximate delay, in milliseconds, between background maintenance tasks. |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.`true` (the default) to turn background expiration checking on,
`false` to turn it off. enabled)Enable or disable background object expiration checking. |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.The expiration we want our pools to use. Not null. expiration)Set the |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.The MetricsRecorder to use, or null if we don't
want to use any. metricsRecorder)Set the |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.`true` to turn on precise object leak detection (the
default) `false` to turn it off. enabled)Enable or disable precise object leak detection. |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.The target pool size. Must be at least 0. size)Set the size of the pool we are building. |
| public synchronized PoolBuilder | Returns: This `PoolBuilder` instance.The ThreadFactory the pool should use to create their
background threads. factory)Set the ThreadFactory that the pools will use to create its background threads with. |
| allocationProcess | back to summary |
|---|---|
| private final AllocationProcess allocationProcess | |
| allocator | back to summary |
|---|---|
| private Allocator<T> allocator | |
| backgroundExpirationCheckDelay | back to summary |
|---|---|
| private int backgroundExpirationCheckDelay | |
| backgroundExpirationEnabled | back to summary |
|---|---|
| private boolean backgroundExpirationEnabled | |
| DEFAULTS | back to summary |
|---|---|
| pack-priv static final Map<AllocationProcessMode, PoolBuilderDefaults> DEFAULTS | |
| expiration | back to summary |
|---|---|
| private Expiration<? super T> expiration | |
| metricsRecorder | back to summary |
|---|---|
| private MetricsRecorder metricsRecorder | |
| PERMISSIONS | back to summary |
|---|---|
| pack-priv static final Map<AllocationProcessMode, PoolBuilderPermissions> PERMISSIONS | |
| permissions | back to summary |
|---|---|
| private final PoolBuilderPermissions permissions | |
| preciseLeakDetectionEnabled | back to summary |
|---|---|
| private boolean preciseLeakDetectionEnabled | |
| size | back to summary |
|---|---|
| private int size | |
| threadFactory | back to summary |
|---|---|
| private ThreadFactory threadFactory | |
| PoolBuilder | back to summary |
|---|---|
| pack-priv PoolBuilder(AllocationProcess allocationProcess, Allocator<T> allocator) Build a new empty `PoolBuilder` object. | |
| build | back to summary |
|---|---|
| public synchronized Pool Build a | |
| checkPermission | back to summary |
|---|---|
| private void checkPermission(boolean permission, String fieldDescription) | |
| clone | back to summary |
|---|---|
| public final synchronized PoolBuilder Overrides java. Returns a shallow copy of this `PoolBuilder` object.
| |
| getAdaptedReallocator | back to summary |
|---|---|
| pack-priv synchronized Reallocator Returns a `Reallocator`, possibly by adapting the configured `Allocator` if need be. If a `MetricsRecorder` has been configured, the return `Reallocator` will automatically record allocation, reallocation and deallocation latencies. | |
| getAllocator | back to summary |
|---|---|
| public synchronized Allocator Get the configured
| |
| getBackgroundExpirationCheckDelay | back to summary |
|---|---|
| public synchronized int getBackgroundExpirationCheckDelay() Return the default approximate delay, in milliseconds, between background maintenance tasks, such as the background expiration checks and retrying failed allocations.
| |
| getExpiration | back to summary |
|---|---|
| public synchronized Expiration Get the configured
| |
| getMetricsRecorder | back to summary |
|---|---|
| public synchronized MetricsRecorder getMetricsRecorder() Get the configured
| |
| getReallocator | back to summary |
|---|---|
| public synchronized Reallocator Get the configured
| |
| getSize | back to summary |
|---|---|
| public synchronized int getSize() Get the currently configured size. The default is 10.
| |
| getThreadFactory | back to summary |
|---|---|
| public synchronized ThreadFactory getThreadFactory() Get the ThreadFactory that has been configured, and will be used to create
the background allocation threads for the pools. The default is similar to
the
| |
| isBackgroundExpirationEnabled | back to summary |
|---|---|
| public synchronized boolean isBackgroundExpirationEnabled() Return whether or not background expiration is enabled. By default, background expiration is enabled.
| |
| isPreciseLeakDetectionEnabled | back to summary |
|---|---|
| public synchronized boolean isPreciseLeakDetectionEnabled() Return whether or not precise object leak detection is enabled, which is the case by default.
| |
| setAllocator | back to summary |
|---|---|
| public synchronized <X extends Poolable> PoolBuilder Set the
| |
| setBackgroundExpirationCheckDelay | back to summary |
|---|---|
| public synchronized PoolBuilder Set the approximate delay, in milliseconds, between background maintenance tasks. These tasks include the background expiration checks, and retrying failed allocations. The default delay is 1.000 milliseconds (1 second). Lowering this value will improve the pools responsiveness to repairing failed allocations, and also increase the frequency of the background expiration checks. This comes at the cost of higher idle CPU usage. It is not recommended to set this value lower than 100 milliseconds. Values lower than this tend to have increased CPU and power usage, for very little gain in responsiveness for the background tasks.
| |
| setBackgroundExpirationEnabled | back to summary |
|---|---|
| public synchronized PoolBuilder Enable or disable background object expiration checking. This is enabled by default, but can be turned off if the check is expensive. The cost of the check matters because it might end up taking resources away from the background thread and hinder its ability to keep up with the demand for allocations and deallocations, even though these tasks always take priority over any expiration checking.
| |
| setExpiration | back to summary |
|---|---|
| public synchronized PoolBuilder Set the
| |
| setMetricsRecorder | back to summary |
|---|---|
| public synchronized PoolBuilder Set the
| |
| setPreciseLeakDetectionEnabled | back to summary |
|---|---|
| public synchronized PoolBuilder Enable or disable precise object leak detection. It is enabled by default. Precise object leak detection makes the pool keep an eye on the allocated Poolables, such that it notices if they get garbage collected without first being deallocated. Using the garbage collector for this purpose, means that no false positives (counting objects as leaked, even though they are not) are ever reported. [NOTE] -- While the pool is able to detect object leaks, it cannot prevent them. All leaks are a sign that there is a bug in the system; most likely a bug in your code, or in the way the pool is used. -- Precise object leak detection incurs virtually no overhead, and is safe to leave enabled at all times – even in the most demanding production environments.
| |
| setSize | back to summary |
|---|---|
| public synchronized PoolBuilder Set the size of the pool we are building.
Pools are required to control the allocations and deallocations, such that
no more than this number of objects are allocated at any time.
This means that a pool of size 1, whose single object have expired, will
deallocate that one object before allocating a replacement.
The size must be at least one, or an
| |
| setThreadFactory | back to summary |
|---|---|
| public synchronized PoolBuilder Set the ThreadFactory that the pools will use to create its background threads with. The ThreadFactory is not allowed to be null, and creating a pool with a null ThreadFactory will throw an IllegalArgumentException.
| |