List of usage examples for org.apache.commons.configuration AbstractConfiguration getString
public String getString(String key, String defaultValue)
From source file:com.netflix.paas.config.base.ConfigurationProxyUtils.java
static Supplier<?> getStaticSupplier(Class<?> type, String key, String defaultValue, AbstractConfiguration configuration) { if (type.isAssignableFrom(String.class)) { return Suppliers.ofInstance(configuration.getString(key, defaultValue)); } else if (type.isAssignableFrom(Integer.class)) { return Suppliers.ofInstance( configuration.getInteger(key, defaultValue == null ? 0 : Integer.parseInt(defaultValue))); } else if (type.isAssignableFrom(Double.class)) { return Suppliers.ofInstance( configuration.getDouble(key, defaultValue == null ? 0.0 : Double.parseDouble(defaultValue))); } else if (type.isAssignableFrom(Long.class)) { return Suppliers.ofInstance( configuration.getLong(key, defaultValue == null ? 0L : Long.parseLong(defaultValue))); } else if (type.isAssignableFrom(Boolean.class)) { return Suppliers.ofInstance(configuration.getBoolean(key, defaultValue == null ? false : Boolean.parseBoolean(defaultValue))); }// w w w . j av a 2 s . c o m throw new RuntimeException("Unsupported value type " + type.getCanonicalName()); }
From source file:com.netflix.iep.dynprop.RemoteConfigurationSource.java
private Properties getProperties() throws IOException { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); String vip = config.getString(VIP, "atlas_archaius-main:7001"); List<String> hosts = getHostsForVip(vip, config.getBoolean(USE_IP, false)); int numAttempts = config.getInt(NUM_RETRIES, 2) + 1; for (int i = 1; i <= numAttempts; ++i) { String host = hosts.get(i % hosts.size()); String url = "http://" + host + "/api/v1/property" + "?asg=" + getAsgName() + "&instanceId=" + getInstanceId() + "&zone=" + getZone(); logger.debug("attempt {} of {}, requesting properties from: {}", i, numAttempts, url); try {// ww w . ja v a 2 s . c o m URLConnection con = new URL(url).openConnection(); con.setConnectTimeout(config.getInt(CONNECT_TIMEOUT, 1000)); con.setReadTimeout(config.getInt(READ_TIMEOUT, 5000)); Properties props = new Properties(); try (InputStream in = con.getInputStream()) { props.load(in); } logger.debug("fetched {} properties from: {}", props.size(), url); return props; } catch (IOException e) { String msg = String.format("attempt %d of %d failed, url: %s", i, numAttempts, url); if (i == numAttempts) { logger.error(msg, e); throw e; } else { logger.warn(msg, e); } } } // Shouldn't get here throw new IllegalStateException("failed to get properties"); }
From source file:com.netflix.iep.gov.Governator.java
private void initJmxPort() { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); if (config.getBoolean(RESTRICT_PORT, false)) { String host = config.getString(JMX_HOST, null); int port = config.getInt(JMX_PORT, 7500); JmxPort.configure(host, port);// ww w . j av a 2 s . co m } else { LOGGER.debug("skipping configuration of jmx port"); } }