### DropwizardMetricsRecorder Example Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/MetricsRecorder.html An example implementation of the MetricsRecorder interface using the Dropwizard Metrics library. This class demonstrates how to integrate Stormpot's metrics recording with Dropwizard's MetricRegistry and Histograms. ```APIDOC ## DropwizardMetricsRecorder Example ### Description An example implementation of the `MetricsRecorder` interface using the Dropwizard Metrics library. This class integrates with `MetricRegistry` to record various latency and lifetime metrics. ### Class `examples.DropwizardMetricsRecorder` ### Constructor `DropwizardMetricsRecorder(String baseName, MetricRegistry registry)` - **baseName** (String) - Required - A base name for metrics. - **registry** (MetricRegistry) - Required - The Dropwizard MetricRegistry to use. ### Implements `MetricsRecorder` ### Methods #### `recordAllocationLatencySampleMillis(long milliseconds)` Updates the allocation latency histogram. #### `recordAllocationFailureLatencySampleMillis(long milliseconds)` Updates the allocation failure latency histogram. #### `recordDeallocationLatencySampleMillis(long milliseconds)` Updates the deallocation latency histogram. #### `recordReallocationLatencySampleMillis(long milliseconds)` Updates the reallocation latency histogram. #### `recordReallocationFailureLatencySampleMillis(long milliseconds)` Updates the reallocation failure latency histogram. #### `recordObjectLifetimeSampleMillis(long milliseconds)` Updates the object lifetime histogram. #### `getAllocationLatencyPercentile(double percentile)` Gets the approximate allocation latency percentile from the histogram. #### `getAllocationFailureLatencyPercentile(double percentile)` Gets the approximate failed allocation latency percentile from the histogram. #### `getDeallocationLatencyPercentile(double percentile)` Gets the approximate deallocation latency percentile from the histogram. #### `getReallocationLatencyPercentile(double percentile)` Gets the approximate reallocation latency percentile from the histogram. #### `getReallocationFailurePercentile(double percentile)` Gets the approximate failed reallocation latency percentile from the histogram. #### `getObjectLifetimePercentile(double percentile)` Gets the approximate object lifetime percentile from the histogram. ### Request Example ```java // Assuming MetricRegistry and baseName are initialized MetricsRecorder recorder = new DropwizardMetricsRecorder("my.pool", metricRegistry); // Example of recording a metric recorder.recordAllocationLatencySampleMillis(50); ``` ### Response Example (This implementation does not have direct API request/response bodies in the traditional sense, as it's a Java class. Metrics are retrieved via the `get...Percentile` methods.) ```java // Example of retrieving a metric double p95AllocationLatency = recorder.getAllocationLatencyPercentile(0.95); System.out.println("95th percentile allocation latency: " + p95AllocationLatency + "ms"); ``` ``` -------------------------------- ### Configure and Build a Pool Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/Pool.java.html Example of setting up a pool with a custom allocator and size. ```java @Override public void deallocate(Pooled poolable) { } }; PoolBuilder> builder = new PoolBuilder<>(direct(), allocator); builder.setSize(objects.length); return builder.build(); } ``` -------------------------------- ### Claim and Release Pattern Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolTap.html Example demonstrating the lifecycle of claiming an object, using it, and ensuring its release back to the pool. ```java Poolable obj = pool.claim(TIMEOUT); if (obj != null) { try { System.out.println(obj); } finally { obj.release(); } } ``` -------------------------------- ### Generate Website and Javadocs Source: http://chrisvest.github.io/stormpot Use this Maven command to generate the project's website and Javadoc documentation. Ensure you have Maven installed. ```bash mvn clean pre-site javadoc:javadoc ``` -------------------------------- ### Basic Stormpot Pool Usage Source: http://chrisvest.github.io/stormpot Demonstrates the fundamental setup and usage of a Stormpot pool. It involves creating an allocator, building a pool, claiming an object with a timeout, performing operations, and releasing the object. Note that 'claim' returns null on timeout. ```java MyAllocator allocator = new MyAllocator(); Pool pool = Pool.from(allocator).build(); Timeout timeout = new Timeout(1, TimeUnit.SECONDS); MyPoolable object = pool.claim(timeout); try { // Do stuff with 'object'. // Note: 'claim' returns 'null' if it times out. } finally { if (object != null) { object.release(); } } ``` -------------------------------- ### Claim, Print, and Release Object from Pool Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/PoolTap.java.html This example demonstrates how to claim an object from a pool, print it to standard output, and then release it back to the pool. It highlights the typical lifecycle of an object obtained from a PoolTap. ```java Pool pool = ...; try (Poolable poolable = pool.claim(timeout)) { MyObject obj = poolable.get(); System.out.println("Claimed object: " + obj); } // object is released automatically here ``` -------------------------------- ### Register Stormpot Pool with MBeanServer Source: http://chrisvest.github.io/stormpot/jmx.html Example of how to register a Stormpot pool with the platform MBeanServer for JMX monitoring. Ensure you have a MetricsRecorder configured to query metrics through JMX. ```java Pool pool = Pool.from(new MyAllocator()).build(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName("com.myapp:objectpool=stormpot"); server.registerMBean(pool.getManagedPool(), name); ``` -------------------------------- ### Get Base Unit Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/Timeout.java.html Gets the unit of precision for the underlying clock. ```APIDOC ## GET /api/timeout/baseUnit ### Description Get the unit of precision for the underlying clock, that is used by getDeadline() and getTimeLeft(long). ### Method GET ### Endpoint /api/timeout/baseUnit ### Parameters None ### Request Example None ### Response #### Success Response (200) - **baseUnit** (TimeUnit) - The unit of precision used by the clock in this Timeout. #### Response Example { "baseUnit": "NANOSECONDS" } ``` -------------------------------- ### Get Timeout Unit Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Timeout.html Get the unit for the timeout value. This unit will never be null. ```java public java.util.concurrent.TimeUnit getUnit() ``` -------------------------------- ### Get Timeout Value Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Timeout.html Get the timeout value in terms of the specified unit. The returned value can be zero or negative. ```java public long getTimeout() ``` -------------------------------- ### Get Timeout in Base Unit Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Timeout.html Get the timeout value in terms of the base unit. The returned value can be zero or negative. ```java public long getTimeoutInBaseUnit() ``` -------------------------------- ### Configure and Use a Pool Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/package-summary.html Initialize a pool using an allocator and manage object lifecycle using claim and release within a try-finally block. ```java Pool pool = Pool.from(new MyAllocator()).build(); Timeout timeout = new Timeout(1, TimeUnit.SECONDS); MyPoolable object = pool.claim(timeout); try { // Do stuff with 'object'. // Note that 'claim' will return 'null' if it times out! } finally { if (object != null) { object.release(); } } ``` -------------------------------- ### Get Expiration Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the currently configured Expiration instance. ```java public Expiration getExpiration() ``` -------------------------------- ### Initialize and use a direct pool Source: http://chrisvest.github.io/stormpot/tutorial.html Creates a pool with a fixed set of objects using Pool.of and demonstrates claiming an object from the pool. ```java Object a = new Object(); Object b = new Object(); Object c = new Object(); Pool> pool = Pool.of(a, b, c); try (Pooled claim = pool.claim(TIMEOUT)) { if (claim != null) { System.out.println(claim.object); } } ``` -------------------------------- ### Get Allocator Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the currently configured Allocator instance. ```java public Allocator getAllocator() ``` -------------------------------- ### GET /PoolBuilder/getSize Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the currently configured size for the pool. ```APIDOC ## GET /PoolBuilder/getSize ### Description Returns the currently configured size of the pool. The default value is 10. ### Method GET ### Response #### Success Response (200) - **size** (int) - The configured pool size. ``` -------------------------------- ### POST /pool/builder/from Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Pool.html Initializes a PoolBuilder using a specified Allocator or Reallocator to configure a new Pool instance. ```APIDOC ## POST /pool/builder/from ### Description Creates a PoolBuilder instance based on the provided allocator. This builder is used to configure and instantiate a new Pool. ### Method POST ### Endpoint /pool/builder/from ### Parameters #### Request Body - **allocator** (Allocator) - Required - The allocator or reallocator used to create Poolable objects. ### Response #### Success Response (200) - **PoolBuilder** (Object) - A configured builder instance for the pool. ``` -------------------------------- ### Get Base Unit Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/Timeout.java.html Returns the unit of precision used by the clock. ```java public TimeUnit getBaseUnit() { return TimeUnit.NANOSECONDS; } ``` -------------------------------- ### PoolException Constructors Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolException.html Details on how to instantiate a PoolException, with explanations for each constructor. ```APIDOC ## PoolException Constructors ### Constructor Summary Constructors | Description ---|--- `PoolException(String message)` | Construct a new PoolException with the given message. `PoolException(String message, Throwable cause)` | Construct a new PoolException with the given message and cause. ### Constructor Detail #### PoolException ```java public PoolException(String message) ``` Construct a new PoolException with the given message. Parameters: - `message` (String) - A description of the exception to be returned from `Throwable.getMessage()`. See Also: - `RuntimeException(String)` #### PoolException ```java public PoolException(String message, Throwable cause) ``` Construct a new PoolException with the given message and cause. Parameters: - `message` (String) - A description for the exception to be returned form `Throwable.getMessage()`. - `cause` (Throwable) - The underlying cause of this exception, as to be shown in the stack trace, and available through `Throwable.getCause()`. See Also: - `RuntimeException(String, Throwable)` ``` -------------------------------- ### GET PoolBuilder.getReallocator() Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/class-use/Reallocator.html Retrieves the configured Allocator instance as a Reallocator from the PoolBuilder. ```APIDOC ## GET PoolBuilder.getReallocator() ### Description Returns the configured Allocator instance cast or converted to a Reallocator. ### Method GET ### Endpoint PoolBuilder.getReallocator() ### Response #### Success Response (200) - **Reallocator** - The configured Reallocator instance. ``` -------------------------------- ### GET /Pool/getManagedPool Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/class-use/ManagedPool.html Retrieves the ManagedPool instance associated with a specific pool. ```APIDOC ## GET /Pool/getManagedPool ### Description Returns the ManagedPool instance that represents the current pool. ### Method GET ### Endpoint /Pool/getManagedPool ### Response #### Success Response (200) - **ManagedPool** (object) - The ManagedPool instance representing this pool. ``` -------------------------------- ### Record Reallocation Latency Sample (Java) Source: http://chrisvest.github.io/stormpot/metrics.html Records a sample of reallocation latency in milliseconds. This method is part of the metrics implementation for Stormpot. ```java public void recordReallocationLatencySampleMillis(long milliseconds) { reallocationLatency.update(milliseconds); } ``` -------------------------------- ### Expiration Configuration Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/PoolBuilder.java.html Methods for getting and setting the expiration policy for poolable objects. ```APIDOC ## GET /expiration ### Description Retrieves the current expiration policy for the pool. ### Method GET ### Endpoint /expiration ### Response #### Success Response (200) - **expiration** (Expiration) - The configured expiration policy. #### Response Example ```json { "expiration": "your_expiration_policy_object" } ``` ## POST /expiration ### Description Sets the expiration policy for the poolable objects. ### Method POST ### Endpoint /expiration ### Parameters #### Request Body - **expiration** (Expiration) - Required - The expiration policy to set. ### Request Example ```json { "expiration": "your_expiration_policy_object" } ``` ### Response #### Success Response (200) - **PoolBuilder** (PoolBuilder) - Returns the current PoolBuilder instance for chaining. #### Response Example ```json { "message": "Expiration policy set successfully" } ``` ``` -------------------------------- ### PoolBuilder.build() Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/class-use/Pool.html Builds a Pool instance with custom configurations. ```APIDOC ## POST /api/users ### Description Builds a `Pool` instance based on the collected configuration. ### Method POST ### Endpoint `/api/users` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **config** (object) - Required - The configuration object for the pool. - **factory** (function) - Required - The factory function to create objects. - **size** (number) - Optional - The maximum size of the pool. ### Request Example ```json { "config": { "factory": "() => new MyObject()", "size": 10 } } ``` ### Response #### Success Response (200) - **pool** (Pool) - The created Pool instance. #### Response Example ```json { "pool": "" } ``` ``` -------------------------------- ### Get Timeout Value Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/Timeout.java.html Retrieves the timeout value in terms of the base unit. ```APIDOC ## GET /api/timeout/value ### Description Retrieves the timeout value in terms of the base unit. ### Method GET ### Endpoint /api/timeout/value ### Parameters None ### Request Example None ### Response #### Success Response (200) - **timeoutValue** (long) - A numerical value of the timeout. Possibly zero or negative. #### Response Example { "timeoutValue": 1000000 } ``` -------------------------------- ### Initialize DirectAllocationController Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/DirectAllocationController.java.html Initializes the DirectAllocationController by allocating a fixed number of objects using the provided allocator and populating the live queue. This constructor is used when the pool size is determined at creation time. ```java class DirectAllocationController extends AllocationController { private final LinkedTransferQueue> live; private final RefillPile disregardPile; private final BSlot poisonPill; private final int size; private final AtomicInteger shutdownState; private final AtomicInteger poisonedSlots; DirectAllocationController( LinkedTransferQueue> live, RefillPile disregardPile, PoolBuilder builder, BSlot poisonPill) { this.live = live; this.disregardPile = disregardPile; this.poisonPill = poisonPill; this.size = builder.getSize(); poisonedSlots = new AtomicInteger(); Allocator allocator = builder.getAllocator(); for (int i = 0; i < size; i++) { BSlot slot = new BSlot<>(live, poisonedSlots); try { slot.obj = allocator.allocate(slot); slot.createdNanos = System.nanoTime(); slot.dead2live(); } catch (Exception e) { throw new RuntimeException("Unexpected exception.", e); } live.offer(slot); } shutdownState = new AtomicInteger(size); } // ... other methods ``` -------------------------------- ### Get Leaked Objects Count Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BlazePool.java.html Retrieves the count of leaked objects from the allocator. ```java return allocator.countLeakedObjects(); ``` -------------------------------- ### Pool Methods Source: http://chrisvest.github.io/stormpot/site/apidocs/index-all.html Methods for interacting with and building Stormpot Pools. ```APIDOC ## Pool Operations ### Description Provides methods for building and accessing information about Stormpot Pools. ### Method GET / POST ### Endpoint /pool ### Parameters #### Query Parameters - **targetSize** (int) - Optional - The currently configured target size of the pool. #### Request Body (for POST /pool) - **objects** (Array) - Required - An array of objects to be pooled. ### Response #### Success Response (200) - **targetSize** (int) - The currently configured target size of the pool. - **threadSafeTap** (PoolTap) - A thread-safe PoolTap for accessing pool elements. - **threadLocalTap** (PoolTap) - A PoolTap for single-thread access. #### Response Example { "targetSize": 15, "threadSafeTap": "PoolTap object", "threadLocalTap": "PoolTap object" } ``` -------------------------------- ### Check Code Formatting Source: http://chrisvest.github.io/stormpot Run this Maven command to check if your code adheres to the project's formatting standards. Address any reported issues before submitting. ```bash mvn checkstyle:check ``` -------------------------------- ### Get Allocation Count Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/DirectAllocationController.java.html Returns the total number of objects that were allocated for the pool. ```java long getAllocationCount() { return size; } ``` -------------------------------- ### GET /getReallocationLatencyPercentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/MetricsRecorder.html Retrieves the approximate reallocation latency in milliseconds for a given percentile. ```APIDOC ## GET /getReallocationLatencyPercentile ### Description Get the approximate latency value, in milliseconds, for reallocation latencies within the given percentile/quantile of what has been recorded so far. ### Parameters #### Query Parameters - **percentile** (double) - Required - The percentile/quantile to get a value for (between 0.0 and 1.0). ### Response #### Success Response (200) - **latency** (double) - The latency value in milliseconds for the given percentile/quantile. Returns Double.NaN if not supported. ``` -------------------------------- ### PoolBuilder Configuration Methods Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/PoolBuilder.html This section details the various methods available on the PoolBuilder class to configure the properties of a Stormpot Pool before it is built. ```APIDOC ## PoolBuilder Configuration Methods This section details the various methods available on the PoolBuilder class to configure the properties of a Stormpot Pool before it is built. ### `setSize(int size)` Sets the size of the pool. - **Parameters**: - `size` (int) - Required - The desired size of the pool. ### `setBackgroundExpirationCheckDelay(int delayMillis)` Sets the delay for background expiration checks. - **Parameters**: - `delayMillis` (int) - Required - The delay in milliseconds between background expiration checks. ### `setAllocator(Allocator allocator)` Sets a custom allocator for the pool. - **Parameters**: - `allocator` (Allocator) - Required - The custom allocator to use. ### `setExpiration(Expiration expiration)` Sets the expiration strategy for the pool. - **Parameters**: - `expiration` (Expiration) - Required - The expiration strategy to apply. ### `setThreadFactory(ThreadFactory threadFactory)` Sets a custom thread factory for the pool's threads. - **Parameters**: - `threadFactory` (ThreadFactory) - Required - The custom thread factory. ### `setBackgroundExpirationEnabled(boolean enabled)` Enables or disables background expiration checks. - **Parameters**: - `enabled` (boolean) - Required - `true` to enable, `false` to disable. ### `setPreciseLeakDetectionEnabled(boolean enabled)` Enables or disables precise leak detection. - **Parameters**: - `enabled` (boolean) - Required - `true` to enable, `false` to disable. ### `setMetricsRecorder(MetricsRecorder metricsRecorder)` Sets a metrics recorder for the pool. - **Parameters**: - `metricsRecorder` (MetricsRecorder) - Required - The metrics recorder to use. ### `getAdaptedReallocator()` Returns an adapted reallocator. ### `getReallocator()` Returns the reallocator. ### `checkPermission(boolean, String)` Checks a permission. ### `build()` Builds and returns the configured Pool. ### `clone()` Creates a clone of the current PoolBuilder. ### `static {...}` Static factory method or initialization block. ### `PoolBuilder(AllocationProcess, Allocator)` Constructor for PoolBuilder. ### `getSize()` Gets the current size of the pool. ### `getAllocator()` Gets the allocator used by the pool. ### `getExpiration()` Gets the expiration strategy of the pool. ### `getMetricsRecorder()` Gets the metrics recorder for the pool. ### `getThreadFactory()` Gets the thread factory used by the pool. ### `isPreciseLeakDetectionEnabled()` Checks if precise leak detection is enabled. ### `isBackgroundExpirationEnabled()` Checks if background expiration is enabled. ### `getBackgroundExpirationCheckDelay()` Gets the delay for background expiration checks. ``` -------------------------------- ### Get Thread Factory Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the ThreadFactory used for background allocation threads. ```java public java.util.concurrent.ThreadFactory getThreadFactory() ``` -------------------------------- ### Implement Micrometer MeterBinder for Stormpot Source: http://chrisvest.github.io/stormpot/metrics.html Exposes pool metrics like allocation counts, leaks, and errors to a Micrometer registry. ```java package examples; import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.binder.MeterBinder; import stormpot.ManagedPool; import stormpot.Pool; public class MicrometerBinderExample implements MeterBinder { private static final String SUCCESSFUL_ALLOCATIONS = "allocationCount"; private static final String FAILED_ALLOCATIONS = "failedAllocationCount"; private static final String LEAKED_OBJECTS = "leakedObjectCount"; private static final String SEP = "."; private final ManagedPool pool; private final String poolName; public MicrometerBinderExample(String poolName, Pool pool) { this.poolName = poolName; this.pool = pool.getManagedPool(); } @Override public void bindTo(MeterRegistry registry) { Gauge.builder(poolName + SEP + SUCCESSFUL_ALLOCATIONS, pool::getAllocationCount) .description("Allocation count for pool") .baseUnit(SUCCESSFUL_ALLOCATIONS) .register(registry); Gauge.builder(poolName + SEP + FAILED_ALLOCATIONS, pool::getFailedAllocationCount) .description("Failed allocation count for pool") .baseUnit(FAILED_ALLOCATIONS) .register(registry); Gauge.builder(poolName + SEP + LEAKED_OBJECTS, pool::getLeakedObjectsCount) .description("Leaked object count for pool") .baseUnit(LEAKED_OBJECTS) .register(registry); } } ``` -------------------------------- ### Implement StormpotThreadFactory Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/StormpotThreadFactory.java.html A singleton ThreadFactory that prefixes thread names with 'Stormpot-' and sets them as daemon threads. ```java /*  * Copyright © 2011-2019 Chris Vest (mr.chrisvest@gmail.com)  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *     http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */ package stormpot; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; final class StormpotThreadFactory implements ThreadFactory {   static final ThreadFactory INSTANCE = new StormpotThreadFactory();   private static final ThreadFactory delegate = Executors.defaultThreadFactory();   private StormpotThreadFactory() {   }   @Override   public Thread newThread(Runnable r) {     Thread thread = delegate.newThread(r);     thread.setName("Stormpot-" + thread.getName());     thread.setDaemon(true);     return thread;   } } ``` -------------------------------- ### Get Reallocator Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the configured Allocator as a Reallocator, wrapping it in an adaptor if necessary. ```java public Reallocator getReallocator() ``` -------------------------------- ### Create an Inline PoolBuilder Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Pool.html Initializes a PoolBuilder that performs allocation and deallocation in-line with claim calls, avoiding background threads. ```java public static PoolBuilder fromInline(Allocator allocator) ``` -------------------------------- ### Get Target Size Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/DirectAllocationController.java.html Returns the fixed size of the pool, which is determined at the time of creation. ```java int getTargetSize() { return size; } ``` -------------------------------- ### PoolBuilder Lifecycle Methods Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Methods for cloning the builder configuration and building the final Pool instance. ```APIDOC ## clone ### Description Returns a shallow copy of this PoolBuilder object. ### Method GET ## build ### Description Build a Pool instance based on the collected configuration. ### Method POST ### Response - **pool** (Pool) - A Pool instance as configured by this builder. ``` -------------------------------- ### Get Failed Allocation Count Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/DirectAllocationController.java.html Returns the count of failed allocations, which is always 0 for this controller. ```java long getFailedAllocationCount() { return 0; } ``` -------------------------------- ### Build Pool Instance Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Constructs and returns a configured Pool instance based on the builder's settings. ```java public Pool build() ``` -------------------------------- ### GET /getReallocationFailurePercentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/MetricsRecorder.html Retrieves the approximate latency for failed reallocation attempts in milliseconds for a given percentile. ```APIDOC ## GET /getReallocationFailurePercentile ### Description Get the approximate latency value, in milliseconds, for failed reallocation latencies within the given percentile/quantile of what has been recorded so far. ### Parameters #### Query Parameters - **percentile** (double) - Required - The percentile/quantile to get a value for (between 0.0 and 1.0). ### Response #### Success Response (200) - **latency** (double) - The latency value in milliseconds for the given percentile/quantile. Returns Double.NaN if not supported. ``` -------------------------------- ### Record Reallocation Failure Latency Sample (Java) Source: http://chrisvest.github.io/stormpot/metrics.html Records a sample of reallocation failure latency in milliseconds. Use this to track performance issues during reallocation. ```java @Override public void recordReallocationFailureLatencySampleMillis(long milliseconds) { reallocationFailureLatency.update(milliseconds); } ``` -------------------------------- ### Get Metrics Recorder Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the configured MetricsRecorder instance, returning null if none is set. ```java public MetricsRecorder getMetricsRecorder() ``` -------------------------------- ### Pool Configuration and Shutdown Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BAllocThread.java.html Methods for managing pool size and initiating the shutdown process. ```java void setTargetSize(int size) { this.targetSize = size; } ``` ```java int getTargetSize() { return targetSize; } ``` ```java Completion shutdown(Thread allocatorThread) { shutdown = true; allocatorThread.interrupt(); return new LatchCompletion(completionLatch); } ``` ```java long getAllocationCount() { return allocationCount; } ``` -------------------------------- ### Get Allocation Latency Percentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/MetricsRecorder.html Retrieve the approximate allocation latency value for a given percentile. ```APIDOC ## GET /getAllocationLatencyPercentile ### Description Get the approximate Poolable object allocation latency value, in milliseconds, of the given percentile/quantile of the values recorded so far. A percentile, or quantile, is a value between 0.0 and 1.0, both inclusive, which represents a percentage of the recorded samples. In other words, given a percentile, the returned value will be the latency in milliseconds, that the given percent of samples is less than or equal to. For instance, if given the percentile 0.9 returns 120, then 90% of all recorded latency samples will be less than or equal to 120 milliseconds. Note: Implementers should strive to return `Double.NaN` as a sentinel value, if they do not support recording of the allocation latencies and/or returning a specific percentile of such recordings. ### Method GET ### Endpoint /getAllocationLatencyPercentile ### Parameters #### Query Parameters - **percentile** (double) - Required - The percentile/quantile to get a value for. ### Response #### Success Response (200) - **latency** (double) - The latency value in milliseconds for the given percentile/quantile. #### Response Example ```json { "latency": 120.5 } ``` ``` -------------------------------- ### Get Pool Size Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolBuilder.html Retrieves the currently configured size of the pool. The default size is 10. ```java public int getSize() ``` -------------------------------- ### Run All Tests (including slow) Source: http://chrisvest.github.io/stormpot Execute all tests, including those marked as slow, with this Maven command. This provides a comprehensive test run. ```bash mvn clean verify ``` -------------------------------- ### Implement Poolable Interface Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/package-summary.html Objects managed by a Stormpot pool must implement the Poolable interface. Extending BasePoolable is the simplest approach. ```java // MyPoolable.java - minimum Poolable implementation import stormpot.BasePoolable; import stormpot.Slot; public class MyPoolable extends BasePoolable { public MyPoolable(Slot slot) { super(slot); } } ``` ```java // MyOtherPoolable.java - explicit Poolable implementation import stormpot.Poolable; import stormpot.Slot; public class MyOtherPoolable implements Poolable { private final Slot slot; public MyOtherPoolable(Slot slot) { this.slot = slot; } @Override public void release() { slot.release(this); } } ``` -------------------------------- ### Stamp Management Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BSlot.java.html Methods for getting and setting a stamp associated with the slot, likely for versioning or tracking purposes. ```java @Override public long getStamp() { return stamp; } ``` ```java @Override public void setStamp(long stamp) { this.stamp = stamp; } ``` -------------------------------- ### Supply Object to Consumer Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/PoolTap.html This section details the 'supply' method, which claims an object, passes it to a consumer, and then releases it back to the pool. ```APIDOC ## Supply Object to Consumer ### Description Claims an object from the pool and supplies it to the given consumer. The object is released back to the pool after the consumer has processed it. Returns false if an object cannot be claimed within the specified timeout. ### Method `supply` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Example usage would involve calling the supply method on a Stormpot pool object. // No direct request body is applicable here. ``` ### Response #### Success Response (boolean) - **true** - if an object could be claimed within the given timeout and passed to the given consumer. - **false** - if an object could not be claimed within the given timeout. #### Response Example ```java boolean success = pool.supply(timeout, consumer); ``` ### Throws - **java.lang.InterruptedException** - if the thread was interrupted. ``` -------------------------------- ### Get Deallocation Latency Percentile Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BlazePool.java.html Retrieves the deallocation latency percentile. Returns NaN if the metrics recorder is not initialized. ```java if (metricsRecorder == null) { return Double.NaN; } return metricsRecorder.getDeallocationLatencyPercentile(percentile); ``` -------------------------------- ### BasePoolable Subclasses Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/class-use/BasePoolable.html Overview of the BasePoolable class hierarchy in Stormpot. ```APIDOC ## BasePoolable Subclasses ### Description This section lists the subclasses of BasePoolable available in the Stormpot library. ### Classes - **Pooled** - A reference to a pooled object. ``` -------------------------------- ### Get Reallocation Failure Percentile Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BlazePool.java.html Retrieves the reallocation failure percentile. Returns NaN if the metrics recorder is not initialized. ```java return metricsRecorder.getReallocationFailurePercentile(percentile); ``` -------------------------------- ### PoolBuilder Class Methods Source: http://chrisvest.github.io/stormpot/site/apidocs/index-all.html Methods for configuring and building a Pool instance. ```APIDOC ## build() ### Description Build a `Pool` instance based on the collected configuration. ### Method Method ### Endpoint class stormpot.PoolBuilder ## clone() ### Description Returns a shallow copy of this `PoolBuilder` object. ### Method Method ### Endpoint class stormpot.PoolBuilder ``` -------------------------------- ### Get Allocation Failure Latency Percentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/MetricsRecorder.html Retrieve the approximate allocation failure latency value for a given percentile. ```APIDOC ## GET /getAllocationFailureLatencyPercentile ### Description Get the approximate latency value, in milliseconds, for failed allocation latencies within the given percentile/quantile of what has been recorded so far. ### Method GET ### Endpoint /getAllocationFailureLatencyPercentile ### Parameters #### Query Parameters - **percentile** (double) - Required - The percentile/quantile to get a value for. ### Response #### Success Response (200) - **latency** (double) - The latency value in milliseconds for the given percentile/quantile. #### Response Example ```json { "latency": 75.2 } ``` ``` -------------------------------- ### Get Object Lifetime Percentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/ManagedPool.html Calculates the approximate object lifetime within a specified percentile. Measured in milliseconds. ```java double getObjectLifetimePercentile​(double percentile) ``` -------------------------------- ### Implement the Poolable interface Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Poolable.html A manual implementation of the Poolable interface requiring a reference to the Slot for release. ```java public class GenericPoolable implements Poolable { private final Slot slot; public GenericPoolable(Slot slot) { this.slot = slot; } public void release() { slot.release(this); } } ``` -------------------------------- ### Constructor for InlineAllocationController Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/InlineAllocationController.java.html Initializes a new InlineAllocationController instance with provided queues, builder, and poison pill. It configures metrics, leak detection, and sets the initial target size for the pool. ```java InlineAllocationController( LinkedTransferQueue> live, RefillPile disregardPile, RefillPile newAllocations, PoolBuilder builder, BSlot poisonPill) { this.live = live; this.disregardPile = disregardPile; this.newAllocations = newAllocations; this.poisonPill = poisonPill; this.metricsRecorder = builder.getMetricsRecorder(); poisonedSlots = new AtomicInteger(); allocator = builder.getAdaptedReallocator(); leakDetector = builder.isPreciseLeakDetectionEnabled() ? new PreciseLeakDetector() : null; setTargetSize(builder.getSize()); } ``` -------------------------------- ### Get Managed Pool Instance Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Pool.html Obtains the `ManagedPool` instance associated with this pool. This instance represents the underlying managed pool. ```java public abstract ManagedPool getManagedPool() ``` -------------------------------- ### Build Pool Instance Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/PoolBuilder.java.html Constructs a new Pool instance based on the current configuration. ```java public synchronized Pool build() { return new BlazePool<>(this, allocationProcess); } ``` -------------------------------- ### Slot Publishing and Metrics Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BAllocThread.java.html Utility methods for publishing slots to the queue and recording object lifetime metrics. ```java private void publishSlot(BSlot slot, boolean success, long now) { resetSlot(slot, now); if (success && !live.hasWaitingConsumer()) { // Successful, fresh allocations go to the front of the queue. newAllocations.push(slot); } else { // Failed allocations go to the back of the queue. live.offer(slot); } incrementAllocationCounts(success); } ``` ```java private void incrementAllocationCounts(boolean success) { if (success) { allocationCount++; consecutiveAllocationFailures = 0; } else { failedAllocationCount++; consecutiveAllocationFailures++; } } ``` ```java private void resetSlot(BSlot slot, long now) { slot.createdNanos = now; slot.claims = 0; slot.stamp = 0; slot.dead2live(); } ``` ```java private void recordObjectLifetimeSample(long nanoseconds) { if (metricsRecorder != null) { long milliseconds = TimeUnit.NANOSECONDS.toMillis(nanoseconds); metricsRecorder.recordObjectLifetimeSampleMillis(milliseconds); } } ``` -------------------------------- ### Get Reallocation Latency Percentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/ManagedPool.html Calculates the approximate latency for object reallocations within a specified percentile. Measured in milliseconds. ```java double getReallocationLatencyPercentile​(double percentile) ``` -------------------------------- ### Get Deallocation Latency Percentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/ManagedPool.html Calculates the approximate latency for object deallocations within a specified percentile. Measured in milliseconds. ```java double getDeallocationLatencyPercentile​(double percentile) ``` -------------------------------- ### State Transition Methods Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/BSlot.java.html Provides methods to transition the slot's state to LIVING or DEAD. These methods use lazySet for direct state changes or compareAndSet for conditional transitions. ```java void claim2live() { lazySet(LIVING); } ``` ```java void claimTlr2live() { lazySet(LIVING); } ``` ```java void dead2live() { lazySet(LIVING); } ``` ```java void claim2dead() { lazySet(DEAD); } ``` ```java boolean live2claim() { return compareAndSet(LIVING, CLAIMED); } ``` ```java boolean live2claimTlr() { return compareAndSet(LIVING, TLR_CLAIMED); } ``` ```java boolean live2dead() { return compareAndSet(LIVING, DEAD); } ``` -------------------------------- ### Get Allocation Latency Percentile Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/ManagedPool.html Calculates the approximate latency for object allocations within a specified percentile. Measured in milliseconds. ```java double getAllocationLatencyPercentile​(double percentile) ``` -------------------------------- ### PoolBuilder Methods Source: http://chrisvest.github.io/stormpot/site/apidocs/index-all.html Methods for configuring and retrieving settings from a PoolBuilder. ```APIDOC ## getAllocator() ### Description Get the configured `Allocator` instance. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (200) - **allocator** (Allocator) - The configured Allocator instance. ### Response Example ```json { "allocator": { ... Allocator details ... } } ``` ## getBackgroundExpirationCheckDelay() ### Description Return the default approximate delay, in milliseconds, between background maintenance tasks, such as the background expiration checks and retrying failed allocations. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (200) - **delayMillis** (long) - The background expiration check delay in milliseconds. ### Response Example ```json { "delayMillis": 60000 } ``` ## getExpiration() ### Description Get the configured `Expiration` instance. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (200) - **expiration** (Expiration) - The configured Expiration instance. ### Response Example ```json { "expiration": { ... Expiration details ... } } ``` ## getMetricsRecorder() ### Description Get the configured `MetricsRecorder` instance, or null if none has been configured. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (200) - **metricsRecorder** (MetricsRecorder | null) - The configured MetricsRecorder instance or null. ### Response Example ```json { "metricsRecorder": { ... MetricsRecorder details ... } } ``` ``` -------------------------------- ### POST /pool/shutdown Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/class-use/Completion.html Initiates the shutdown process for a Stormpot pool and returns a Completion object to track the status. ```APIDOC ## POST /pool/shutdown ### Description Initiate the shut down process on this pool, and return a Completion instance representing the shut down procedure. ### Method POST ### Endpoint /pool/shutdown ### Response #### Success Response (200) - **Completion** (object) - An instance representing the shut down procedure. ``` -------------------------------- ### Get Thread-Safe Pool Tap Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Pool.html Returns a thread-safe `PoolTap` implementation that can be safely shared and used across multiple threads concurrently. ```java public final PoolTap getThreadSafeTap() ``` -------------------------------- ### PoolBuilder Configuration Source: http://chrisvest.github.io/stormpot/site/apidocs/index-all.html Methods for configuring a pool instance using the PoolBuilder. ```APIDOC ## PoolBuilder Configuration Methods ### Description Configures various settings for a pool, including allocators, expiration policies, and metrics. ### Methods - **setAllocator(Allocator)** - Set the Allocator or Reallocator. - **setBackgroundExpirationCheckDelay(int)** - Set delay in milliseconds between background maintenance. - **setBackgroundExpirationEnabled(boolean)** - Enable or disable background expiration. - **setExpiration(Expiration)** - Set the Expiration policy. - **setMetricsRecorder(MetricsRecorder)** - Set the MetricsRecorder. - **setPreciseLeakDetectionEnabled(boolean)** - Enable or disable leak detection. - **setSize(int)** - Set the pool size. - **setThreadFactory(ThreadFactory)** - Set the ThreadFactory for background threads. ``` -------------------------------- ### Get Time Left (Deprecated) Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Timeout.html Deprecated: This method is subject to removal in a future version because it encourages code susceptible to overflow bugs. ```java @Deprecated(forRemoval=true) public long getTimeLeft (long deadline) ``` -------------------------------- ### Display Dependency Updates Source: http://chrisvest.github.io/stormpot Check for available updates for project dependencies using this command. ```bash mvn versions:display-dependency-updates ``` -------------------------------- ### Check if Pool is Shut Down Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/ManagedPool.html Determines if the pool's shutdown process has been initiated. Returns true if shutdown has started, false otherwise. ```java boolean isShutDown() ``` -------------------------------- ### Initialize VarHandles for InlineAllocationController Source: http://chrisvest.github.io/stormpot/site/jacoco/stormpot/InlineAllocationController.java.html This static initializer block sets up VarHandles for atomic access to volatile fields like 'size', 'allocationCount', and 'failedAllocationCount' within the InlineAllocationController class. It uses MethodHandles.lookup() to find and create these VarHandles, ensuring thread-safe modifications. ```java static { try { MethodHandles.Lookup lookup = MethodHandles.lookup(); Class receiver = InlineAllocationController.class; SIZE = lookup.findVarHandle(receiver, "size", int.class); ALLOC_COUNT = lookup.findVarHandle(receiver, "allocationCount", long.class); FAILED_ALLOC_COUNT = lookup.findVarHandle(receiver, "failedAllocationCount", long.class); } catch (Exception e) { throw new LinkageError("Failed to create VarHandle.", e); } } ``` -------------------------------- ### ToString Method Source: http://chrisvest.github.io/stormpot/site/apidocs/stormpot/stormpot/Pooled.html Returns a string representation of the Pooled instance. ```java public java.lang.String toString() ```