Example usage for org.apache.commons.configuration Configuration addProperty

List of usage examples for org.apache.commons.configuration Configuration addProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration addProperty.

Prototype

void addProperty(String key, Object value);

Source Link

Document

Add a property to the configuration.

Usage

From source file:com.yahoo.pulsar.zookeeper.ZkBookieRackAffinityMapping.java

private ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> getAndSetZkCache(
        Configuration conf) {
    ZooKeeperCache zkCache = null;//from   w  w  w  . j  a  v  a 2  s  .c o m
    if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
        zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
    } else {
        int zkTimeout;
        String zkServers;
        if (conf instanceof ClientConfiguration) {
            zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
            zkServers = ((ClientConfiguration) conf).getZkServers();
            ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(zkTimeout) {
            };
            try {
                ZooKeeper zkClient = ZkUtils.createConnectedZookeeperClient(zkServers, w);
                zkCache = new ZooKeeperCache(zkClient) {
                };
                conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
            } catch (Exception e) {
                LOG.error("Error creating zookeeper client", e);
            }
        } else {
            LOG.error("No zk configurations available");
        }
    }
    ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> zkDataCache = getZkBookieRackMappingCache(
            zkCache);
    if (zkDataCache != null) {
        zkDataCache.registerListener(this);
    }
    return zkDataCache;
}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testCuncurrent() throws IOException {
    Configuration con1 = new ZookeeperConfiguration(zkConnection, 5000, "/concurrent/");
    Configuration con2 = new ZookeeperConfiguration(zkConnection, 5000, "/concurrent/");

    final String key = UUID.randomUUID().toString();
    final String v1 = UUID.randomUUID().toString(), v2 = UUID.randomUUID().toString(),
            v3 = UUID.randomUUID().toString(), v4 = UUID.randomUUID().toString(),
            v5 = UUID.randomUUID().toString();

    assertNull(con1.getString(key));//  w w  w.j a v a  2  s  . c o m
    assertNull(con2.getString(key));
    assertEquals(v5, con1.getString(key, v5));
    assertEquals(v5, con2.getString(key, v5));

    con1.setProperty(key, v1);
    assertEquals(v1, con2.getString(key, v5));
    assertEquals(v1, con1.getString(key, v5));

    con2.addProperty(key, v2);
    assertEquals(v1, con1.getString(key, v5));
    assertEquals(v1, con2.getString(key, v5));
    assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v1, v2));
    assertThat(con1.getList(key), CoreMatchers.<Object>hasItems(v1, v2));

    con2.addProperty(key, v3);
    con1.addProperty(key, v4);
    assertEquals(v1, con2.getString(key, v5));
    assertEquals(v1, con1.getString(key, v5));
    assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4));
    assertThat(con1.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4));

    con2.clearProperty(key);
    assertNull(con2.getString(key));
    assertNull(con1.getString(key));
    assertEquals(v5, con1.getString(key, v5));
    assertEquals(v5, con2.getString(key, v5));

    con1.addProperty(key, v5);
    assertEquals(v5, con2.getString(key));

    con1.clearProperty(key);
    con2.setProperty(key, Arrays.asList(v3, v2, v4, v1, v5));
    assertEquals(v3, con1.getString(key));
    assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v3, v2, v4, v1, v5));

}

From source file:com.kixeye.chassis.bootstrap.configuration.ConfigurationBuilder.java

private void addServerInstanceProperties(Configuration configuration) {
    String instanceId = LOCAL_INSTANCE_ID;
    String region = UNKNOWN;
    String availabilityZone = UNKNOWN;
    String privateIp = "127.0.0.1";
    String publicIp = null;/*from   w ww .j  a v  a2s  .co  m*/
    String instanceName = Joiner.on("-").join(appEnvironment, appName, appVersion);

    if (serverInstanceContext != null) {
        instanceId = serverInstanceContext.getInstanceId();
        region = serverInstanceContext.getRegion();
        availabilityZone = serverInstanceContext.getAvailabilityZone();
        privateIp = serverInstanceContext.getPrivateIp();
        publicIp = serverInstanceContext.getPublicIp();
    }

    configuration.addProperty(BootstrapConfigKeys.AWS_INSTANCE_ID.getPropertyName(), instanceId);
    configuration.addProperty(BootstrapConfigKeys.AWS_INSTANCE_REGION.getPropertyName(), region);
    configuration.addProperty(BootstrapConfigKeys.AWS_INSTANCE_AVAILABILITY_ZONE.getPropertyName(),
            availabilityZone);
    configuration.addProperty(BootstrapConfigKeys.AWS_INSTANCE_PRIVATE_IP.getPropertyName(), privateIp);
    if (publicIp != null) {
        configuration.addProperty(BootstrapConfigKeys.AWS_INSTANCE_PUBLIC_IP.getPropertyName(), publicIp);
    }
    configuration.addProperty(BootstrapConfigKeys.AWS_INSTANCE_NAME.getPropertyName(), instanceName);
}

From source file:edu.kit.dama.rest.client.DataManagerPropertiesHelper.java

/**
 * Test access to webDAV server./* www . j  av  a2s .com*/
 * <b>Attention:<b><br/>
 * This method should only chosen if the credentials are not fixed. The chosen
 * authentication is slow but allows you to test several credentials.
 *
 * @param pAuthenticationClass Class used for authentication.
 * @return success
 */
private boolean genericWebDavAccess(String pAuthenticationClass) {
    boolean returnValue = false;
    StagingServiceRESTClient ssrc = new StagingServiceRESTClient(restServerUrl + REST_STAGING_PATH, context);
    try {
        StagingAccessPointConfigurationWrapper allAccessPoints = ssrc
                .getAllAccessPoints(properties.getAccessPoint(), properties.getUserGroup(), context);
        String webDavUrl = ssrc.getAccessPointById(allAccessPoints.getEntities().get(0).getId(), context)
                .getEntities().get(0).getRemoteBaseUrl();
        // Method to overwrite the Webdav configuration class with a custom configuration class
        for (String protocol : new String[] { "http", "https" }) {
            Configuration configuration = ProtocolSettings.getSingleton().getConfiguration(protocol);
            configuration.setProperty("authClass", pAuthenticationClass);
            Iterator iter = configuration.getKeys();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                String value = configuration.getString(key);
                configuration.clearProperty(key);
                configuration.addProperty(protocol + "." + key, value);
            }
            ProtocolSettings.getSingleton().overwriteConfiguration(configuration);
        }
        LOGGER.debug(
                "Overwriting the default configuration with the specific configuration of generic ingest client.");
        AbstractFile af = new AbstractFile(new URL(webDavUrl + "/USERS"));
        af.list();
        AbstractFile createDirectory = af.createDirectory(UUID.randomUUID().toString());
        if (createDirectory.exists()) {
            createDirectory.delete();
            returnValue = true;
        }
    } catch (MalformedURLException | AdalapiException e) {
        LOGGER.error(invalidWebDavSettings, e);
    }
    return returnValue;

}

From source file:co.turnus.analysis.buffers.MpcBoundedSchedulingCliLauncher.java

private static Configuration parseCommandLine(CommandLine cmd) throws ParseException {
    Configuration config = new BaseConfiguration();

    StringBuffer s = new StringBuffer();

    config.setProperty(VERBOSE, cmd.hasOption("v"));

    if (!cmd.hasOption("t")) {
        s.append("Trace project directory not specified. ");
    } else {//from  ww w.  j a  va  2  s.c o  m
        String fileName = cmd.getOptionValue("t", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Trace project does not exists. ");
        } else {
            config.setProperty(TRACE_PROJECT, fileName);
        }
    }

    if (!cmd.hasOption("o")) {
        s.append("Output directory not specified. ");
    } else {
        String fileName = cmd.getOptionValue("o", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Output directory does not exists. ");
        } else {
            config.setProperty(OUTPUT_PATH, fileName);
        }
    }

    if (cmd.hasOption("xls")) {
        String fileName = cmd.getOptionValue("xls", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("XLS file name is not correct. ");
        } else {
            config.setProperty(XLS, fileName);
        }
    }

    if (cmd.hasOption("bxdf")) {
        String fileName = cmd.getOptionValue("bxdf", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("BXDF file name is not correct. ");
        } else {
            config.setProperty(BXDF, fileName);
        }
    }

    if (!cmd.hasOption("s") && !cmd.hasOption("d")) {
        s.append("please choose at least one option for the trace cut (max steps or max degree) ");
    }

    if (cmd.hasOption("s")) {
        String[] sArray = cmd.getOptionValues("s");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(TRACE_CUT_STEPS_MIN, value);
            config.addProperty(TRACE_CUT_STEPS_MAX, value);
            config.addProperty(TRACE_CUT_STEPS_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
            config.addProperty(TRACE_CUT_STEPS_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_NUM, points);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
        }
    }

    if (cmd.hasOption("d")) {
        String[] sArray = cmd.getOptionValues("d");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(TRACE_CUT_DEGREE_MIN, value);
            config.addProperty(TRACE_CUT_DEGREE_MAX, value);
            config.addProperty(TRACE_CUT_DEGREE_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(TRACE_CUT_DEGREE_MIN, min);
            config.addProperty(TRACE_CUT_DEGREE_MAX, max);
            config.addProperty(TRACE_CUT_DEGREE_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(TRACE_CUT_DEGREE_MIN, min);
            config.addProperty(TRACE_CUT_DEGREE_NUM, points);
            config.addProperty(TRACE_CUT_DEGREE_MAX, max);
        }
    }

    if (cmd.hasOption("c")) {
        String[] sArray = cmd.getOptionValues("c");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(HC_MIN, value);
            config.addProperty(HC_MAX, value);
            config.addProperty(HC_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(HC_MIN, min);
            config.addProperty(HC_MAX, max);
            config.addProperty(HC_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(HC_MIN, min);
            config.addProperty(HC_NUM, points);
            config.addProperty(HC_MAX, max);
        }
    } else {
        s.append("the control horizon has not been choosed");
    }

    boolean recovery = cmd.hasOption("r");
    config.setProperty(RECOVERY, recovery);

    boolean bitAccurate = cmd.hasOption("b");
    config.setProperty(BIT_ACCURATE, bitAccurate);

    boolean zeroStartingPoint = cmd.hasOption("z");
    config.setProperty(ZERO_STARTING_POINT, zeroStartingPoint);

    boolean quickCut = cmd.hasOption("q");
    config.setProperty(QUICK_CUT, quickCut);

    String error = s.toString();
    if (!error.isEmpty()) {
        throw new ParseException(error);
    }

    return config;
}

From source file:co.turnus.analysis.buffers.BoundedBufferSchedulingCliLauncher.java

private static Configuration parseCommandLine(CommandLine cmd) throws ParseException {
    Configuration config = new BaseConfiguration();

    StringBuffer s = new StringBuffer();

    config.setProperty(VERBOSE, cmd.hasOption("v"));

    if (!cmd.hasOption("t")) {
        s.append("Trace project directory not specified. ");
    } else {//from  w  ww  .  j av a 2s .c  om
        String fileName = cmd.getOptionValue("t", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Trace project does not exists. ");
        } else {
            config.setProperty(TRACE_PROJECT, fileName);
        }
    }

    if (!cmd.hasOption("o")) {
        s.append("Output directory not specified. ");
    } else {
        String fileName = cmd.getOptionValue("o", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Output directory does not exists. ");
        } else {
            config.setProperty(OUTPUT_PATH, fileName);
        }
    }

    if (cmd.hasOption("xls")) {
        String fileName = cmd.getOptionValue("xls", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("XLS file name is not correct. ");
        } else {
            config.setProperty(XLS, fileName);
        }
    }

    if (cmd.hasOption("bxdf")) {
        String fileName = cmd.getOptionValue("bxdf", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("BXDF file name is not correct. ");
        } else {
            config.setProperty(BXDF, fileName);
        }
    }

    boolean bitAccurate = cmd.hasOption("b");
    config.setProperty(BIT_ACCURATE, bitAccurate);

    boolean zeroStartingPoint = cmd.hasOption("z");
    config.setProperty(ZERO_STARTING_POINT, zeroStartingPoint);

    boolean quickCut = cmd.hasOption("q");
    config.setProperty(QUICK_CUT, quickCut);

    if (cmd.hasOption("s")) {
        String[] sArray = cmd.getOptionValues("s");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(TRACE_CUT_STEPS_MIN, value);
            config.addProperty(TRACE_CUT_STEPS_MAX, value);
            config.addProperty(TRACE_CUT_STEPS_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
            config.addProperty(TRACE_CUT_STEPS_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_NUM, points);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
        }
    }

    String error = s.toString();
    if (!error.isEmpty()) {
        throw new ParseException(error);
    }

    return config;
}

From source file:nl.salp.warcraft4j.config.Warcraft4jConfigBuilder.java

/**
 * Build a PropertyWarcraft4jConfig instance from the builder values.
 *
 * @return The PropertyWarcraft4jConfig instance.
 *
 * @throws Warcraft4jConfigException When the configuration values were invalid.
 *///from ww w .  j a  v  a 2 s .  c om
public PropertyWarcraft4jConfig build() throws Warcraft4jConfigException {
    Configuration config = new BaseConfiguration();
    config.addProperty(PropertyWarcraft4jConfig.ONLINE_KEY, online);
    config.addProperty(PropertyWarcraft4jConfig.WOW_DIR_KEY, wowDir);
    config.addProperty(PropertyWarcraft4jConfig.CACHE_KEY, caching);
    config.addProperty(PropertyWarcraft4jConfig.CACHE_DIR_KEY, cacheDir);
    config.addProperty(PropertyWarcraft4jConfig.LOCALE_KEY, locale);
    config.addProperty(PropertyWarcraft4jConfig.REGION_KEY, region);
    config.addProperty(PropertyWarcraft4jConfig.BRANCH_KEY, branch);
    return new PropertyWarcraft4jConfig(config);
}

From source file:org.apache.accumulo.core.client.ClientConfigurationTest.java

private ClientConfiguration createConfig() {
    Configuration first = new PropertiesConfiguration();
    first.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "firstZkHosts");
    Configuration second = new PropertiesConfiguration();
    second.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "secondZkHosts");
    second.addProperty(ClientProperty.INSTANCE_NAME.getKey(), "secondInstanceName");
    Configuration third = new PropertiesConfiguration();
    third.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "thirdZkHosts");
    third.addProperty(ClientProperty.INSTANCE_NAME.getKey(), "thirdInstanceName");
    third.addProperty(ClientProperty.INSTANCE_ZK_TIMEOUT.getKey(), "123s");
    return new ClientConfiguration(Arrays.asList(first, second, third));
}

From source file:org.apache.atlas.repository.graphdb.titan1.Titan1Database.java

public static Configuration getConfiguration() throws AtlasException {
    Configuration configProperties = ApplicationProperties.get();

    Configuration titanConfig = ApplicationProperties.getSubsetConfiguration(configProperties, GRAPH_PREFIX);

    //add serializers for non-standard property value types that Atlas uses

    titanConfig.addProperty("attributes.custom.attribute1.attribute-class", TypeCategory.class.getName());
    titanConfig.addProperty("attributes.custom.attribute1.serializer-class",
            TypeCategorySerializer.class.getName());

    //not ideal, but avoids making large changes to Atlas
    titanConfig.addProperty("attributes.custom.attribute2.attribute-class", ArrayList.class.getName());
    titanConfig.addProperty("attributes.custom.attribute2.serializer-class",
            StringListSerializer.class.getName());

    titanConfig.addProperty("attributes.custom.attribute3.attribute-class", BigInteger.class.getName());
    titanConfig.addProperty("attributes.custom.attribute3.serializer-class",
            BigIntegerSerializer.class.getName());

    titanConfig.addProperty("attributes.custom.attribute4.attribute-class", BigDecimal.class.getName());
    titanConfig.addProperty("attributes.custom.attribute4.serializer-class",
            BigDecimalSerializer.class.getName());

    return titanConfig;
}

From source file:org.apache.juddi.auth.AuthenticatorTest.java

@Test
public void testDecryptFromConfigXML_InMemory() {
    System.out.println("testDecryptFromConfigXML_InMemory");
    try {/*from  w  ww.  j a  va  2  s.  c o m*/
        Configuration config = AppConfig.getConfiguration();

        Cryptor auth = new AES128Cryptor();
        String encrypt = auth.encrypt("test");
        Assert.assertNotNull(encrypt);
        Assert.assertNotSame(encrypt, "test");

        //add to the config
        config.addProperty("testDecryptFromConfigXML", encrypt);
        config.addProperty("testDecryptFromConfigXML" + Property.ENCRYPTED_ATTRIBUTE, "true");

        //retrieve it
        String pwd = config.getString("testDecryptFromConfigXML");
        Assert.assertNotNull(pwd);
        //test for encryption
        if (config.getBoolean("testDecryptFromConfigXML" + Property.ENCRYPTED_ATTRIBUTE, false)) {
            String test = auth.decrypt(pwd);
            Assert.assertEquals(test, "test");
        } else {
            Assert.fail("config reports that the setting is not encrypted");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("unexpected");
    }
}