Example usage for org.apache.commons.configuration AbstractConfiguration getInt

List of usage examples for org.apache.commons.configuration AbstractConfiguration getInt

Introduction

In this page you can find the example usage for org.apache.commons.configuration AbstractConfiguration getInt.

Prototype

public int getInt(String key, int defaultValue) 

Source Link

Usage

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 . jav a2s  . c  o  m
    } 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 . ja v  a 2 s. 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");
}