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

de.team33.patterns.pooling.ariel.ProviderBase 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.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 ProviderBase extends Mutual {

    ProviderBase(final XSupplier, RuntimeException> 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! */ public final void run(final Consumer consumer) { 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 X if the execution of the given {@link XConsumer} causes one. */ public final void runEx(final XConsumer xConsumer) throws 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} */ public final R get(final Function function) { 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 X if the execution of the given {@link XFunction} causes one. */ public final R getEx(final XFunction xFunction) throws X { return apply(xFunction); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy