本文整理汇总了Java中org.cfg4j.source.context.environment.Environment类的典型用法代码示例。如果您正苦于以下问题:Java Environment类的具体用法?Java Environment怎么用?Java Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Environment类属于org.cfg4j.source.context.environment包,在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configurationProvider
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider = () -> Collections.singletonList(Paths.get("application.yaml"));
// Use local files as configuration store
ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
// Use relative paths
Environment environment = new ImmutableEnvironment(filesPath);
// Reload configuration every 500 milliseconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(500, TimeUnit.MILLISECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withReloadStrategy(reloadStrategy)
.withEnvironment(environment)
.withMetrics(metricRegistry, "firstProvider.")
.build();
}
示例2: configurationProvider
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Use Git repository as configuration store
ConfigurationSource source = new GitConfigurationSourceBuilder()
.withRepositoryURI(configRepoPath)
.build();
// Select branch to use (use new DefaultEnvironment()) for master
Environment environment = new ImmutableEnvironment(branch);
// Reload configuration every 5 seconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withEnvironment(environment)
.withReloadStrategy(reloadStrategy)
.build();
}
示例3: configurationProvider
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("application.properties"), Paths.get("otherConfig.properties"));
// Use Git repository as configuration store
ConfigurationSource source = new GitConfigurationSourceBuilder()
.withRepositoryURI(configRepoPath)
.withConfigFilesProvider(configFilesProvider)
.build();
// Select branch to use (use new DefaultEnvironment()) for master
Environment environment = new ImmutableEnvironment(branch);
// Reload configuration every 5 seconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withEnvironment(environment)
.withReloadStrategy(reloadStrategy)
.build();
}
示例4: configurationProvider
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Bean
public ConfigurationProvider configurationProvider() {
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("application.yaml"), Paths.get("otherConfig.properties"));
// Use local files as configuration store
ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
// Use relative paths
Environment environment = new ImmutableEnvironment(filesPath);
// Reload configuration every 5 seconds
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
// Create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withReloadStrategy(reloadStrategy)
.withEnvironment(environment)
.build();
}
示例5: getConfiguration
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Override
public Properties getConfiguration(Environment environment) {
if (!initialized) {
throw new IllegalStateException("Configuration source has to be successfully initialized before you request configuration.");
}
environmentVariables.clear();
environmentVariables.putAll(System.getenv());
Properties properties = new Properties();
String environmentContext = formatEnvironmentContext(environment);
for (Map.Entry<String, String> entry : environmentVariables.entrySet()) {
if (entry.getKey().startsWith(environmentContext)) {
properties.put(convertToPropertiesKey(entry.getKey(), environmentContext), entry.getValue());
}
}
return properties;
}
示例6: getConfiguration
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Override
public Properties getConfiguration(Environment environment) {
Properties properties = new Properties();
for (ConfigurationSource source : sources) {
Properties configuration = source.getConfiguration(environment);
Map<Object, Object> filtered = configuration.entrySet().stream()
.filter(entry -> !entry.getValue().toString().isEmpty())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
properties.putAll(filtered);
}
return properties;
}
示例7: getConfiguration
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Override
public Properties getConfiguration(Environment environment) {
Timer.Context context = getConfigurationTimer.time();
try {
return delegate.getConfiguration(environment);
} finally {
context.stop();
}
}
示例8: getConfiguration
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
/**
* Get configuration set for a given {@code environment} from this source in a form of {@link Properties}. The configuration
* set is a result of a merge of provided {@link ConfigurationSource} configurations. In case of key collision
* last-match wins merge strategy is used.
*
* @param environment environment to use
* @return configuration set for {@code environment}
* @throws MissingEnvironmentException when requested environment couldn't be found
* @throws IllegalStateException when unable to fetch configuration from one of the underlying sources
*/
@Override
public Properties getConfiguration(Environment environment) {
Properties properties = new Properties();
for (ConfigurationSource source : sources) {
Properties sourceProperties = source.getConfiguration(environment);
properties.putAll(sourceProperties);
}
return properties;
}
示例9: formatEnvironmentContext
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
/**
* Format the provided {@link Environment} to ensure it ends with an underscore
*
* @param environment The provided {@link Environment} context
* @return The formatted {@link String} of the {@link Environment} context
*/
private static String formatEnvironmentContext(Environment environment) {
String environmentName = environment.getName();
if (environmentName == null || environmentName.isEmpty()) {
return "";
} else {
return environmentName.endsWith("_") ? environmentName : environmentName + "_";
}
}
示例10: getConfigurationCallsDelegate
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Test
public void getConfigurationCallsDelegate() throws Exception {
Properties properties = new Properties();
when(delegate.getConfiguration(any(Environment.class))).thenReturn(properties);
assertThat(source.getConfiguration(new DefaultEnvironment())).isEqualTo(properties);
}
示例11: getConfigurationPropagatesMissingEnvironmentExceptions
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Test
public void getConfigurationPropagatesMissingEnvironmentExceptions() throws Exception {
when(delegate.getConfiguration(any(Environment.class))).thenThrow(new MissingEnvironmentException(""));
expectedException.expect(MissingEnvironmentException.class);
source.getConfiguration(new DefaultEnvironment());
}
示例12: getConfigurationPropagatesIllegalStateExceptions
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Test
public void getConfigurationPropagatesIllegalStateExceptions() throws Exception {
when(delegate.getConfiguration(any(Environment.class))).thenThrow(new IllegalStateException(""));
expectedException.expect(IllegalStateException.class);
source.getConfiguration(new DefaultEnvironment());
}
示例13: getConfigurationReturnsReloadResult
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Test
public void getConfigurationReturnsReloadResult() throws Exception {
Properties properties = new Properties();
when(delegateSource.getConfiguration(any(Environment.class))).thenReturn(properties);
cachedConfigurationSource.reload(new DefaultEnvironment());
assertThat(cachedConfigurationSource.getConfiguration(new DefaultEnvironment())).isEqualTo(properties);
}
示例14: getConfigurationDoesNotChangeValueBetweenReloads
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Test
public void getConfigurationDoesNotChangeValueBetweenReloads() throws Exception {
Properties properties = new Properties();
when(delegateSource.getConfiguration(any(Environment.class))).thenReturn(properties);
cachedConfigurationSource.reload(new DefaultEnvironment());
Properties newProperties = new Properties();
newProperties.put("testConfig", "testValue");
when(delegateSource.getConfiguration(any(Environment.class))).thenReturn(newProperties);
assertThat(cachedConfigurationSource.getConfiguration(new DefaultEnvironment())).isEqualTo(properties);
}
示例15: reloadPropagatesMissingEnvExceptions
import org.cfg4j.source.context.environment.Environment; //导入依赖的package包/类
@Test
public void reloadPropagatesMissingEnvExceptions() throws Exception {
when(delegateSource.getConfiguration(any(Environment.class))).thenThrow(new MissingEnvironmentException(""));
expectedException.expect(MissingEnvironmentException.class);
cachedConfigurationSource.reload(new DefaultEnvironment());
}