S - The type of provided instances (subjects)E - A type of exception that may be caused by the creation of new subject instances.public class XProvider<S,E extends Exception> extends Object
The tool maintains a number of such subjects and only creates as many as are actually required at most at the same time in its application context. The subjects are retained and reused for subsequent operations.
In this respect, this tool is suitable for providing subject 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 subject could be made available.
This implementation supports checked exceptions to occur while creating new subject instances.
Provider| Constructor and Description |
|---|
XProvider(XSupplier<S,E> newItem)
Initializes a new instance giving an
XSupplier that defines the intended initialization of a
new subject. |
| Modifier and Type | Method and Description |
|---|---|
<R> R |
get(Function<? super S,R> function)
Calls a given
Function with a parameter provided for it and returns its result. |
<R,X extends Exception> |
getEx(XFunction<? super S,R,X> xFunction)
Calls a given
XFunction with a parameter provided for it and returns its result. |
void |
run(Consumer<? super S> consumer)
Runs a given
Consumer with a parameter provided for it. |
<X extends Exception> |
runEx(XConsumer<? super S,X> xConsumer)
Runs a given
XConsumer with a parameter provided for it. |
int |
size()
Returns the number of currently unused subjects in stock.
|
public final <X extends Exception> void runEx(XConsumer<? super S,X> xConsumer) throws E extends Exception, X extends Exception
public final <R,X extends Exception> R getEx(XFunction<? super S,R,X> xFunction) throws E extends Exception, X extends Exception
public final int size()
Copyright © 2022 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.