All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.team33.patterns.pooling.ariel.XProvider Maven / Gradle / Ivy

Go to download

Provides a simple pooling of "expensive", reusable but thread-sensitive instances.

There is a newer version: 1.21.0
Show newest version
package de.team33.patterns.pooling.ariel;

import de.team33.patterns.exceptional.dione.XSupplier;

/**
 * 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 checked exceptions to occur while creating new item instances. * * @param The type of provided instances (items) * @param A type of exception that may be caused by the creation of new item instances. * @see Provider * @see RProvider * @see XRProvider */ public class XProvider extends XProviderBase { /** * Initializes a new instance giving an {@link XSupplier} that defines the intended initialization of a * new item. */ public XProvider(final XSupplier newItem) { super(() -> { final I item = newItem.get(); return () -> item; }); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy