Java Code Examples for com.netflix.config.DynamicPropertyFactory#getBackingConfigurationSource()

The following examples show how to use com.netflix.config.DynamicPropertyFactory#getBackingConfigurationSource() . 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 File: ITBootListener.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected void selectPort(String cfgKey) {
  String endpoint = DynamicPropertyFactory.getInstance().getStringProperty(cfgKey, null).get();
  if (endpoint == null) {
    return;
  }

  URI uri = URI.create("http://" + endpoint);
  if (uri.getPort() == 0) {
    int port = getRandomPort();
    try {
      ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
          .getBackingConfigurationSource();
      endpoint = new URIBuilder("http://" + endpoint).setPort(port).build().toString().substring(7);
      config.getConfiguration(0).setProperty(cfgKey, endpoint);
      LOGGER.info("change {} to {}.", cfgKey, endpoint);
    } catch (URISyntaxException e) {
      throw new IllegalStateException("Failed to build endpoint.", e);
    }
  }
}
 
Example 2
Source File: EdgeBootListener.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public void onBootEvent(BootEvent event) {
  if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
    return;
  }

  TransportClientConfig.setRestTransportClientCls(EdgeRestTransportClient.class);
  TransportConfig.setRestServerVerticle(EdgeRestServerVerticle.class);

  String defaultExecutor = DynamicPropertyFactory.getInstance()
      .getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null)
      .get();
  if (defaultExecutor != null) {
    LOGGER.info("Edge service default executor is {}.", defaultExecutor);
    return;
  }

  // change default to reactive mode
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_REACTIVE);
  LOGGER.info("Set ReactiveExecutor to be edge service default executor.");
}
 
Example 3
Source File: RestServletInitializer.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("try")
public void onStartup(ServletContext servletContext) throws ServletException {
  if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
    // ensure the servlet will be instantiated
    Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
    configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
  }

  if (this.factory == null) {
    // when running in external tomcat, WebServerFactoryCustomizer will not be available, but now tomcat
    // is already listening and we can call ServletUtils.init directly.
    ServletUtils.init(servletContext);
    return;
  }

  if (factory.getPort() == 0) {
    LOGGER.warn(
        "spring boot embedded web container listen port is 0, ServiceComb will not use container's port to handler REST request.");
    return;
  }

  // when running in embedded tomcat, web container did not listen now. Call ServletUtils.init needs server is ready,
  // so mock to listen, and then close.
  try (ServerSocket ss = new ServerSocket(factory.getPort(), 0, factory.getAddress())) {
    ServletUtils.init(servletContext);
  } catch (IOException e) {
    throw new ServletException(e);
  }
}
 
Example 4
Source File: ArchaiusUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void setProperty(String key, Object value) {
  // ensure have instance
  DynamicPropertyFactory.getInstance();

  ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
      .getBackingConfigurationSource();
  if (value != null) {
    config.getConfiguration(0).setProperty(key, value);
    return;
  }

  config.getConfiguration(0).clearProperty(key);
}
 
Example 5
Source File: TestPriorityProperty.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void globalRefresh() {
  PriorityProperty<String> property = priorityPropertyManager.createPriorityProperty(String.class, null, null, keys);

  Assert.assertNull(property.getValue());

  ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
      .getBackingConfigurationSource();
  config.addConfiguration(new MapConfiguration(Collections.singletonMap(high, "high-value")));

  Assert.assertEquals("high-value", property.getValue());
}
 
Example 6
Source File: ConfigurePropertyUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
/**
 * 获取key包含prefix前缀的所有配置项
 */
public static Map<String, String> getPropertiesWithPrefix(String prefix) {
  Object config = DynamicPropertyFactory.getBackingConfigurationSource();
  if (!Configuration.class.isInstance(config)) {
    return new HashMap<>();
  }

  return getPropertiesWithPrefix((Configuration) config, prefix);
}
 
Example 7
Source File: URLMappedEdgeDispatcher.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void loadConfigurations() {
  ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
      .getBackingConfigurationSource();
  configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
  config.addConfigurationListener(event -> {
    if (event.getPropertyName().startsWith(KEY_MAPPING_PREFIX)) {
      LOG.info("Map rule have been changed. Reload configurations. Event=" + event.getType());
      configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
    }
  });
}
 
Example 8
Source File: CommonHttpEdgeDispatcher.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void loadConfigurations() {
  ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
      .getBackingConfigurationSource();
  configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
  config.addConfigurationListener(event -> {
    if (event.getPropertyName().startsWith(KEY_MAPPING_PREFIX)) {
      LOG.info("Map rule have been changed. Reload configurations. Event=" + event.getType());
      configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
    }
  });
}
 
Example 9
Source File: AccessController.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void loadConfigurations(String prefix) {
  ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
      .getBackingConfigurationSource();
  loadConfigurations(config, prefix);
  config.addConfigurationListener(event -> {
    if (event.getPropertyName().startsWith(prefix)) {
      LOG.info("Access rule have been changed. Reload configurations. Event=" + event.getType());
      loadConfigurations(config, prefix);
    }
  });
}
 
Example 10
Source File: TestServletConfig.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetServletUrlPattern() {
  DynamicPropertyFactory.getInstance();
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, "/*");
  Assert.assertEquals("/*", ServletConfig.getServletUrlPattern());
}
 
Example 11
Source File: FilterChainsConfig.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public FilterChainsConfig(TransportFiltersConfig transportFiltersConfig, InvocationType type) {
  this.transportFiltersConfig = transportFiltersConfig;

  Configuration config = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  String root = FILTER_CHAINS_PREFIX + type.name().toLowerCase(Locale.US);
  defaultChain = resolve(ConfigUtil.getStringList(config, root + ".default"));
  loadMicroserviceChains(config, root + ".policies");
}
 
Example 12
Source File: ConfigUtil.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static Object getProperty(String key) {
  Object config = DynamicPropertyFactory.getBackingConfigurationSource();
  return getProperty(config, key);
}