List of usage examples for org.apache.commons.configuration Configuration getProperty
Object getProperty(String key);
From source file:com.yahoo.pulsar.zookeeper.ZkIsolatedBookieEnsemblePlacementPolicy.java
private ZooKeeperCache getAndSetZkCache(Configuration conf) { ZooKeeperCache zkCache = null;//from w ww . jav a 2s. com 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"); } } return zkCache; }
From source file:net.krotscheck.jersey2.configuration.Jersey2ToolkitConfigTest.java
/** * Assert that the default version configuration in a compile environment is * null, and that you cannot override it. This will be populated once the * package is actually packaged and has the metadata associated with it. *///from w w w. ja v a 2 s. c o m @Test public void testDebugVersionConfiguration() { Configuration config = new Jersey2ToolkitConfig(); Assert.assertEquals(null, config.getProperty("jersey2-toolkit.version")); // Override the version property. System.setProperty("jersey2-toolkit.version", "override1"); Assert.assertEquals(null, config.getProperty("jersey2-toolkit.version")); System.clearProperty("jersey2-toolkit.version"); }
From source file:net.krotscheck.jersey2.configuration.Jersey2ToolkitConfigTest.java
/** * Assert that the system properties override the text properties. *///from www . j av a2 s.co m @Test public void testSystemOverride() { // Override a property in jersey2-toolkit.properties System.setProperty("property1", "override1"); // Add a new system property. System.setProperty("property3", "override3"); Configuration config = new Jersey2ToolkitConfig(); Assert.assertEquals("override1", config.getProperty("property1")); Assert.assertEquals("value2", config.getProperty("property2")); Assert.assertEquals("override3", config.getProperty("property3")); System.clearProperty("property1"); System.clearProperty("property3"); }
From source file:com.yahoo.pulsar.zookeeper.ZkBookieRackAffinityMapping.java
private ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> getAndSetZkCache( Configuration conf) { ZooKeeperCache zkCache = null;/*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:grakn.core.graql.analytics.CommonOLAP.java
/** * Load <code>persistentProperties</code> and any hard coded fields from an apache config object for use by the * spark executor.//w w w . j av a 2 s . c o m * * @param graph the tinker graph * @param configuration the apache config object containing the values */ public void loadState(final Graph graph, final Configuration configuration) { // load selected types configuration.subset(PREFIX_SELECTED_TYPE_KEY).getKeys().forEachRemaining(key -> selectedTypes .add((LabelId) configuration.getProperty(PREFIX_SELECTED_TYPE_KEY + "." + key))); // load user specified properties configuration.subset(PREFIX_PERSISTENT_PROPERTIES).getKeys().forEachRemaining(key -> persistentProperties .put(key, configuration.getProperty(PREFIX_PERSISTENT_PROPERTIES + "." + key))); }
From source file:com.zyeeda.jofm.services.JofmService.java
@Override public void init(Configuration config) throws Exception { Object classes = config.getProperty(SCOPE_CLASSES); if (classes instanceof Collection<?>) { Collection<?> classNameList = (Collection<?>) classes; for (Object className : classNameList) { this.extractMappingAnnotations((String) className); }/*www. j a v a 2 s. c o m*/ } else if (classes instanceof String) { String className = (String) classes; this.extractMappingAnnotations(className); } else { throw new InvalidConfigurationException(" " + SCOPE_CLASSES + " "); } }
From source file:ai.grakn.graql.internal.analytics.DegreeAndPersistVertexProgram.java
@Override public void loadState(final Graph graph, final Configuration configuration) { super.loadState(graph, configuration); configuration.subset(OF_TYPE_NAMES).getKeys().forEachRemaining( key -> ofTypeNames.add((String) configuration.getProperty(OF_TYPE_NAMES + "." + key))); }
From source file:grakn.core.graql.analytics.DegreeVertexProgram.java
@Override public void loadState(final Graph graph, final Configuration configuration) { super.loadState(graph, configuration); configuration.subset(OF_LABELS).getKeys().forEachRemaining( key -> ofLabelIds.add((LabelId) configuration.getProperty(OF_LABELS + "." + key))); }
From source file:com.tribloom.reposize.GetRepoSize.java
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { if (logger.isDebugEnabled()) { logger.debug("Entering GetRepoSize.executeImpl()"); }/*from w ww. ja va 2 s. c o m*/ Map<String, Object> model = new HashMap<String, Object>(); // Use Apache Configuration library to perform variable interpolation if // necessary MapConfiguration config = (MapConfiguration) ConfigurationConverter.getConfiguration(globalProperties); Configuration intConfig = config.interpolatedConfiguration(); String contentStore = (String) intConfig.getProperty("dir.contentstore"); String indexes = (String) intConfig.getProperty("dir.indexes"); String indexesBackup = (String) intConfig.getProperty("dir.indexes.backup"); if (logger.isDebugEnabled()) { logger.debug(" contentStorePath = " + contentStore); logger.debug(" indexes = " + indexes); logger.debug(" indexesBackup = " + indexesBackup); } try { /** * TODO: Figure if there's a need and a way to perform this size request on multiple * stores, configured with the Content Selector Service * * Can do nodeService.getStores() to get the StoreRef's, but how * to retrieve contentService for these refs? Or does contentService * intelligently handle this? */ long storeFreeSpace = contentService.getStoreFreeSpace(); long storeTotalSpace = contentService.getStoreTotalSpace(); if (logger.isDebugEnabled()) { logger.debug(" storeFreeSpace = " + storeFreeSpace); logger.debug(" storeTotalSpace = " + storeTotalSpace); } long contentStoreSize = getFileSize(new File(contentStore)); if (logger.isDebugEnabled()) { logger.debug(" contentStoreSize = " + contentStoreSize); } long indexesSize = getFileSize(new File(indexes)); long indexesBackupSize = getFileSize(new File(indexesBackup)); if (logger.isDebugEnabled()) { logger.debug(" indexesSize = " + indexesSize); logger.debug(" indexesBackupSize = " + indexesBackupSize); } model.put("contentStorePath", contentStore); model.put("contentStoreSize", contentStoreSize); model.put("storeFreeSpace", storeFreeSpace); model.put("storeTotalSpace", storeTotalSpace); model.put("indexesPath", indexes); model.put("indexesSize", indexesSize); model.put("indexesBackupPath", indexesBackup); model.put("indexesBackupSize", indexesBackupSize); } catch (Exception e) { logger.error("Exception encountered during GetRepoSize webscript processing: ", e); status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR); status.setException(e); status.setMessage(e.getMessage()); status.setRedirect(false); } if (logger.isDebugEnabled()) { logger.debug("Exiting GetRepoSize.executeImpl()"); } return model; }
From source file:com.netflix.config.ConcurrentMapConfigurationTest.java
private void testConfigurationGet(Configuration conf) { long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { conf.getProperty("key" + (i % 100)); }/*from ww w .ja v a2 s . c om*/ long duration = System.currentTimeMillis() - start; System.out.println("get property for " + conf + " took " + duration + " ms"); }