当前位置: 首页>>代码示例>>Java>>正文


Java Environment类代码示例

本文整理汇总了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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:23,代码来源:ConfigBeans.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:21,代码来源:ConfigBeans.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:25,代码来源:ConfigBeans.java

示例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();
}
 
开发者ID:cfg4j,项目名称:cfg4j-sample-apps,代码行数:22,代码来源:ConfigBeans.java

示例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;
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:22,代码来源:EnvironmentVariablesConfigurationSource.java

示例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;
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:15,代码来源:SkipMissingConfigurationSource.java

示例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();
  }
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:11,代码来源:MeteredConfigurationSource.java

示例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;
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:22,代码来源:MergeConfigurationSource.java

示例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 + "_";
  }
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:16,代码来源:EnvironmentVariablesConfigurationSource.java

示例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);
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:MeteredConfigurationSourceTest.java

示例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());
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:MeteredConfigurationSourceTest.java

示例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());
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:MeteredConfigurationSourceTest.java

示例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);
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:9,代码来源:CachedConfigurationSourceTest.java

示例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);
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:14,代码来源:CachedConfigurationSourceTest.java

示例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());
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:8,代码来源:CachedConfigurationSourceTest.java


注:本文中的org.cfg4j.source.context.environment.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。