Java Code Examples for com.netflix.config.DynamicStringProperty

The following examples show how to use com.netflix.config.DynamicStringProperty. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-cloud-huawei   Source File: RouterRuleCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 每次序列化额外缓存,配置更新时触发回调函数 返回false即初始化规则失败: 1. 规则解析错误 2. 规则为空
 *
 * @param targetServiceName
 * @return
 */
public static boolean doInit(String targetServiceName) {
  if (!isServerContainRule(targetServiceName)) {
    return false;
  }
  if (!serviceInfoCacheMap.containsKey(targetServiceName)) {
    synchronized (servicePool.intern(targetServiceName)) {
      if (serviceInfoCacheMap.containsKey(targetServiceName)) {
        return true;
      }
      //Yaml not thread-safe
      DynamicStringProperty ruleStr = DynamicPropertyFactory.getInstance().getStringProperty(
          String.format(ROUTE_RULE, targetServiceName), null, () -> {
            refresh(targetServiceName);
            DynamicStringProperty tepRuleStr = DynamicPropertyFactory.getInstance()
                .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
            addAllRule(targetServiceName, tepRuleStr.get());
          });
      return addAllRule(targetServiceName, ruleStr.get());
    }
  }
  return true;
}
 
Example 2
Source Project: servicecomb-java-chassis   Source File: RouterRuleCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * cache and register callback return false when: 1. parsing error 2. rule is null
 *
 * @param targetServiceName
 * @return
 */
public static boolean doInit(String targetServiceName) {
  if (!isServerContainRule(targetServiceName)) {
    return false;
  }
  if (!serviceInfoCacheMap.containsKey(targetServiceName)) {
    synchronized (servicePool.intern(targetServiceName)) {
      if (serviceInfoCacheMap.containsKey(targetServiceName)) {
        return true;
      }
      //Yaml not thread-safe
      DynamicStringProperty ruleStr = DynamicPropertyFactory.getInstance().getStringProperty(
          String.format(ROUTE_RULE, targetServiceName), null, () -> {
            refresh(targetServiceName);
            DynamicStringProperty tepRuleStr = DynamicPropertyFactory.getInstance()
                .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
            addAllRule(targetServiceName, tepRuleStr.get());
          });
      return addAllRule(targetServiceName, ruleStr.get());
    }
  }
  return true;
}
 
Example 3
Source Project: zuul   Source File: SurgicalDebugFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public HttpRequestMessage apply(HttpRequestMessage request) {
    DynamicStringProperty routeVip = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_VIP, null);
    DynamicStringProperty routeHost = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_HOST, null);

    SessionContext ctx = request.getContext();

    if (routeVip.get() != null || routeHost.get() != null) {

        ctx.set("routeHost", routeHost.get());
        ctx.set("routeVIP", routeVip.get());

        request.getHeaders().set(ZuulHeaders.X_ZUUL_SURGICAL_FILTER, "true");

        HttpQueryParams queryParams = request.getQueryParams();
        queryParams.set("debugRequest", "true");

        ctx.setDebugRequest(true);
        ctx.set("zuulToZuul", true);

    }
    return request;
}
 
Example 4
Source Project: spring-cloud-huawei   Source File: RouterRuleCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * if a server don't have rule , avoid registered too many callback , it may cause memory leak
 *
 * @param targetServiceName
 * @return
 */
public static boolean isServerContainRule(String targetServiceName) {
  DynamicStringProperty lookFor = DynamicPropertyFactory.getInstance()
      .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
  if (StringUtils.isEmpty(lookFor.get())) {
    return false;
  }
  return true;
}
 
Example 5
Source Project: spring-cloud-huawei   Source File: RouterDistributorTest.java    License: Apache License 2.0 5 votes vote down vote up
private List<ServiceIns> mainFilter(List<ServiceIns> serverlist, Map<String, String> headermap) {
  TestDistributer TestDistributer = new TestDistributer();
  DynamicPropertyFactory dpf = DynamicPropertyFactory.getInstance();
  DynamicStringProperty strp = new DynamicStringProperty("", ruleStr);
  new Expectations(dpf) {
    {
      dpf.getStringProperty(anyString, null, (Runnable) any);
      result = strp;
    }
  };
  RouterRuleCache.refresh();
  return RouterFilter
      .getFilteredListOfServers(serverlist, targetServiceName, headermap,
          TestDistributer);
}
 
Example 6
Source Project: spring-cloud-huawei   Source File: HeaderPassUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isHaveHeadersRule() {
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
  if (StringUtils.isEmpty(headerStr)) {
    return false;
  }
  return true;
}
 
Example 7
Source Project: spring-cloud-huawei   Source File: HeaderPassUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean loadHeaders() {
  if (!CollectionUtils.isEmpty(passHeader)) {
    return true;
  }
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null, () -> {
        DynamicStringProperty temHeader = DynamicPropertyFactory.getInstance()
            .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
        if (!addAllHeaders(temHeader.get())) {
          passHeader = new ArrayList<>();
        }
      });
  return addAllHeaders(headerStr.get());
}
 
Example 8
Source Project: s2g-zuul   Source File: InitializeServletListener.java    License: MIT License 5 votes vote down vote up
private void registerEureka() {
	DynamicBooleanProperty eurekaEnabled = DynamicPropertyFactory.getInstance().getBooleanProperty("eureka.enabled",
			true);
	if (!eurekaEnabled.get())
		return;

	EurekaInstanceConfig eurekaInstanceConfig = new PropertiesInstanceConfig() {
	};
       ConfigurationManager.getConfigInstance().setProperty("eureka.statusPageUrl","http://"+ getTurbineInstance());

	DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, new DefaultEurekaClientConfig());

	final DynamicStringProperty serverStatus = DynamicPropertyFactory.getInstance()
			.getStringProperty("server." + IPUtil.getLocalIP() + ".status", "up");
	DiscoveryManager.getInstance().getDiscoveryClient().registerHealthCheckCallback(new HealthCheckCallback() {
		@Override
		public boolean isHealthy() {
			return serverStatus.get().toLowerCase().equals("up");
		}
	});

	String version = String.valueOf(System.currentTimeMillis());
	String group = ConfigurationManager.getConfigInstance().getString("server.group", "default");
	String dataCenter = ConfigurationManager.getConfigInstance().getString("server.data-center", "default");

	Map<String, String> metadata = new HashMap<String, String>();
	metadata.put("version", version);
	metadata.put("group", group);
	metadata.put("dataCenter", dataCenter);

	String turbineInstance = getTurbineInstance();
	if (turbineInstance != null) {
		metadata.put("turbine.instance", turbineInstance);
	}

	ApplicationInfoManager.getInstance().registerAppMetadata(metadata);
}
 
Example 9
/**
 * read config and get Header
 */
private boolean loadHeaders() {
  if (!CollectionUtils.isEmpty(allHeader)) {
    return true;
  }
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null, () -> {
        DynamicStringProperty temHeader = DynamicPropertyFactory.getInstance()
            .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
        if (!addAllHeaders(temHeader.get())) {
          allHeader = new ArrayList<>();
        }
      });
  return addAllHeaders(headerStr.get());
}
 
Example 10
/**
 * if don't have headers rule , avoid registered too many callback
 */
private boolean isHaveHeadersRule() {
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
  if (StringUtils.isEmpty(headerStr)) {
    return false;
  }
  return true;
}
 
Example 11
Source Project: servicecomb-java-chassis   Source File: RouterRuleCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * if a server don't have rule , avoid registered too many callback , it may cause memory leak
 *
 * @param targetServiceName
 * @return
 */
public static boolean isServerContainRule(String targetServiceName) {
  DynamicStringProperty lookFor = DynamicPropertyFactory.getInstance()
      .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
  if (StringUtils.isEmpty(lookFor.get())) {
    return false;
  }
  return true;
}
 
Example 12
private List<ServiceIns> mainFilter(List<ServiceIns> serverlist, Map<String, String> headermap) {
  RouterDistributor<ServiceIns, ServiceIns> testDistributer = new TestDistributer();
  DynamicPropertyFactory dpf = DynamicPropertyFactory.getInstance();
  DynamicStringProperty strp = new DynamicStringProperty("", ruleStr);
  new Expectations(dpf) {
    {
      dpf.getStringProperty(anyString, null, (Runnable) any);
      result = strp;
    }
  };
  RouterRuleCache.refresh();
  return RouterFilter
      .getFilteredListOfServers(serverlist, targetServiceName, headermap,
          testDistributer);
}
 
Example 13
protected void setProp(String serviceId, String suffix, String value) {
	// how to set the namespace properly?
	String key = getKey(serviceId, suffix);
	DynamicStringProperty property = getProperty(key);
	if (property.get().equals(VALUE_NOT_SET)) {
		ConfigurationManager.getConfigInstance().setProperty(key, value);
	}
}
 
Example 14
protected void setProp(String serviceId, String suffix, String value) {
	// how to set the namespace properly?
	String key = getKey(serviceId, suffix);
	DynamicStringProperty property = getProperty(key);
	if (property.get().equals(VALUE_NOT_SET)) {
		ConfigurationManager.getConfigInstance().setProperty(key, value);
	}
}
 
Example 15
Source Project: suro   Source File: DynamicPropertyInputConfigurator.java    License: Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    DynamicStringProperty inputFP = new DynamicStringProperty(INPUT_CONFIG_PROPERTY, initialInputConfig) {
        @Override
        protected void propertyChanged() {
            buildInput(get(), false);
        }
    };

    buildInput(inputFP.get(), true);
}
 
Example 16
@PostConstruct
public void init() {
    DynamicStringProperty routingMapFP = new DynamicStringProperty(ROUTING_MAP_PROPERTY, initialRoutingMap) {
        @Override
        protected void propertyChanged() {
            buildMap(get());
        }
    };

    buildMap(routingMapFP.get());
}
 
Example 17
Source Project: suro   Source File: DynamicPropertySinkConfigurator.java    License: Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    DynamicStringProperty sinkDescription = new DynamicStringProperty(SINK_PROPERTY, initialSink) {
        @Override
        protected void propertyChanged() {
            buildSink(get(), false);
        }
    };

    buildSink(sinkDescription.get(), true);
}
 
Example 18
@Override
public String getStringProperty(String propertyName, Consumer<String> consumer, String defaultValue) {
  DynamicStringProperty prop = propertyFactoryInstance().getStringProperty(propertyName, defaultValue);
  prop.addCallback(() -> consumer.accept(prop.get()));
  return prop.get();
}
 
Example 19
public HttpVersion getHttpVersion() {
  DynamicStringProperty property =
      DynamicPropertyFactory.getInstance()
          .getStringProperty("servicecomb.service.registry.client.httpVersion", "HTTP_1_1");
  return HttpVersion.valueOf(property.get());
}
 
Example 20
public DynamicStringProperty getManualCheckProperty() {
  return manualCheckProperty;
}
 
Example 21
Source Project: servicecomb-java-chassis   Source File: ServletConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static String getLocalServerAddress() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty(SERVICECOMB_REST_ADDRESS, null);
  return address.get();
}
 
Example 22
Source Project: servicecomb-java-chassis   Source File: ServletConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static String getServletUrlPattern() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty(KEY_SERVLET_URL_PATTERN, null);
  return address.get();
}
 
Example 23
Source Project: servicecomb-java-chassis   Source File: TransportConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static String getAddress() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.rest.address", null);
  return address.get();
}
 
Example 24
Source Project: servicecomb-java-chassis   Source File: HighwayConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static String getAddress() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.highway.address", null);
  return address.get();
}
 
Example 25
Source Project: AsuraFramework   Source File: ConfigSubscriber.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getString(String key, String defaultValue, Runnable callback) {
    final DynamicStringProperty property = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue, callback);
    return property.get();
}
 
Example 26
protected DynamicStringProperty getProperty(String key) {
	return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET);
}
 
Example 27
protected DynamicStringProperty getProperty(String key) {
	return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET);
}
 
Example 28
Source Project: dyno   Source File: ArchaiusConnectionPoolConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
public void setDualWriteClusterName(DynamicStringProperty stringProperty) {
    this.dualWriteClusterName = stringProperty;
}
 
Example 29
Source Project: AsuraFramework   Source File: ConfigSubscriber.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @param key
 *         配置项的key
 * @param defaultValue
 *         如果取回的配置项值为空, 应该返回的默认值
 *
 * @return 配置项的值
 */
@Override
public String getString(String key, String defaultValue) {
    final DynamicStringProperty property = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue);
    return property.get();
}