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


Java DynamicConfiguration类代码示例

本文整理汇总了Java中com.netflix.config.DynamicConfiguration的典型用法代码示例。如果您正苦于以下问题:Java DynamicConfiguration类的具体用法?Java DynamicConfiguration怎么用?Java DynamicConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DynamicConfiguration类属于com.netflix.config包,在下文中一共展示了DynamicConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLocalConfig

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
  ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();

  duplicateServiceCombConfigToCse(config,
      new ConcurrentMapConfiguration(new SystemConfiguration()),
      "configFromSystem");
  duplicateServiceCombConfigToCse(config,
      convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())),
      "configFromEnvironment");
  duplicateServiceCombConfigToCse(config,
      new DynamicConfiguration(
          new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()),
      "configFromYamlFile");

  return config;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:ConfigUtil.java

示例2: testFullOperation

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Test
public void testFullOperation() {
  // configuration from system properties
  ConcurrentMapConfiguration configFromSystemProperties =
      new ConcurrentMapConfiguration(new SystemConfiguration());
  // configuration from yaml file
  DynamicConfiguration configFromYamlFile =
      new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler());
  // create a hierarchy of configuration that makes
  // 1) dynamic configuration source override system properties
  ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
  finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
  finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
  Assert.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5);

  Object o = finalConfig.getProperty("zq");
  @SuppressWarnings("unchecked")
  List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
  Assert.assertEquals(3, listO.size());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:TestYAMLConfigurationSource.java

示例3: ArchaiusInitializingBeanPostProcessor

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
public ArchaiusInitializingBeanPostProcessor(ConfigurableApplicationContext applicationContext, AbstractPollingScheduler pollingScheduler, SpringEnvironmentPolledConfigurationSource polledConfigurationSource, List<ClasspathPropertySource> propertyBindings) {
  this.applicationContext = Objects.requireNonNull(applicationContext, "applicationContext");
  this.pollingScheduler = Objects.requireNonNull(pollingScheduler, "pollingScheduler");
  this.polledConfigurationSource = Objects.requireNonNull(polledConfigurationSource, "polledConfigurationSource");
  this.propertyBindings = propertyBindings != null ? propertyBindings : Collections.emptyList();
  initPropertyBindings();

  configurationInstance = new DynamicConfiguration(polledConfigurationSource, pollingScheduler);
  if (!ConfigurationManager.isConfigurationInstalled()) {
    ConfigurationManager.install(new CompositeConfiguration());
  }
  CompositeConfiguration config = (CompositeConfiguration) ConfigurationManager.getConfigInstance();
  config.addConfiguration(configurationInstance);

  applicationContext.getBeanFactory().registerSingleton("environmentBackedConfig", ConfigurationManager.getConfigInstance());
  applicationContext.getBeanFactory().registerAlias("environmentBackedConfig", "abstractConfiguration");
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:18,代码来源:ArchaiusConfiguration.java

示例4: duplicateServiceCombConfigToCseListValue

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Test
public void duplicateServiceCombConfigToCseListValue() throws Exception {
  List<String> list = Arrays.asList("a", "b");

  AbstractConfiguration config = new DynamicConfiguration();
  config.addProperty("servicecomb.list", list);
  Deencapsulation.invoke(ConfigUtil.class, "duplicateServiceCombConfigToCse", config);

  Object result = config.getProperty("cse.list");
  assertThat(result, instanceOf(List.class));
  assertThat(result, equalTo(list));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:TestConfigUtil.java

示例5: testConvertEnvVariable

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Test
public void testConvertEnvVariable() {
  String someProperty = "cse_service_registry_address";
  AbstractConfiguration config = new DynamicConfiguration();
  config.addProperty(someProperty, "testing");
  AbstractConfiguration result = ConfigUtil.convertEnvVariable(config);
  assertThat(result.getString("cse.service.registry.address"), equalTo("testing"));
  assertThat(result.getString("cse_service_registry_address"), equalTo("testing"));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:10,代码来源:TestConfigUtil.java

示例6: testExtendedClassCompatible

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Test
public void testExtendedClassCompatible() {
  Configuration configuration = new DynamicConfiguration();
  configuration.setProperty(CONFIG_SERVICE_DESCRIPTION_KEY + AbstractPropertiesLoader.EXTENDED_CLASS, "invalidClass");

  AbstractPropertiesLoader loader = MicroservicePropertiesLoader.INSTANCE;
  try {
    loader.loadProperties(configuration);
    Assert.fail("Must throw exception");
  } catch (Error e) {
    Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass());
    Assert.assertEquals("invalidClass", e.getCause().getMessage());
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:TestPropertiesLoader.java

示例7: locate

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Override
	public PropertySource<?> locate(Environment environment) {
		
		try {
			// configuration from local properties file
			ConcurrentMapConfiguration configFromPropertiesFile = new ConcurrentMapConfiguration(new PropertiesConfiguration("application.yml"));
			
			// configuration from system properties
			ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
			
			// configuration from a dynamic source
//			PolledConfigurationSource source = new NetflixUrlPolledConfigurationSource();
			PolledConfigurationSource source = new NetflixEurekaPolledConfigurationSource();
			AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler();
			DynamicConfiguration dynamicConfiguration = new DynamicConfiguration(source, scheduler);
			
			// create a hierarchy of configuration that makes
			// 1) dynamic configuration source override system properties
			// 2) system properties override properties file
			ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
			finalConfig.addConfiguration(dynamicConfiguration, "dynamicConfig");
			finalConfig.addConfiguration(configFromSystemProperties, "systemConfig");
			finalConfig.addConfiguration(configFromPropertiesFile, "fileConfig");
			
			// install with ConfigurationManager so that finalConfig
			// becomes the source of dynamic properties
			ConfigurationManager.install(finalConfig);
		} catch(Exception e) {
			logger.error(e.getMessage());
		}
		
		return null;
	}
 
开发者ID:colddew,项目名称:micro-service-netflix,代码行数:34,代码来源:NetflixPropertySourceLocator.java

示例8: getConfiguration

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Override
protected AbstractConfiguration getConfiguration() throws ConfigNotFoundException {

  AbstractConfiguration config = ConfigurationManager.getConfigInstance();

  boolean dynamic = config.getBoolean(DYNAMIC_CONFIG, true);
  if (!dynamic) {
    return new DynamicConfiguration();
  }

  String appId;
  DeploymentContext context = ConfigurationManager.getDeploymentContext();
  appId = context.getApplicationId();
  if (appId == null) {
    LOG.info(
      "No applicationId set on archaius deployment context. Will try to use the 'application' property as fallback.");
    appId = config.getString("application");
  }

  if (appId == null) {
    throw new RuntimeException(
      "Archaius deployment context's applicationId not set nor property 'application' found");
  }

  String[] etcdHosts = config.getStringArray(ETCD_HOSTS);

  Etcd etcdClient;
  if(etcdHosts != null && etcdHosts.length > 0) {
    URI[] etcdHostURIs = Arrays.stream(etcdHosts).map(URI::create).toArray(URI[]::new);
    etcdClient = ClientBuilder.builder().hosts(etcdHostURIs).createClient();
  } else {
    throw new ConfigNotFoundException("No etcd hosts configured. Could not create etcd client");
  }


  EtcdConfigurationSource configSource = new EtcdConfigurationSource(etcdClient, appId);

  return new DynamicWatchedConfiguration(configSource);
}
 
开发者ID:irenical,项目名称:jindy,代码行数:40,代码来源:ArchaiusEtcdFactory.java

示例9: getConfiguration

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Override
protected AbstractConfiguration getConfiguration() throws Exception {
  AbstractConfiguration config = ConfigurationManager.getConfigInstance();
  boolean dynamic = config.getBoolean(DYNAMIC_CONFIG, true);
  if (!dynamic) {
    return new DynamicConfiguration();
  }

  String appId = null;
  DeploymentContext context = ConfigurationManager.getDeploymentContext();
  appId = context.getApplicationId();
  if (appId == null) {
    LOG.info(
      "No applicationId set on archaius deployment context. Will try to use the 'application' property as fallback.");
    appId = config.getString("application");
  }

  if (appId == null) {
    throw new RuntimeException(
      "Archaius deployment context's applicationId not set nor property 'application' found");
  }

  String zooKeeperConnString = config.getString(ZOOKEEPER_HOSTS);
  String rootConfigPath = "/" + appId;

  CuratorFramework client = CuratorFrameworkFactory.newClient(zooKeeperConnString, new ExponentialBackoffRetry(1000, 3));
  ZooKeeperConfigurationSource configSource = new ZooKeeperConfigurationSource(client, rootConfigPath);

  // do the first update synchronously
  try {
    client.start();
    configSource.start();
  } catch (Exception e) {
    configSource.close();
    throw e;
  }

  return new DynamicWatchedConfiguration(configSource);
}
 
开发者ID:irenical,项目名称:jindy,代码行数:40,代码来源:ArchaiusZooKeeperFactory.java

示例10: getConfiguration

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Override
protected AbstractConfiguration getConfiguration() {

  AbstractConfiguration config = ConfigurationManager.getConfigInstance();
  boolean dynamic = config.getBoolean(DYNAMIC_CONFIG, true);
  if (!dynamic) {
    return new DynamicConfiguration();
  } else {
    String appId = null;
    DeploymentContext context = ConfigurationManager.getDeploymentContext();
    appId = context.getApplicationId();
    
    if (appId == null) {
      throw new RuntimeException(
          "Archaius deployment context's applicationId not set (archaius.deployment.applicationId)");
    }

    String consulHost = config.getString(CONSUL_HOST, CONSUL_DEFAULT_HOST);
    int consulPort = config.getInt(CONSUL_PORT, 8500);
    String consulAclToken = config.getString(CONSUL_TOKEN);

    ConsulWatchedConfigurationSource configSource = new ConsulWatchedConfigurationSource(appId,
        new ConsulClient(consulHost, consulPort), 30, TimeUnit.SECONDS, consulAclToken);

    // do the first update synchronously
    try {
      configSource.runOnce();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }

    configSource.startAsync();

    return new DynamicWatchedConfiguration(configSource);
  }
}
 
开发者ID:irenical,项目名称:jindy,代码行数:37,代码来源:ArchaiusConsulFactory.java

示例11: toSourceName

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
public static String toSourceName(Configuration config) {
    if (config instanceof NamedConfigurationSource) {
        return ((NamedConfigurationSource) config).getSourceName();
    }

    if (config instanceof DynamicConfiguration) {
        return ((DynamicConfiguration) config).getSource().getClass().getName();
    }

    return config == null ? null : config.getClass().getName();
}
 
开发者ID:rancher,项目名称:cattle,代码行数:12,代码来源:ArchaiusUtil.java

示例12: refresh

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
protected void refresh(AbstractConfiguration config) {
    if ( config instanceof DynamicConfiguration && ((DynamicConfiguration)config).getSource() instanceof LazyJDBCSource ) {
        LazyJDBCSource source = (LazyJDBCSource) ((DynamicConfiguration)config).getSource();

        if ( configDataSource == null ) {
            configDataSource = dataSourceFactory.createDataSource(dataSourceName);
        }

        source.setSource(new JDBCConfigurationSource(configDataSource, query, keyColumnName, valueColumnName));
    }
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:12,代码来源:ArchaiusStartup.java

示例13: toString

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
protected String toString(Configuration config) {
    if ( config instanceof NamedConfigurationSource ) {
        return ((NamedConfigurationSource)config).getSourceName();
    }

    if ( config instanceof DynamicConfiguration ) {
        return ((DynamicConfiguration)config).getSource().getClass().getName();
    }

    return config == null ? null : config.getClass().getName();
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:12,代码来源:SettingManager.java

示例14: register

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
public void register(BreakerboxConfiguration breakerboxConfiguration) {
    if (breakerboxConfiguration.getUrls().isEmpty()) {
        return;
    }

    final TenacityPollingScheduler tenacityPollingScheduler = new TenacityPollingScheduler(
            Ints.checkedCast(breakerboxConfiguration.getInitialDelay().toMilliseconds()),
            Ints.checkedCast(breakerboxConfiguration.getDelay().toMilliseconds()),
            true);

    final CountDownLatch countDownLatch = new CountDownLatch(1);

    if (breakerboxConfiguration.isWaitForInitialLoad()) {
        tenacityPollingScheduler.addPollListener((eventType, lastResult, exception) -> countDownLatch.countDown());
    }

    final DynamicConfiguration dynConfig = new DynamicConfiguration(
            new URLConfigurationSource(breakerboxConfiguration.getUrls().split(",")),
            tenacityPollingScheduler);

    ConfigurationManager.getConfigInstance();
    ConfigurationManager.loadPropertiesFromConfiguration(dynConfig);

    if (breakerboxConfiguration.isWaitForInitialLoad()) {
        final Duration duration = breakerboxConfiguration.getWaitForInitialLoad();
        try {
            final boolean success = countDownLatch.await(duration.getQuantity(), duration.getUnit());
            LOGGER.info("Breakerbox initial configuration load: {}", success ? "SUCCESS" : "FAILURE");
        } catch (Exception err) {
            LOGGER.warn("Failed waiting for Breakerbox initial load", err);
        }
    }
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:34,代码来源:ArchaiusPropertyRegister.java

示例15: getConfiguration

import com.netflix.config.DynamicConfiguration; //导入依赖的package包/类
@Override
protected DynamicConfiguration getConfiguration() {
    return new DynamicConfiguration();
}
 
开发者ID:irenical,项目名称:jindy,代码行数:5,代码来源:ArchaiusConfigurationExample.java


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