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


Java ConfigurationManager.loadProperties方法代碼示例

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


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

示例1: testReadAll

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Test
public void testReadAll() {
    Properties properties = new Properties();
    properties.put("id1.sometype.a", "_a1");
    properties.put("id2.sometype", "{\"type\":\"_type\",\"a\":\"_a2\"}");
    properties.put("id3.sometype", "{\"type\":\"_type\",\"a\":\"_a3\"}");
    
    System.out.println(properties);
    properties.put("id1.someothertype.a", "_a");
    
    ConfigurationManager.loadProperties(properties);
    
    ArchaiusTypeConfigurationResolver resolver = new ArchaiusTypeConfigurationResolver(null);
    Map<String, ConfigurationNode> someTypeConfigs = resolver.getConfigurationFactory("sometype").getAllConfigurations();
    Assert.assertEquals(3, someTypeConfigs.keySet().size());
    Assert.assertEquals("_a1", someTypeConfigs.get("id1").getChild("a").getValue(String.class));
    Assert.assertEquals("_a2", someTypeConfigs.get("id2").getChild("a").getValue(String.class));
    Assert.assertEquals("_a3", someTypeConfigs.get("id3").getChild("a").getValue(String.class));
    
    Map<String, ConfigurationNode> someOtherTypeConfigs = resolver.getConfigurationFactory("someothertype").getAllConfigurations();
    Assert.assertEquals(1, someOtherTypeConfigs.keySet().size());
    Assert.assertEquals("_a", someOtherTypeConfigs.get("id1").getChild("a").getValue(String.class));
}
 
開發者ID:Netflix,項目名稱:fabricator,代碼行數:24,代碼來源:ArchaiusTypeConfigurationResolverTest.java

示例2: testresolveDeploymentContextbasedVipAddresses

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Test
public void testresolveDeploymentContextbasedVipAddresses() throws Exception {
	DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
	clientConfig.loadDefaultValues();
    Properties props = new Properties();
    
    final String restClientName = "testRestClient2";
    
    clientConfig.setProperty(props, restClientName,CommonClientConfigKey.AppName.key(), "movieservice");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.DeploymentContextBasedVipAddresses.key(),
            "${<appname>}-${netflix.appinfo.stack}-${netflix.environment}:${<port>},${<appname>}--${netflix.environment}:${<port>}");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.Port.key(), "7001");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.EnableZoneAffinity.key(), "true");        
    ConfigurationManager.loadProperties(props);
    
    clientConfig.loadProperties(restClientName);
    
    Assert.assertEquals("movieservice", clientConfig.getProperty(CommonClientConfigKey.AppName));
    Assert.assertEquals("true", clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
    
    ConfigurationManager.getConfigInstance().setProperty("testRestClient2.ribbon.DeploymentContextBasedVipAddresses", "movieservice-xbox-test:7001");
    assertEquals("movieservice-xbox-test:7001", clientConfig.getProperty(CommonClientConfigKey.DeploymentContextBasedVipAddresses));
    
    ConfigurationManager.getConfigInstance().clearProperty("testRestClient2.ribbon.EnableZoneAffinity");
    assertNull(clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:27,代碼來源:ClientConfigTest.java

示例3: initializeArchiaus

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
/**
 * Hystrix expects configuration via Archaius so we initialize it here
 */
public static void initializeArchiaus(Config appConfig) {
    // Initialize Archaius
    DynamicPropertyFactory.getInstance();
    // Load properties from Typesafe config for Hystrix, etc.
    ConfigurationManager.loadProperties(toProperties(appConfig));
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:10,代碼來源:ArchaiusUtils.java

示例4: createClient

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@VisibleForTesting
void createClient() {
    if (ribbonEtc.containsKey("eureka")) {
        ribbonEtc.setProperty(
            clientName + ".ribbon.AppName", clientName);
        ribbonEtc.setProperty(
            clientName + ".ribbon.NIWSServerListClassName",
            "com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList");
        String[] host_port = addressList.get(0).split(":");
        ribbonEtc.setProperty(
            clientName + ".ribbon.DeploymentContextBasedVipAddresses",
            host_port[0]);
        ribbonEtc.setProperty(
            clientName + ".ribbon.Port",
            host_port[1]);
    } else {
        ribbonEtc.setProperty(clientName + ".ribbon.listOfServers", Joiner.on(",").join(addressList));
    }
    ribbonEtc.setProperty(
        clientName + ".ribbon.EnablePrimeConnections",
        "true");
    String retryPropertyName = clientName + ".ribbon." + CommonClientConfigKey.OkToRetryOnAllOperations;
    if (ribbonEtc.getProperty(retryPropertyName) == null) {
        // default set this to enable retry on POST operation upon read timeout
        ribbonEtc.setProperty(retryPropertyName, "true");
    }
    String maxRetryProperty = clientName + ".ribbon." + CommonClientConfigKey.MaxAutoRetriesNextServer;
    if (ribbonEtc.getProperty(maxRetryProperty) == null) {
        // by default retry two different servers upon exception
        ribbonEtc.setProperty(maxRetryProperty, "2");
    }
    ConfigurationManager.loadProperties(ribbonEtc);
    client = (RestClient) ClientFactory.getNamedClient(clientName);

}
 
開發者ID:Netflix,項目名稱:suro,代碼行數:36,代碼來源:ElasticSearchSink.java

示例5: setupEnv

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@BeforeSuite
public void setupEnv() {
    Properties props = getProps();

    try {
        ConfigurationManager.loadProperties(props);

        LifecycleInjectorBuilder builder = LifecycleInjector.builder();
        builder.withModules(
                new EurekaModule(),
                new EVCacheModule(), 
                new ConnectionModule(),
                new SpectatorModule()
                );

        injector = builder.build().createInjector();
        lifecycleManager = injector.getInstance(LifecycleManager.class);

        lifecycleManager.start();
        injector.getInstance(ApplicationInfoManager.class);
        final EVCacheModule lib = injector.getInstance(EVCacheModule.class);
        manager = injector.getInstance(EVCacheClientPoolManager.class);
    } catch (Throwable e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
    }

}
 
開發者ID:Netflix,項目名稱:EVCache,代碼行數:29,代碼來源:Base.java

示例6: loadProperties

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
public static void loadProperties(Properties properties) {
    ConfigurationManager.loadProperties(properties);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:4,代碼來源:ArchaiusUtils.java

示例7: EurekaModule

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
public EurekaModule(Properties properties) {
    ConfigurationManager.loadProperties(properties);
}
 
開發者ID:schibsted,項目名稱:ratpack-eureka,代碼行數:4,代碼來源:EurekaModule.java

示例8: testProperies

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Test
    public void testProperies() throws Exception {
        // 1.  Bootstrap on startup
        // 2.  Load by 'id'
        // 3.  Map with prefix
        final Properties props = new Properties();
        
        // Properties is NOT a map
        props.put("id1.some.type",          "d");
        props.put("id1.some.properties",    "simplevalue");
        
        // Properties not provided
        props.put("id2.some.type",          "d");
        
        // Properties is a map
        props.put("id3.some.type",          "d");
        props.put("id3.some.properties.a",  "a");
        props.put("id3.some.properties.b.c","bc");
        props.put("id3.some.properties.d",  "true");
        props.put("id3.some.properties.e",  "123");
        
        ConfigurationManager.loadProperties(props);
        Injector injector = Guice.createInjector(
            new ArchaiusConfigurationModule(),
            new SomeInterfaceModule(),
            new AbstractModule() {
                @Override
                protected void configure() {
                    install(new ComponentModuleBuilder<SomeInterface>()
                            .implementation(BaseD.class)
                            .build(SomeInterface.class)
                            );
                }
            }
        );

        ComponentManager<SomeInterface> ifmanager = injector.getInstance(Key.get(new TypeLiteral<ComponentManager<SomeInterface>>() {}));
        
        BaseD iface2 = (BaseD)ifmanager.get("id2");
        BaseD iface3 = (BaseD)ifmanager.get("id3");
        
        LOG.info(iface2.toString());
        LOG.info(iface3.toString());
        
        try {
            // TODO: Need to fix this unit test
            BaseD iface1 = (BaseD)ifmanager.get("id1");
            LOG.info(iface1.toString());
//            Assert.fail();
        }
        catch (Exception e) {
            
        }
    }
 
開發者ID:Netflix,項目名稱:fabricator,代碼行數:55,代碼來源:ComponentFactoryModuleBuilderTest.java

示例9: testNiwsConfigViaProperties

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Test
public void testNiwsConfigViaProperties() throws Exception {
	DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
	DefaultClientConfigImpl override = new DefaultClientConfigImpl();
	clientConfig.loadDefaultValues();
    Properties props = new Properties();
    
    final String restClientName = "testRestClient";
    
    props.setProperty("netflix.appinfo.stack","xbox");
    props.setProperty("netflix.environment","test");
    
    props.setProperty("appname", "movieservice");
    
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.AppName.key(), "movieservice");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.DeploymentContextBasedVipAddresses.key(),
            "${appname}-${netflix.appinfo.stack}-${netflix.environment},movieservice--${netflix.environment}");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.EnableZoneAffinity.key(), "false");
    
    ConfigurationManager.loadProperties(props);
    ConfigurationManager.getConfigInstance().setProperty("testRestClient.ribbon.customProperty", "abc");
    
    clientConfig.loadProperties(restClientName);
    clientConfig.setProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    override.setProperty(CommonClientConfigKey.Port, "8000");
    override.setProperty(CommonClientConfigKey.ConnectTimeout, "5000");
    clientConfig.applyOverride(override);
    
    Assert.assertEquals("movieservice", clientConfig.getProperty(CommonClientConfigKey.AppName));
    Assert.assertEquals("false", clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));        
    Assert.assertEquals("movieservice-xbox-test,movieservice--test", clientConfig.resolveDeploymentContextbasedVipAddresses());
    Assert.assertEquals("5000", clientConfig.getProperty(CommonClientConfigKey.ConnectTimeout));

    Assert.assertEquals("8000", clientConfig.getProperty(CommonClientConfigKey.Port));
    assertEquals("abc", clientConfig.getProperties().get("customProperty"));
    System.out.println("AutoVipAddress:" + clientConfig.resolveDeploymentContextbasedVipAddresses());
    
    ConfigurationManager.getConfigInstance().setProperty("testRestClient.ribbon.EnableZoneAffinity", "true");
    ConfigurationManager.getConfigInstance().setProperty("testRestClient.ribbon.customProperty", "xyz");
    assertEquals("true", clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
    assertEquals("xyz", clientConfig.getProperties().get("customProperty"));        
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:43,代碼來源:ClientConfigTest.java

示例10: getObject

import com.netflix.config.ConfigurationManager; //導入方法依賴的package包/類
@Override
public Injector getObject() throws Exception {

    if ( this.injector != null ) {
        return injector;
    }

    try {

        logger.info( "Loading Core Persistence properties" );

        String hostsString = "";

        CassandraHost[] hosts = chc.buildCassandraHosts();
        if ( hosts.length == 0 ) {
            throw new RuntimeException( "Fatal error: no Cassandra hosts configured" );
        }

        for ( CassandraHost host : hosts ) {
            if ( StringUtils.isEmpty( host.getHost() ) ) {
                throw new RuntimeException( "Fatal error: Cassandra hostname cannot be empty" );
            }
            hostsString += host.getHost() + ",";
        }

        hostsString = hostsString.substring( 0, hostsString.length() - 1 );

        logger.info( "hostsString: {}", hostsString );

        Properties cpProps = new Properties();

        // Some Usergrid properties must be mapped to Core Persistence properties
        cpProps.put( "cassandra.hosts", hostsString );
        cpProps.put( "cassandra.port", hosts[0].getPort() );

        cpProps.put( "cassandra.cluster_name", getAndValidateProperty( "cassandra.cluster" ) );

        cpProps
            .put( "cassandra.strategy", getAndValidateProperty( "cassandra.keyspace.strategy" ) );

        cpProps
            .put( "cassandra.strategy.local", getAndValidateProperty( "cassandra.keyspace.strategy.local" ) );

        cpProps.put( "cassandra.strategy.options",
            getAndValidateProperty( "cassandra.keyspace.replication" ) );

        cpProps.put( "cassandra.strategy.options.local",
            getAndValidateProperty( "cassandra.keyspace.replication.local" ) );



        if (logger.isDebugEnabled()) {
            logger.debug("Set Cassandra properties for Core Persistence: {}", cpProps.toString());
        }

        // Load the properties into the new CP Props Map by calling getProperty as the methods may be overridden
        for( Object propKey : systemProperties.keySet()){

            cpProps.setProperty((String)propKey, systemProperties.getProperty((String)propKey));

        }
        //logger.debug("All properties fed to Core Persistence: " + cpProps.toString() );
        ConfigurationManager.loadProperties( cpProps );
    }
    catch ( Exception e ) {
        throw new RuntimeException( "Fatal error loading configuration.", e );
    }

    List<Module> moduleList = new ArrayList<>();
    if(applicationContext.containsBean("serviceModule")){
        Module serviceModule =(Module)applicationContext.getBean("serviceModule");
        moduleList.add( serviceModule);
    }
    moduleList.add(new CoreModule( systemProperties ));
    moduleList.add(new PersistenceModule(applicationContext));
    //we have to inject a couple of spring beans into our Guice.  Wire it with PersistenceModule
    injector = Guice.createInjector( moduleList );

    return injector;
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:81,代碼來源:GuiceFactory.java


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