Java源码示例:com.netflix.archaius.api.config.CompositeConfig

示例1
/**
 * Create a config to be used in the Netflix Cloud.
 */
public static Config createConfig(Config config) {
  try {
    // We cannot use the libraries layer as the nf-archaius2-platform-bridge
    // will delegate the Config binding to archaius1 and the libraries layer
    // then wraps that. So anything added to the libraries layer will not get
    // picked up by anything injecting Config.
    //
    // Instead we just create a composite where the injected config will override
    // the prop files. If no config binding is present use the environment and
    // system properties config.
    CompositeConfig cc = new DefaultCompositeConfig(true);
    cc.addConfig("ATLAS", loadPropFiles());
    cc.addConfig("ENVIRONMENT", EnvironmentConfig.INSTANCE);
    cc.addConfig("SYS", SystemConfig.INSTANCE);

    if (config != null) {
      LOGGER.debug("found injected config, adding as override layer");
      cc.addConfig("INJECTED", config);
    } else {
      LOGGER.debug("no injected config found");
    }

    return cc;
  } catch (ConfigException e) {
    throw new IllegalStateException("failed to load atlas config", e);
  }
}
 
示例2
@Inject
public EVCacheConfig(PropertyRepository repository) {
 PropertyRepository _propertyRepository = null;
 if(repository == null) {
     try {
	        final CompositeConfig applicationConfig = new DefaultCompositeConfig(true);
	        CompositeConfig remoteLayer = new DefaultCompositeConfig(true);
	        applicationConfig.addConfig("RUNTIME", new DefaultSettableConfig());
            applicationConfig.addConfig("REMOTE", remoteLayer);
	        applicationConfig.addConfig("SYSTEM", SystemConfig.INSTANCE);
	        applicationConfig.addConfig("ENVIRONMENT",  EnvironmentConfig.INSTANCE);
	        final EVCachePersistedProperties remote = new EVCachePersistedProperties();
            remoteLayer.addConfig("remote-1", remote.getPollingDynamicConfig());
	        _propertyRepository = new DefaultPropertyFactory(applicationConfig);
	        
     } catch (Exception e) {
         e.printStackTrace();
         _propertyRepository = new DefaultPropertyFactory(new DefaultCompositeConfig());
        }
 } else {
     _propertyRepository = repository;
 }
 propertyRepository =  new EVCachePropertyRepository(_propertyRepository);
 //propertyRepository = _propertyRepository;

    INSTANCE = this;
}