jdplus.sa.base.api.diagnostics.SeasonalityTestsLoader Maven / Gradle / Ivy
package jdplus.sa.base.api.diagnostics;
import java.lang.IllegalStateException;
import java.lang.Iterable;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.StreamSupport;
public final class SeasonalityTestsLoader {
/**
* Custom service loader for {@link jdplus.sa.base.api.diagnostics.SeasonalityTests.Factory}.
*
This class is thread-safe.
* Properties:
*
* - Quantifier: SINGLE
* - Fallback: null
* - Preprocessing: null
* - Mutability: CONCURRENT
* - Singleton: false
* - Name: null
* - Backend: null
* - Cleaner: null
* - Batch: false
* - Batch name: null
*
*/
public static final class Factory {
private final Iterable source = ServiceLoader.load(SeasonalityTests.Factory.class);
private final AtomicReference resource = new AtomicReference<>(doLoad());
private final Consumer cleaner = loader -> ((ServiceLoader)loader).reload();
private SeasonalityTests.Factory doLoad() throws IllegalStateException {
return StreamSupport.stream(source.spliterator(), false)
.findFirst()
.orElseThrow(() -> new IllegalStateException("Missing mandatory provider of SeasonalityTests.Factory"));
}
/**
* Gets a {@link jdplus.sa.base.api.diagnostics.SeasonalityTests.Factory} instance.
*
This method is thread-safe.
* @return the current non-null value
*/
public SeasonalityTests.Factory get() {
return resource.get();
}
/**
* Sets a {@link jdplus.sa.base.api.diagnostics.SeasonalityTests.Factory} instance.
*
This method is thread-safe.
* @param newValue new non-null value
*/
public void set(SeasonalityTests.Factory newValue) {
resource.set(Objects.requireNonNull(newValue));
}
/**
* Reloads the content by clearing the cache and fetching available providers.
*
This method is thread-safe.
*/
public void reload() throws IllegalStateException {
synchronized(source) {
cleaner.accept(source);
set(doLoad());
}
}
/**
* Resets the content without clearing the cache.
*
This method is thread-safe.
*/
public void reset() throws IllegalStateException {
synchronized(source) {
set(doLoad());
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy