de.team33.patterns.pooling.ariel.RProvider Maven / Gradle / Ivy
Show all versions of pooling-ariel Show documentation
package de.team33.patterns.pooling.ariel;
import de.team33.patterns.expiry.tethys.Recent;
import java.util.function.Supplier;
/**
* A tool that makes instances of a certain type available for the course of operations that require such an instance.
* The instances provided are referred to as item in the following.
*
* The tool maintains a number of such items and only creates as many as are actually required at most at
* the same time in its application context. The items are retained and reused for subsequent operations.
*
* In this respect, this tool is suitable for providing item types whose instantiation is relatively
* "expensive", which are rather unsuitable for concurrent access, but are designed for multiple or permanent use.
* Database or other client-server connections may be an example.
*
* Note: this implementation cannot detect when an internal operation is taking place in the course of an operation to
* which the same item could be made available.
*
* This implementation supports expiry and reinitialisation of provided items.
*
* This implementation does not support checked exceptions to occur while creating new item instances.
*
* @param The type of provided instances (items).
* @see Provider
* @see XProvider
* @see XRProvider
*/
public class RProvider extends ProviderBase {
/**
* Initializes a new instance giving a {@link Supplier} that defines the intended initialization of a
* new item.
*
* Once an instance item is initialized it will expire and be renewed after a maximum idle time
* or at least after a maximum lifetime.
*/
public RProvider(final Supplier newItem, final long maxIdle, final long maxLiving) {
super(() -> new Recent<>(newItem, maxIdle, maxLiving)::get);
}
}