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

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

Introduction

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

Prototype

long getLong(String key);

Source Link

Document

Get a long associated with the given configuration key.

Usage

From source file:nl.tudelft.graphalytics.configuration.ConfigurationUtil.java

public static long getLong(Configuration config, String property) throws InvalidConfigurationException {
    ensureConfigurationKeyExists(config, property);
    try {/*  ww  w. j a  va  2  s  .co m*/
        return config.getLong(property);
    } catch (ConversionException ignore) {
        throw new InvalidConfigurationException("Invalid value for property \"" + resolve(config, property)
                + "\": \"" + config.getString(property) + "\", expected a long value.");
    }
}

From source file:org.apache.qpid.server.store.SlowMessageStore.java

public void configureConfigStore(String name, ConfigurationRecoveryHandler recoveryHandler,
        Configuration config) throws Exception {
    _logger.info("Starting SlowMessageStore on Virtualhost:" + name);
    Configuration delays = config.subset(DELAYS);

    configureDelays(delays);//from   ww w  .j ava2 s  .c om

    String messageStoreClass = config.getString("realStore");

    if (delays.containsKey(DEFAULT_DELAY)) {
        _defaultDelay = delays.getLong(DEFAULT_DELAY);
    }

    if (messageStoreClass != null) {
        Class<?> clazz = Class.forName(messageStoreClass);

        Object o = clazz.newInstance();

        if (!(o instanceof MessageStore)) {
            throw new ClassCastException("Message store class must implement " + MessageStore.class + ". Class "
                    + clazz + " does not.");
        }
        _realStore = (MessageStore) o;
        if (o instanceof DurableConfigurationStore) {
            _durableConfigurationStore = (DurableConfigurationStore) o;
        }
    }
    _durableConfigurationStore.configureConfigStore(name, recoveryHandler, config);

}

From source file:org.apache.qpid.server.store.SlowMessageStore.java

private void configureDelays(Configuration config) {
    @SuppressWarnings("unchecked")
    Iterator<String> delays = config.getKeys();

    while (delays.hasNext()) {
        String key = (String) delays.next();
        if (key.endsWith(PRE)) {
            _preDelays.put(key.substring(0, key.length() - PRE.length() - 1), config.getLong(key));
        } else if (key.endsWith(POST)) {
            _postDelays.put(key.substring(0, key.length() - POST.length() - 1), config.getLong(key));
        }/*  w w  w.j a va 2  s  .co m*/
    }
}

From source file:org.apache.samoa.LocalStormDoTask.java

/**
 * The main method./*from   w w  w .  j  av a2  s  . com*/
 * 
 * @param args
 *          the arguments
 */
public static void main(String[] args) {

    List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args));

    int numWorker = StormSamoaUtils.numWorkers(tmpArgs);

    args = tmpArgs.toArray(new String[0]);

    // convert the arguments into Storm topology
    StormTopology stormTopo = StormSamoaUtils.argsToTopology(args);
    String topologyName = stormTopo.getTopologyName();

    Config conf = new Config();
    // conf.putAll(Utils.readStormConfig());
    conf.setDebug(false);

    // local mode
    conf.setMaxTaskParallelism(numWorker);

    backtype.storm.LocalCluster cluster = new backtype.storm.LocalCluster();
    cluster.submitTopology(topologyName, conf, stormTopo.getStormBuilder().createTopology());

    // Read local mode execution duration from property file
    Configuration stormConfig = StormSamoaUtils
            .getPropertyConfig(LocalStormDoTask.SAMOA_STORM_PROPERTY_FILE_LOC);
    long executionDuration = stormConfig.getLong(LocalStormDoTask.EXECUTION_DURATION_KEY);
    backtype.storm.utils.Utils.sleep(executionDuration * 1000);

    cluster.killTopology(topologyName);
    cluster.shutdown();

}

From source file:org.apache.tinkerpop.gremlin.driver.Settings.java

/**
 * Read configuration from a file into a new {@link Settings} object.
 *///from  w  w  w. ja v a2 s .c  o m
public static Settings from(final Configuration conf) {
    final Settings settings = new Settings();

    if (conf.containsKey("port"))
        settings.port = conf.getInt("port");

    if (conf.containsKey("nioPoolSize"))
        settings.nioPoolSize = conf.getInt("nioPoolSize");

    if (conf.containsKey("workerPoolSize"))
        settings.workerPoolSize = conf.getInt("workerPoolSize");

    if (conf.containsKey("username"))
        settings.username = conf.getString("username");

    if (conf.containsKey("password"))
        settings.password = conf.getString("password");

    if (conf.containsKey("jaasEntry"))
        settings.jaasEntry = conf.getString("jaasEntry");

    if (conf.containsKey("protocol"))
        settings.protocol = conf.getString("protocol");

    if (conf.containsKey("hosts"))
        settings.hosts = conf.getList("hosts").stream().map(Object::toString).collect(Collectors.toList());

    if (conf.containsKey("serializer.className")) {
        final SerializerSettings serializerSettings = new SerializerSettings();
        final Configuration serializerConf = conf.subset("serializer");

        if (serializerConf.containsKey("className"))
            serializerSettings.className = serializerConf.getString("className");

        final Configuration serializerConfigConf = conf.subset("serializer.config");
        if (IteratorUtils.count(serializerConfigConf.getKeys()) > 0) {
            final Map<String, Object> m = new HashMap<>();
            serializerConfigConf.getKeys().forEachRemaining(name -> {
                m.put(name, serializerConfigConf.getProperty(name));
            });
            serializerSettings.config = m;
        }
        settings.serializer = serializerSettings;
    }

    final Configuration connectionPoolConf = conf.subset("connectionPool");
    if (IteratorUtils.count(connectionPoolConf.getKeys()) > 0) {
        final ConnectionPoolSettings cpSettings = new ConnectionPoolSettings();

        if (connectionPoolConf.containsKey("channelizer"))
            cpSettings.channelizer = connectionPoolConf.getString("channelizer");

        if (connectionPoolConf.containsKey("enableSsl"))
            cpSettings.enableSsl = connectionPoolConf.getBoolean("enableSsl");

        if (connectionPoolConf.containsKey("trustCertChainFile"))
            cpSettings.trustCertChainFile = connectionPoolConf.getString("trustCertChainFile");

        if (connectionPoolConf.containsKey("minSize"))
            cpSettings.minSize = connectionPoolConf.getInt("minSize");

        if (connectionPoolConf.containsKey("maxSize"))
            cpSettings.maxSize = connectionPoolConf.getInt("maxSize");

        if (connectionPoolConf.containsKey("minSimultaneousUsagePerConnection"))
            cpSettings.minSimultaneousUsagePerConnection = connectionPoolConf
                    .getInt("minSimultaneousUsagePerConnection");

        if (connectionPoolConf.containsKey("maxSimultaneousUsagePerConnection"))
            cpSettings.maxSimultaneousUsagePerConnection = connectionPoolConf
                    .getInt("maxSimultaneousUsagePerConnection");

        if (connectionPoolConf.containsKey("maxInProcessPerConnection"))
            cpSettings.maxInProcessPerConnection = connectionPoolConf.getInt("maxInProcessPerConnection");

        if (connectionPoolConf.containsKey("minInProcessPerConnection"))
            cpSettings.minInProcessPerConnection = connectionPoolConf.getInt("minInProcessPerConnection");

        if (connectionPoolConf.containsKey("maxWaitForConnection"))
            cpSettings.maxWaitForConnection = connectionPoolConf.getInt("maxWaitForConnection");

        if (connectionPoolConf.containsKey("maxContentLength"))
            cpSettings.maxContentLength = connectionPoolConf.getInt("maxContentLength");

        if (connectionPoolConf.containsKey("reconnectInterval"))
            cpSettings.reconnectInterval = connectionPoolConf.getInt("reconnectInterval");

        if (connectionPoolConf.containsKey("reconnectInitialDelay"))
            cpSettings.reconnectInitialDelay = connectionPoolConf.getInt("reconnectInitialDelay");

        if (connectionPoolConf.containsKey("resultIterationBatchSize"))
            cpSettings.resultIterationBatchSize = connectionPoolConf.getInt("resultIterationBatchSize");

        if (connectionPoolConf.containsKey("keepAliveInterval"))
            cpSettings.keepAliveInterval = connectionPoolConf.getLong("keepAliveInterval");

        settings.connectionPool = cpSettings;
    }

    return settings;
}

From source file:org.janusgraph.olap.ShortestDistanceVertexProgram.java

@Override
public void loadState(final Graph graph, final Configuration configuration) {
    maxDepth = configuration.getInt(MAX_DEPTH);
    seed = configuration.getLong(SEED);
    weightProperty = configuration.getString(WEIGHT_PROPERTY, "distance");
    incidentMessageScope = MessageScope.Local.of(__::inE,
            (msg, edge) -> msg + edge.<Integer>value(weightProperty));
    log.debug("Loaded maxDepth={}", maxDepth);
}

From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.ConcurrentConfigurationTest.java

@Test
public void testMethodWrappers() {
    CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class);
    Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null);

    concurrentConfiguration.subset("subset");
    concurrentConfiguration.isEmpty();//from   ww w .j av a  2 s  . co m
    concurrentConfiguration.containsKey("key");
    concurrentConfiguration.getProperty("getprop");
    concurrentConfiguration.getKeys("getkeys");
    concurrentConfiguration.getKeys();
    concurrentConfiguration.getProperties("getprops");
    concurrentConfiguration.getBoolean("getboolean1");
    concurrentConfiguration.getBoolean("getboolean2", true);
    concurrentConfiguration.getBoolean("getboolean3", Boolean.FALSE);
    concurrentConfiguration.getByte("getbyte1");
    concurrentConfiguration.getByte("getbyte2", (byte) 0);
    concurrentConfiguration.getByte("getbyte3", Byte.valueOf((byte) 0));
    concurrentConfiguration.getDouble("getdouble1");
    concurrentConfiguration.getDouble("getdouble2", 0.2);
    concurrentConfiguration.getDouble("getdouble3", Double.valueOf(0.2));
    concurrentConfiguration.getFloat("getfloat1");
    concurrentConfiguration.getFloat("getfloat2", 0f);
    concurrentConfiguration.getFloat("getfloat3", Float.valueOf(0f));
    concurrentConfiguration.getInt("getint1");
    concurrentConfiguration.getInt("getint2", 0);
    concurrentConfiguration.getInteger("getint3", 0);
    concurrentConfiguration.getLong("getlong1");
    concurrentConfiguration.getLong("getlong2", 0L);
    concurrentConfiguration.getLong("getlong3", Long.valueOf(0L));
    concurrentConfiguration.getShort("getshort1");
    concurrentConfiguration.getShort("getshort2", (short) 0);
    concurrentConfiguration.getShort("getshort3", Short.valueOf((short) 0));
    concurrentConfiguration.getBigDecimal("getbigd1");
    concurrentConfiguration.getBigDecimal("getbigd2", BigDecimal.valueOf(0.4));
    concurrentConfiguration.getBigInteger("getbigi1");
    concurrentConfiguration.getBigInteger("getbigi2", BigInteger.valueOf(2L));
    concurrentConfiguration.getString("getstring1");
    concurrentConfiguration.getString("getstring2", "def");
    concurrentConfiguration.getStringArray("stringarray");
    concurrentConfiguration.getList("getlist1");
    concurrentConfiguration.getList("getlist2", Arrays.asList("a", "b"));

    verify(mockConfiguration, times(1)).subset("subset");
    verify(mockConfiguration, times(1)).isEmpty();
    verify(mockConfiguration, times(1)).containsKey("key");
    verify(mockConfiguration, times(1)).getProperty("getprop");
    verify(mockConfiguration, times(1)).getKeys("getkeys");
    verify(mockConfiguration, times(1)).getKeys();
    verify(mockConfiguration, times(1)).getProperties("getprops");
    verify(mockConfiguration, times(1)).getBoolean("getboolean1");
    verify(mockConfiguration, times(1)).getBoolean("getboolean2", true);
    verify(mockConfiguration, times(1)).getBoolean("getboolean3", Boolean.FALSE);
    verify(mockConfiguration, times(1)).getByte("getbyte1");
    verify(mockConfiguration, times(1)).getByte("getbyte2", (byte) 0);
    verify(mockConfiguration, times(1)).getByte("getbyte3", Byte.valueOf((byte) 0));
    verify(mockConfiguration, times(1)).getDouble("getdouble1");
    verify(mockConfiguration, times(1)).getDouble("getdouble2", 0.2);
    verify(mockConfiguration, times(1)).getDouble("getdouble3", Double.valueOf(0.2));
    verify(mockConfiguration, times(1)).getFloat("getfloat1");
    verify(mockConfiguration, times(1)).getFloat("getfloat2", 0f);
    verify(mockConfiguration, times(1)).getFloat("getfloat3", Float.valueOf(0f));
    verify(mockConfiguration, times(1)).getInt("getint1");
    verify(mockConfiguration, times(1)).getInt("getint2", 0);
    verify(mockConfiguration, times(1)).getInteger("getint3", Integer.valueOf(0));
    verify(mockConfiguration, times(1)).getLong("getlong1");
    verify(mockConfiguration, times(1)).getLong("getlong2", 0L);
    verify(mockConfiguration, times(1)).getLong("getlong3", Long.valueOf(0L));
    verify(mockConfiguration, times(1)).getShort("getshort1");
    verify(mockConfiguration, times(1)).getShort("getshort2", (short) 0);
    verify(mockConfiguration, times(1)).getShort("getshort3", Short.valueOf((short) 0));
    verify(mockConfiguration, times(1)).getBigDecimal("getbigd1");
    verify(mockConfiguration, times(1)).getBigDecimal("getbigd2", BigDecimal.valueOf(0.4));
    verify(mockConfiguration, times(1)).getBigInteger("getbigi1");
    verify(mockConfiguration, times(1)).getBigInteger("getbigi2", BigInteger.valueOf(2L));
    verify(mockConfiguration, times(1)).getString("getstring1");
    verify(mockConfiguration, times(1)).getString("getstring2", "def");
    verify(mockConfiguration, times(1)).getStringArray("stringarray");
    verify(mockConfiguration, times(1)).getList("getlist1");
    verify(mockConfiguration, times(1)).getList("getlist2", Arrays.asList("a", "b"));
}

From source file:org.lable.oss.dynamicconfig.core.ConcurrencyIT.java

@Test
public void concurrencyTest() throws IOException, InterruptedException, ConfigurationException {
    final int threadCount = 20;

    final Path configFile = Files.createTempFile("config", ".yaml");
    Files.write(configFile, "test: 0\n".getBytes());

    System.setProperty(ConfigurationInitializer.LIBRARY_PREFIX + ".type", "file");
    System.setProperty(ConfigurationInitializer.LIBRARY_PREFIX + ".file.path",
            configFile.toAbsolutePath().toString());
    HierarchicalConfiguration defaults = new HierarchicalConfiguration();
    defaults.setProperty("test", -1);
    final Configuration configuration = ConfigurationInitializer.configureFromProperties(defaults,
            new YamlDeserializer());

    final CountDownLatch ready = new CountDownLatch(threadCount + 1);
    final CountDownLatch start = new CountDownLatch(1);
    final CountDownLatch done = new CountDownLatch(threadCount + 1);
    final Map<Integer, Long> result = new ConcurrentHashMap<>(threadCount);
    final long stopTime = System.currentTimeMillis() + 1_000;

    for (int i = 0; i < threadCount; i++) {
        final Integer number = 10 + i;
        new Thread(() -> {
            ready.countDown();/*from  ww w . j  a  v  a  2 s.c om*/
            try {
                result.put(number, 0L);
                start.await();
                while (System.currentTimeMillis() < stopTime) {
                    System.out.println(configuration.getLong("test"));
                    result.put(number, result.get(number) + 1);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.getMessage());
            }
            done.countDown();
        }, String.valueOf(number)).start();
    }

    new Thread(() -> {
        long count = 1;
        ready.countDown();
        try {
            start.await();
            while (System.currentTimeMillis() < stopTime) {
                String contents = "test: " + count + "\n";
                Files.write(configFile, contents.getBytes());
                count++;
                Thread.sleep(10);
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
        done.countDown();
    }, "setter").start();

    ready.await();
    start.countDown();
    done.await();

    for (Map.Entry<Integer, Long> entry : result.entrySet()) {
        System.out.println("Thread " + entry.getKey() + ": " + entry.getValue());
    }

}

From source file:org.mobicents.servlet.restcomm.sms.smpp.SmppService.java

private void initializeSmppConnections() {
    Configuration smppConfiguration = this.configuration.subset("smpp");

    List<Object> smppConnections = smppConfiguration.getList("connections.connection.name");

    int smppConnecsSize = smppConnections.size();
    if (smppConnecsSize == 0) {
        logger.warning("No SMPP Connections defined!");
        return;/*w  w w  .j ava  2s  .co m*/
    }

    for (int count = 0; count < smppConnecsSize; count++) {
        String name = smppConfiguration.getString("connections.connection(" + count + ").name");
        String systemId = smppConfiguration.getString("connections.connection(" + count + ").systemid");
        String peerIp = smppConfiguration.getString("connections.connection(" + count + ").peerip");
        int peerPort = smppConfiguration.getInt("connections.connection(" + count + ").peerport");
        SmppBindType bindtype = SmppBindType
                .valueOf(smppConfiguration.getString("connections.connection(" + count + ").bindtype"));

        if (bindtype == null) {
            logger.warning("Bindtype for SMPP name=" + name + " is not specified. Using default TRANSCEIVER");
        }

        String password = smppConfiguration.getString("connections.connection(" + count + ").password");
        String systemType = smppConfiguration.getString("connections.connection(" + count + ").systemtype");

        byte interfaceVersion = smppConfiguration
                .getByte("connections.connection(" + count + ").interfaceversion");

        byte ton = smppConfiguration.getByte("connections.connection(" + count + ").ton");
        byte npi = smppConfiguration.getByte("connections.connection(" + count + ").npi");
        String range = smppConfiguration.getString("connections.connection(" + count + ").range");

        Address address = null;
        if (ton != -1 && npi != -1 && range != null) {
            address = new Address(ton, npi, range);
        }

        int windowSize = smppConfiguration.getInt("connections.connection(" + count + ").windowsize");

        long windowWaitTimeout = smppConfiguration
                .getLong("connections.connection(" + count + ").windowwaittimeout");

        long connectTimeout = smppConfiguration.getLong("connections.connection(" + count + ").connecttimeout");
        long requestExpiryTimeout = smppConfiguration
                .getLong("connections.connection(" + count + ").requestexpirytimeout");
        long windowMonitorInterval = smppConfiguration
                .getLong("connections.connection(" + count + ").windowmonitorinterval");
        boolean logBytes = smppConfiguration.getBoolean("connections.connection(" + count + ").logbytes");
        boolean countersEnabled = smppConfiguration
                .getBoolean("connections.connection(" + count + ").countersenabled");

        long enquireLinkDelay = smppConfiguration
                .getLong("connections.connection(" + count + ").enquirelinkdelay");

        Smpp smpp = new Smpp(name, systemId, peerIp, peerPort, bindtype, password, systemType, interfaceVersion,
                address, connectTimeout, windowSize, windowWaitTimeout, requestExpiryTimeout,
                windowMonitorInterval, countersEnabled, logBytes, enquireLinkDelay);

        this.smppList.add(smpp);

        if (logger.isInfoEnabled()) {
            logger.info("creating new SMPP connection " + smpp);
        }

    }

    // for monitoring thread use, it's preferable to create your own
    // instance of an executor and cast it to a ThreadPoolExecutor from
    // Executors.newCachedThreadPool() this permits exposing thinks like
    // executor.getActiveCount() via JMX possible no point renaming the
    // threads in a factory since underlying Netty framework does not easily
    // allow you to customize your thread names
    this.executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();

    // to enable automatic expiration of requests, a second scheduled
    // executor is required which is what a monitor task will be executed
    // with - this is probably a thread pool that can be shared with between
    // all client bootstraps
    this.monitorExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1,
            new ThreadFactory() {
                private AtomicInteger sequence = new AtomicInteger(0);

                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName("SmppServer-SessionWindowMonitorPool-" + sequence.getAndIncrement());
                    return t;
                }
            });

    // a single instance of a client bootstrap can technically be shared
    // between any sessions that are created (a session can go to any
    // different number of SMSCs) - each session created under a client
    // bootstrap will use the executor and monitorExecutor set in its
    // constructor - just be *very* careful with the "expectedSessions"
    // value to make sure it matches the actual number of total concurrent
    // open sessions you plan on handling - the underlying netty library
    // used for NIO sockets essentially uses this value as the max number of
    // threads it will ever use, despite the "max pool size", etc. set on
    // the executor passed in here

    // Setting expected session to be 25. May be this should be
    // configurable?
    this.clientBootstrap = new DefaultSmppClient(this.executor, 25, monitorExecutor);

    this.smppClientOpsThread = new SmppClientOpsThread(this.clientBootstrap, outboundInterface("udp").getPort(),
            smppMessageHandler);

    (new Thread(this.smppClientOpsThread)).start();

    for (Smpp smpp : this.smppList) {
        this.smppClientOpsThread.scheduleConnect(smpp);
    }

    if (logger.isInfoEnabled()) {
        logger.info("SMPP Service started");
    }
}

From source file:org.restcomm.connect.commons.push.PushNotificationServerHelper.java

public PushNotificationServerHelper(final ActorSystem actorSystem, final Configuration configuration) {
    this.dispatcher = actorSystem.dispatchers().lookup("restcomm-blocking-dispatcher");

    final Configuration runtime = configuration.subset("runtime-settings");
    this.pushNotificationServerEnabled = runtime.getBoolean("push-notification-server-enabled", false);
    if (this.pushNotificationServerEnabled) {
        this.pushNotificationServerUrl = runtime.getString("push-notification-server-url");
        this.pushNotificationServerDelay = runtime.getLong("push-notification-server-delay");
    }//from w  w  w.  jav a2s.c o  m
}