io.nosqlbench.engine.api.scoping.ScopedSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of engine-api Show documentation
Show all versions of engine-api Show documentation
The engine API for nosqlbench;
Provides the interfaces needed to build internal modules for the
nosqlbench core engine
package io.nosqlbench.engine.api.scoping;
import java.util.function.Supplier;
/**
* Helper class to consolidate the notions of scoping items over different
* NB layers of execution.
*/
public enum ScopedSupplier {
/**
* Once a supplier is instantiated for singleton scope, it should provide only one instance of
* the supplied element for that instance. Multiple instances (separately constructed)
* of the supplier can each provide their own distinct supplied instance.
*/
singleton,
/**
* Once a supplier is instantiated for thread scope, it should provide a unique instance of
* the supplied element for each thread, according to the inner supplier's semantics.
*/
thread,
/**
* When a supplier is instantiated for caller scope, each time the supplier is accessed,
* it returns a new instance according to the inner supplier's semantics.
*/
caller;
public Supplier supplier(Supplier supplier) {
switch (this) {
case singleton:
T got = supplier.get();
return () -> got;
case thread:
ThreadLocal tlsupplier = ThreadLocal.withInitial(supplier);
return tlsupplier::get;
case caller:
return supplier;
default:
throw new RuntimeException("Unknown scope type:" + this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy