List of usage examples for org.apache.commons.configuration Configuration getKeys
Iterator getKeys();
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.gryo.kryoshim.unshaded.UnshadedKryoShimService.java
private LinkedBlockingQueue<Kryo> initialize(final Configuration configuration) { // DCL is safe in this case due to volatility if (!INITIALIZED) { synchronized (UnshadedKryoShimService.class) { if (!INITIALIZED) { // so we don't get a WARN that a new configuration is being created within an active context final SparkConf sparkConf = null == Spark.getContext() ? new SparkConf() : Spark.getContext().getConf().clone(); configuration.getKeys() .forEachRemaining(key -> sparkConf.set(key, configuration.getProperty(key).toString())); final KryoSerializer serializer = new KryoSerializer(sparkConf); // Setup a pool backed by our spark.serializer instance // Reuse Gryo poolsize for Kryo poolsize (no need to copy this to SparkConf) KRYOS.clear();//from ww w . ja va2 s. c o m final int poolSize = configuration.getInt(GryoPool.CONFIG_IO_GRYO_POOL_SIZE, GryoPool.CONFIG_IO_GRYO_POOL_SIZE_DEFAULT); for (int i = 0; i < poolSize; i++) { KRYOS.add(serializer.newKryo()); } INITIALIZED = true; } } } return KRYOS; }
From source file:org.apache.tinkerpop.gremlin.spark.structure.Spark.java
public static void create(final Configuration configuration) { final SparkConf sparkConf = new SparkConf(); configuration.getKeys() .forEachRemaining(key -> sparkConf.set(key, configuration.getProperty(key).toString())); sparkConf.setAppName("Apache TinkerPop's Spark-Gremlin"); CONTEXT = SparkContext.getOrCreate(sparkConf); }
From source file:org.apache.tinkerpop.gremlin.structure.GraphConstructionTest.java
/** * A {@link Graph} should maintain the original {@code Configuration} object passed to it via {@link GraphFactory}. *///from w ww .ja v a2 s . co m @Test public void shouldMaintainOriginalConfigurationObjectGivenToFactory() throws Exception { final Configuration originalConfig = graphProvider.newGraphConfiguration("temp2", this.getClass(), name.getMethodName(), null); final Graph createdGraph = GraphFactory.open(originalConfig); final Configuration configInGraph = createdGraph.configuration(); final AtomicInteger keyCount = new AtomicInteger(0); originalConfig.getKeys().forEachRemaining(k -> { assertTrue(configInGraph.containsKey(k)); keyCount.incrementAndGet(); }); // need some keys in the originalConfig for this test to be meaningful assertTrue(keyCount.get() > 0); assertEquals(keyCount.get(), IteratorUtils.count(configInGraph.getKeys())); graphProvider.clear(createdGraph, originalConfig); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldLoadSystemProperties() { System.setProperty("blah.aa", "1"); System.setProperty("blah.b", "true"); System.setProperty("blah.c", "three"); System.setProperty("bleep.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", false); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("blah.aa")); assertTrue(configuration.getBoolean("blah.b")); assertEquals("three", configuration.getProperty("blah.c")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); System.clearProperty("blah.aa"); System.clearProperty("blah.b"); System.clearProperty("blah.c"); System.clearProperty("bleep.d"); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldTrimSystemPropertyPrefixes() { System.setProperty("blah.a", "1"); System.setProperty("blah.bbb", "true"); System.setProperty("blah.c", "three"); System.setProperty("bleep.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", true); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("a")); assertTrue(configuration.getBoolean("bbb")); assertEquals("three", configuration.getProperty("c")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); System.clearProperty("blah.a"); System.clearProperty("blah.bbb"); System.clearProperty("blah.c"); System.clearProperty("bleep.d"); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldTrimSystemPropertyPrefixesAndNoMore() { System.setProperty("blah.a.x", "1"); System.setProperty("blah.b.y", "true"); System.setProperty("blah.cc.zzz", "three"); System.setProperty("bleep.d.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", true); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("a.x")); assertTrue(configuration.getBoolean("b.y")); assertEquals("three", configuration.getProperty("cc.zzz")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); assertFalse(configuration.containsKey("d.d") || configuration.containsKey("bleep.d.d")); System.clearProperty("blah.a.x"); System.clearProperty("blah.b.y"); System.clearProperty("blah.cc.zzz"); System.clearProperty("bleep.d.d"); }
From source file:org.apache.torque.dsfactory.AbstractDataSourceFactory.java
/** * Encapsulates setting configuration properties on * <code>DataSource</code> objects. * * @param property the property to read from the configuration * @param c the configuration to read the property from * @param ds the <code>DataSource</code> instance to write the property to * @throws Exception if anything goes wrong *//*from ww w .j a va 2s . co m*/ protected void setProperty(String property, Configuration c, Object ds) throws Exception { if (c == null || c.isEmpty()) { return; } String key = property; Class<?> dsClass = ds.getClass(); int dot = property.indexOf('.'); try { if (dot > 0) { property = property.substring(0, dot); MappedPropertyDescriptor mappedPD = new MappedPropertyDescriptor(property, dsClass); Class<?> propertyType = mappedPD.getMappedPropertyType(); Configuration subProps = c.subset(property); // use reflection to set properties Iterator<?> j = subProps.getKeys(); while (j.hasNext()) { String subProp = (String) j.next(); String propVal = subProps.getString(subProp); Object value = ConvertUtils.convert(propVal, propertyType); PropertyUtils.setMappedProperty(ds, property, subProp, value); if (log.isDebugEnabled()) { log.debug( "setMappedProperty(" + ds + ", " + property + ", " + subProp + ", " + value + ")"); } } } else { if ("password".equals(key)) { // do not log value of password // for this, ConvertUtils.convert cannot be used // as it also logs the value of the converted property // so it is assumed here that the password is a String String value = c.getString(property); PropertyUtils.setSimpleProperty(ds, property, value); if (log.isDebugEnabled()) { log.debug("setSimpleProperty(" + ds + ", " + property + ", " + " (value not logged)" + ")"); } } else { Class<?> propertyType = PropertyUtils.getPropertyType(ds, property); Object value = ConvertUtils.convert(c.getString(property), propertyType); PropertyUtils.setSimpleProperty(ds, property, value); if (log.isDebugEnabled()) { log.debug("setSimpleProperty(" + ds + ", " + property + ", " + value + ")"); } } } } catch (RuntimeException e) { throw new TorqueRuntimeException("Runtime error setting property " + property, e); } catch (Exception e) { log.error("Property: " + property + " value: " + c.getString(key) + " is not supported by DataSource: " + ds.getClass().getName()); } }
From source file:org.apache.torque.dsfactory.AbstractDataSourceFactory.java
/** * Iterate over a Configuration subset and apply all * properties to a passed object which must contain Bean * setter and getter/*from www .j a va 2 s . c om*/ * * @param c The configuration subset * @param o The object to apply the properties to * @throws TorqueException if a property set fails */ protected void applyConfiguration(Configuration c, Object o) throws TorqueException { log.debug("applyConfiguration(" + c + ", " + o + ")"); if (c != null) { try { for (Iterator<?> i = c.getKeys(); i.hasNext();) { String key = (String) i.next(); setProperty(key, c, o); } } catch (Exception e) { log.error(e); throw new TorqueException(e); } } }
From source file:org.apache.torque.dsfactory.JndiDataSourceFactory.java
/** * Initializes JNDI./*from ww w. j a v a2s . c o m*/ * * @param configuration where to read the settings from * @throws TorqueException if a property set fails */ private void initJNDI(Configuration configuration) throws TorqueException { log.debug("Starting initJNDI"); Configuration c = configuration.subset(JNDI_KEY); if (c == null || c.isEmpty()) { throw new TorqueException( "JndiDataSourceFactory requires a jndi " + "path property to lookup the DataSource in JNDI."); } try { Hashtable<String, Object> env = new Hashtable<String, Object>(); for (Iterator<?> i = c.getKeys(); i.hasNext();) { String key = (String) i.next(); if (key.equals(PATH_KEY)) { path = c.getString(key); if (log.isDebugEnabled()) { log.debug("JNDI path: " + path); } } else if (key.equals(TIME_BETWEEN_LOOKUPS_KEY)) { ttl = c.getLong(key, ttl); if (log.isDebugEnabled()) { log.debug("Time between context lookups: " + ttl); } } else { String value = c.getString(key); env.put(key, value); if (log.isDebugEnabled()) { log.debug("Set jndi property: " + key + "=" + value); } } } ctx = new InitialContext(env); log.debug("Created new InitialContext"); debugCtx(ctx); } catch (Exception e) { log.error("", e); throw new TorqueException(e); } }
From source file:org.apache.torque.dsfactory.JndiDataSourceFactory.java
/** * Initializes the DataSource.//from www. java 2 s . com * * @param configuration where to read the settings from * @throws TorqueException if a property set fails */ private void initDataSource(Configuration configuration) throws TorqueException { log.debug("Starting initDataSource"); try { Object dataSource = null; Configuration c = configuration.subset(DATASOURCE_KEY); if (c != null) { for (Iterator<?> i = c.getKeys(); i.hasNext();) { String key = (String) i.next(); if (key.equals(CLASSNAME_KEY)) { String classname = c.getString(key); if (log.isDebugEnabled()) { log.debug("Datasource class: " + classname); } Class<?> dsClass = Class.forName(classname); dataSource = dsClass.newInstance(); } else { if (dataSource != null) { if (log.isDebugEnabled()) { log.debug("Setting datasource property: " + key); } setProperty(key, c, dataSource); } else { log.error("Tried to set property " + key + " without Datasource definition!"); } } } } if (dataSource != null) { synchronized (ctx) { bindDStoJndi(ctx, path, dataSource); } } } catch (Exception e) { log.error("", e); throw new TorqueException(e); } }