當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurationManager.getDeploymentContext方法代碼示例

本文整理匯總了Java中com.netflix.config.ConfigurationManager.getDeploymentContext方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurationManager.getDeploymentContext方法的具體用法?Java ConfigurationManager.getDeploymentContext怎麽用?Java ConfigurationManager.getDeploymentContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.netflix.config.ConfigurationManager的用法示例。


在下文中一共展示了ConfigurationManager.getDeploymentContext方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initWithNiwsConfig

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Override
public void initWithNiwsConfig(IClientConfig niwsClientConfig) {
    String sZoneAffinity = "" + niwsClientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity, false);
    if (sZoneAffinity != null){
        zoneAffinity = Boolean.parseBoolean(sZoneAffinity);
        logger.debug("ZoneAffinity is set to {}", zoneAffinity);
    }
    String sZoneExclusive = "" + niwsClientConfig.getProperty(CommonClientConfigKey.EnableZoneExclusivity, false);
    if (sZoneExclusive != null){
        zoneExclusive = Boolean.parseBoolean(sZoneExclusive);
    }
    if (ConfigurationManager.getDeploymentContext() != null) {
        zone = ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone);
    }
    activeReqeustsPerServerThreshold = DynamicPropertyFactory.getInstance().getDoubleProperty(niwsClientConfig.getClientName() + "." + niwsClientConfig.getNameSpace() + ".zoneAffinity.maxLoadPerServer", 0.6d);
    logger.debug("activeReqeustsPerServerThreshold: {}", activeReqeustsPerServerThreshold.get());
    blackOutServerPercentageThreshold = DynamicPropertyFactory.getInstance().getDoubleProperty(niwsClientConfig.getClientName() + "." + niwsClientConfig.getNameSpace() + ".zoneAffinity.maxBlackOutServesrPercentage", 0.8d);
    logger.debug("blackOutServerPercentageThreshold: {}", blackOutServerPercentageThreshold.get());
    availableServersThreshold = DynamicPropertyFactory.getInstance().getIntProperty(niwsClientConfig.getClientName() + "." + niwsClientConfig.getNameSpace() + ".zoneAffinity.minAvailableServers", 2);
    logger.debug("availableServersThreshold: {}", availableServersThreshold.get());
    overrideCounter = Monitors.newCounter("ZoneAffinity_OverrideCounter");

    Monitors.registerObject("NIWSServerListFilter_" + niwsClientConfig.getClientName());
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:25,代碼來源:ZoneAffinityServerListFilter.java

示例2: getConfiguration

import com.netflix.config.ConfigurationManager; //導入方法依賴的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

示例3: getConfiguration

import com.netflix.config.ConfigurationManager; //導入方法依賴的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

示例4: getConfiguration

import com.netflix.config.ConfigurationManager; //導入方法依賴的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

示例5: initWithNiwsConfig

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Override
public void initWithNiwsConfig(IClientConfig niwsClientConfig) {
	super.initWithNiwsConfig(niwsClientConfig);
	if (ConfigurationManager.getDeploymentContext() != null) {
		this.zone = ConfigurationManager.getDeploymentContext().getValue(
				ContextKey.zone);
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-netflix,代碼行數:9,代碼來源:ZonePreferenceServerListFilter.java


注:本文中的com.netflix.config.ConfigurationManager.getDeploymentContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。