de.otto.edison.togglz.configuration.InMemoryFeatureStateRepositoryConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edison-togglz Show documentation
Show all versions of edison-togglz Show documentation
Status library of the edison-microservice project.
package de.otto.edison.togglz.configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.togglz.core.Feature;
import org.togglz.core.repository.FeatureState;
import org.togglz.core.repository.StateRepository;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class InMemoryFeatureStateRepositoryConfiguration {
@Bean
@ConditionalOnMissingBean(StateRepository.class)
public StateRepository stateRepository() {
return createInMemoryStateRepository();
}
private StateRepository createInMemoryStateRepository() {
return new StateRepository() {
Logger LOG = LoggerFactory.getLogger(TogglzConfiguration.class);
private Map featureStore = new HashMap<>();
@Override
public FeatureState getFeatureState(final Feature feature) {
if (featureStore.containsKey(feature.name())) {
return featureStore.get(feature.name());
}
return new FeatureState(feature, false);
}
@Override
public void setFeatureState(final FeatureState featureState) {
featureStore.put(featureState.getFeature().name(), featureState);
LOG.info("Switched feature state to " + featureState.toString());
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy