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

io.quarkiverse.unleash.runtime.UnleashRecorder Maven / Gradle / Ivy

The newest version!
package io.quarkiverse.unleash.runtime;

import java.util.function.Supplier;

import org.jboss.logging.Logger;

import io.getunleash.Unleash;
import io.quarkus.runtime.ApplicationConfig;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class UnleashRecorder {

    private static final Logger LOGGER = Logger.getLogger(UnleashRecorder.class);

    private final ApplicationConfig applicationConfig;
    private final RuntimeValue unleashRuntimeConfig;

    public UnleashRecorder(ApplicationConfig applicationConfig, RuntimeValue unleashRuntimeConfig) {
        this.applicationConfig = applicationConfig;
        this.unleashRuntimeConfig = unleashRuntimeConfig;
    }

    public Supplier getSupplier() {
        if (unleashRuntimeConfig.getValue().active()) {
            String app = unleashRuntimeConfig.getValue().appName().orElse(applicationConfig.name.orElse("default-app-name"));
            return new Supplier() {
                @Override
                public Unleash get() {
                    Unleash unleash = UnleashCreator.createUnleash(unleashRuntimeConfig.getValue(), app);
                    LOGGER.infof("Unleash client application '%s' fetch feature toggle names: %s", app,
                            unleash.more().getFeatureToggleNames());
                    return unleash;
                }
            };
        } else {
            return new Supplier() {
                @Override
                public Unleash get() {
                    LOGGER.info("Unleash extension disabled from configuration");
                    return new NoOpUnleash();
                }
            };
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy