qunar.tc.qconfig.servercommon.service.EnvironmentMappingService Maven / Gradle / Ivy
The newest version!
package qunar.tc.qconfig.servercommon.service;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import qunar.tc.qconfig.client.Configuration;
import qunar.tc.qconfig.client.Feature;
import qunar.tc.qconfig.client.MapConfig;
import qunar.tc.qconfig.common.util.Environment;
import javax.annotation.PostConstruct;
import java.util.Map;
@Service
public class EnvironmentMappingService {
private final Logger logger = LoggerFactory.getLogger(EnvironmentMappingService.class);
private static final String ENV_MAPPING_FILE = "env-mapping.properties";
private static final String DEFAULT_ENV_KEY = "_default";
private volatile static Optional DEFAULT_ENV = Optional.absent();
private volatile ImmutableMap envMapping = ImmutableMap.of();
@PostConstruct
public void init() {
MapConfig mapConfig = MapConfig.get(ENV_MAPPING_FILE, Feature.create().setFailOnNotExists(false).build());
mapConfig.asMap();
mapConfig.addListener(new Configuration.ConfigListener
© 2015 - 2024 Weber Informatics LLC | Privacy Policy