List of usage examples for org.apache.commons.configuration AbstractConfiguration getBoolean
public Boolean getBoolean(String key, Boolean defaultValue)
Boolean
object. 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))); }//from ww w . j a v a 2s. c o m throw new RuntimeException("Unsupported value type " + type.getCanonicalName()); }
From source file:com.netflix.spectator.nflx.Plugin.java
@PostConstruct private void init() throws IOException { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); final boolean enabled = config.getBoolean(ENABLED_PROP, true); if (enabled) { ConfigurationManager.loadPropertiesFromResources(CONFIG_FILE); if (config.getBoolean("spectator.gc.loggingEnabled")) { GC_LOGGER.start(new ChronosGcEventListener(rxHttp)); LOGGER.info("gc logging started"); } else {//w w w.j av a 2 s . co m LOGGER.info("gc logging is not enabled"); } Jmx.registerStandardMXBeans(Spectator.registry()); } else { LOGGER.debug("plugin not enabled, set " + ENABLED_PROP + "=true to enable"); } }
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);/*www . j a v a 2s. c om*/ } else { LOGGER.debug("skipping configuration of jmx port"); } }
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 {// w w w . j a v a2s .co 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.explorers.AppConfigGlobalModelContext.java
@Inject public AppConfigGlobalModelContext(@Named("explorerAppName") String appName) { final String propertiesFileName = appName + "-explorers-app.properties"; try {//from w w w .j a v a 2 s . c o m ConfigurationManager.loadPropertiesFromResources(propertiesFileName); } catch (IOException e) { LOG.error(String.format( "Exception loading properties file - %s, Explorers application may not work correctly ", propertiesFileName)); } AbstractConfiguration configuration = ConfigurationManager.getConfigInstance(); environmentName = configuration.getString(PROPERTY_ENVIRONMENT_NAME); currentRegion = configuration.getString(PROPERTY_CURRENT_REGION); applicationVersion = (String) configuration.getProperty(PROPERTY_APPLICATION_VERSION); applicationName = (String) configuration.getProperty(PROPERTY_APPLICATION_NAME); isLocal = configuration.getBoolean(PROPERTY_IS_LOCAL, false); homePageUrl = configuration.getString(PROPERTY_HOME_PAGE); defaultPort = configuration.getShort(PROPERTY_DEFAULT_PORT, (short) 8080); dataCenter = configuration.getString(PROPERTY_DATA_CENTER); defaultExplorerName = configuration.getString(PROPERTY_DEFAULT_EXPLORER); try { Iterator<String> dcKeySet = configuration.getKeys(PROPERTIES_PREFIX + ".dc"); while (dcKeySet.hasNext()) { String dcKey = dcKeySet.next(); String key = StringUtils.substringBefore(dcKey, "."); String attr = StringUtils.substringAfter(dcKey, "."); CrossLink link = links.get(key); if (link == null) { link = new CrossLink(); links.put(key, link); } BeanUtils.setProperty(link, attr, configuration.getProperty(dcKey)); } } catch (Exception e) { LOG.error("Exception in constructing links map ", e); throw new RuntimeException(e); } }
From source file:org.skb.util.types.composite.util.TSPropertyMap.java
public String loadFromFile(String fn) { try {//from w ww . jav a2s . c om AbstractConfiguration cfg; String prefix = ""; if (fn.endsWith(".ini")) { cfg = new INIConfiguration(fn); prefix = "tribe."; } else if (fn.endsWith(".xml")) cfg = new XMLConfiguration(fn); else if (fn.endsWith(".properties")) cfg = new PropertiesConfiguration(fn); else return "unknown configuration file format, use '.ini' or '.xml' or '.properties'"; File file = new File(fn); if (!file.canRead()) return "can't read configuration file <" + fn + ">"; Iterator<?> it; if (prefix != "") it = cfg.getKeys(prefix); else it = cfg.getKeys(); while (it.hasNext()) { String p = it.next().toString(); if (this.containsKey(p)) { String type = this.get(p, TSPropertyMap.pmValType).toString(); if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_STRING)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getString(p)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_BOOLEAN)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getBoolean(p, false)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_INTEGER)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getInteger(p, 0)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_DOUBLE)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getDouble(p)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_LONG)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getLong(p, 0)); // else // System.err.println("TSPropMap, loadfromfile, unknown type <"+type+"> for <"+p+">"); } } } catch (Exception e) { // ReportManager repMgr=ReportManager.getInstance(); // repMgr.reportErrorNoFile(e.toString()); } return null; }