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

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

Go to download

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

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

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

import java.util.function.Consumer;
import java.util.function.Function;

class XProviderBase extends Mutual {

    XProviderBase(final XSupplier, E> newItem) {
        super(newItem);
    }

    /**
     * Runs a given {@link Consumer} with a parameter provided for it. The parameter is kept for future use.
     * 

* While the {@link Consumer} is being executed, the parameter is exclusively available to it, but must not be * "hijacked" from the context of the execution or the executing thread! * * @throws E if the initialization of a new item causes one. */ public final void run(final Consumer consumer) throws E { accept(consumer::accept); } /** * Runs a given {@link XConsumer} with a parameter provided for it. The parameter is kept for future use. *

* While the {@link XConsumer} is being executed, the parameter is exclusively available to it, but must not be * "hijacked" from the context of the execution or the executing thread! * * @param A type of exception that may be caused by the given {@link XConsumer}. * @throws E if the initialization of a new item causes one. * @throws X if the execution of the given {@link XConsumer} causes one. */ public final void runEx(final XConsumer xConsumer) throws E, X { accept(xConsumer); } /** * Calls a given {@link Function} with a parameter provided for it and returns its result. * The parameter is kept for future use. *

* While the {@link Function} is being called, the parameter is exclusively available to it, but must not be * "hijacked" from the context of the call or the executing thread! * * @param The result type of the given {@link Function} * @throws E if the initialization of a new item causes one. */ public final R get(final Function function) throws E { return apply(function::apply); } /** * Calls a given {@link XFunction} with a parameter provided for it and returns its result. * The parameter is kept for future use. *

* While the {@link XFunction} is being called, the parameter is exclusively available to it, but must not be * "hijacked" from the context of the call or the executing thread! * * @param The result type of the given {@link XFunction} * @param A type of exception that may be caused by the given {@link XFunction}. * @throws E if the initialization of a new item causes one. * @throws X if the execution of the given {@link XFunction} causes one. */ public final R getEx(final XFunction xFunction) throws E, X { return apply(xFunction); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy