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

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

Introduction

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

Prototype

int getInt(String key, int defaultValue);

Source Link

Document

Get a int associated with the given configuration key.

Usage

From source file:edu.berkeley.sparrow.examples.ProtoFrontendAsync.java

public static void main(String[] args) {
    try {//from w  w  w.  j a  v a 2  s  .  com
        OptionParser parser = new OptionParser();
        parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
        parser.accepts("help", "print help statement");
        OptionSet options = parser.parse(args);

        if (options.has("help")) {
            parser.printHelpOn(System.out);
            System.exit(-1);
        }

        // Logger configuration: log to the console
        BasicConfigurator.configure();
        LOG.setLevel(Level.DEBUG);

        Configuration conf = new PropertiesConfiguration();

        if (options.has("c")) {
            String configFile = (String) options.valueOf("c");
            conf = new PropertiesConfiguration(configFile);
        }

        Random r = new Random();
        double lambda = conf.getDouble("job_arrival_rate_s", DEFAULT_JOB_ARRIVAL_RATE_S);
        int tasksPerJob = conf.getInt("tasks_per_job", DEFAULT_TASKS_PER_JOB);
        int benchmarkIterations = conf.getInt("benchmark.iterations", DEFAULT_BENCHMARK_ITERATIONS);
        int benchmarkId = conf.getInt("benchmark.id", DEFAULT_TASK_BENCHMARK);

        int schedulerPort = conf.getInt("scheduler_port", SchedulerThrift.DEFAULT_SCHEDULER_THRIFT_PORT);

        TProtocolFactory factory = new TBinaryProtocol.Factory();
        TAsyncClientManager manager = new TAsyncClientManager();

        long lastLaunch = System.currentTimeMillis();
        // Loop and generate tasks launches
        while (true) {
            // Lambda is the arrival rate in S, so we need to multiply the result here by
            // 1000 to convert to ms.
            long delay = (long) (generateInterarrivalDelay(r, lambda) * 1000);
            long curLaunch = lastLaunch + delay;
            long toWait = Math.max(0, curLaunch - System.currentTimeMillis());
            lastLaunch = curLaunch;
            if (toWait == 0) {
                LOG.warn("Generated workload not keeping up with real time.");
            }
            List<TTaskSpec> tasks = generateJob(tasksPerJob, benchmarkId, benchmarkIterations);
            TUserGroupInfo user = new TUserGroupInfo();
            user.setUser("*");
            user.setGroup("*");
            TSchedulingRequest req = new TSchedulingRequest();
            req.setApp("testApp");
            req.setTasks(tasks);
            req.setUser(user);

            TNonblockingTransport tr = new TNonblockingSocket("localhost", schedulerPort);
            SchedulerService.AsyncClient client = new SchedulerService.AsyncClient(factory, manager, tr);
            //client.registerFrontend("testApp", new RegisterCallback());
            client.submitJob(req, new SubmitCallback(req, tr));
        }
    } catch (Exception e) {
        LOG.error("Fatal exception", e);
    }
}

From source file:edu.berkeley.sparrow.examples.BBackend.java

public static void main(String[] args) throws IOException, TException {
    ipAddress = InetAddress.getLocalHost().toString();
    OptionParser parser = new OptionParser();
    parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
    parser.accepts("help", "print help statement");
    OptionSet options = parser.parse(args);

    if (options.has("help")) {
        parser.printHelpOn(System.out);
        System.exit(-1);/*from  w  ww. j  ava  2 s .c o  m*/
    }

    // Logger configuration: log to the console
    BasicConfigurator.configure();

    Configuration conf = new PropertiesConfiguration();

    if (options.has("c")) {
        String configFile = (String) options.valueOf("c");
        try {
            conf = new PropertiesConfiguration(configFile);
        } catch (ConfigurationException e) {
        }
    }
    // Start backend server
    LOG.setLevel(Level.toLevel(conf.getString(LOG_LEVEL, DEFAULT_LOG_LEVEL)));
    LOG.debug("debug logging on");
    int listenPort = conf.getInt(LISTEN_PORT, DEFAULT_LISTEN_PORT);
    int nodeMonitorPort = conf.getInt(NODE_MONITOR_PORT, NodeMonitorThrift.DEFAULT_NM_THRIFT_PORT);
    batchingDelay = conf.getLong(BATCHING_DELAY, DEFAULT_BATCHING_DELAY);
    String nodeMonitorHost = conf.getString(NODE_MONITOR_HOST, DEFAULT_NODE_MONITOR_HOST);
    int workerThread = conf.getInt(WORKER_THREADS, DEFAULT_WORKER_THREADS);
    appClientAdress = InetAddress.getByName(conf.getString(APP_CLIENT_IP));
    appClientPortNumber = conf.getInt(APP_CLIENT_PORT_NUMBER, DEFAULT_APP_CLIENT_PORT_NUMBER);
    executor = Executors.newFixedThreadPool(workerThread);
    // Starting logging of results
    resultLog = new SynchronizedWrite("ResultsBackend.txt");
    Thread resultLogTh = new Thread(resultLog);
    resultLogTh.start();

    BBackend protoBackend = new BBackend();
    BackendService.Processor<BackendService.Iface> processor = new BackendService.Processor<BackendService.Iface>(
            protoBackend);

    TServers.launchSingleThreadThriftServer(listenPort, processor);
    protoBackend.initialize(listenPort, nodeMonitorHost, nodeMonitorPort);

}

From source file:edu.berkeley.sparrow.examples.SimpleBackend.java

public static void main(String[] args) throws IOException, TException {
    OptionParser parser = new OptionParser();
    parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
    parser.accepts("help", "print help statement");
    OptionSet options = parser.parse(args);

    if (options.has("help")) {
        parser.printHelpOn(System.out);
        System.exit(-1);/*  w w  w .  j  a  v  a2s .com*/
    }

    // Logger configuration: log to the console
    BasicConfigurator.configure();
    LOG.setLevel(Level.DEBUG);
    LOG.debug("debug logging on");

    Configuration conf = new PropertiesConfiguration();

    if (options.has("c")) {
        String configFile = (String) options.valueOf("c");
        try {
            conf = new PropertiesConfiguration(configFile);
        } catch (ConfigurationException e) {
        }
    }
    // Start backend server
    SimpleBackend protoBackend = new SimpleBackend();
    BackendService.Processor<BackendService.Iface> processor = new BackendService.Processor<BackendService.Iface>(
            protoBackend);

    int listenPort = conf.getInt(LISTEN_PORT, DEFAULT_LISTEN_PORT);
    int nodeMonitorPort = conf.getInt(NODE_MONITOR_PORT, NodeMonitorThrift.DEFAULT_NM_THRIFT_PORT);
    String nodeMonitorHost = conf.getString(NODE_MONITOR_HOST, DEFAULT_NODE_MONITOR_HOST);
    TServers.launchSingleThreadThriftServer(listenPort, processor);
    protoBackend.initialize(listenPort, nodeMonitorHost, nodeMonitorPort);
}

From source file:edu.berkeley.sparrow.examples.ProtoBackend.java

public static void main(String[] args) throws IOException, TException {
    OptionParser parser = new OptionParser();
    parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
    parser.accepts("help", "print help statement");
    OptionSet options = parser.parse(args);

    if (options.has("help")) {
        parser.printHelpOn(System.out);
        System.exit(-1);//  www.  j  a  v a2 s  .c  o  m
    }

    // Logger configuration: log to the console
    BasicConfigurator.configure();
    LOG.setLevel(Level.DEBUG);
    LOG.debug("debug logging on");

    Configuration conf = new PropertiesConfiguration();

    if (options.has("c")) {
        String configFile = (String) options.valueOf("c");
        try {
            conf = new PropertiesConfiguration(configFile);
        } catch (ConfigurationException e) {
        }
    }
    // Start backend server
    ProtoBackend protoBackend = new ProtoBackend();
    BackendService.Processor<BackendService.Iface> processor = new BackendService.Processor<BackendService.Iface>(
            protoBackend);

    int listenPort = conf.getInt("listen_port", DEFAULT_LISTEN_PORT);
    NM_PORT = conf.getInt("node_monitor_port", NodeMonitorThrift.DEFAULT_NM_THRIFT_PORT);
    TServers.launchThreadedThriftServer(listenPort, THRIFT_WORKER_THREADS, processor);
    protoBackend.initialize(listenPort);
}

From source file:edu.berkeley.sparrow.daemon.util.Resources.java

public static int getSystemCPUCount(Configuration conf) {
    // No system interrogation yet
    return conf.getInt(SparrowConf.SYSTEM_CPUS, SparrowConf.DEFAULT_SYSTEM_CPUS);
}

From source file:ch.epfl.eagle.daemon.util.Resources.java

public static int getSystemCPUCount(Configuration conf) {
    // No system interrogation yet
    return conf.getInt(EagleConf.SYSTEM_CPUS, EagleConf.DEFAULT_SYSTEM_CPUS);
}

From source file:com.microrisc.simply.iqrf.dpa.v201.init.DPA_InitializerConfigurationFactory.java

private static EnumerationConfiguration createEnumerationConfiguration(Configuration configuration) {
    int getPerAttemptsNum = configuration.getInt(
            "initialization.type.dpa.enumeration.getPeripheral.num_attempts",
            EnumerationConfiguration.DEFAULT_GET_PER_ATTEMPTS_NUM);

    long getPerTimeout = configuration.getLong("initialization.type.dpa.enumeration.getPeripheral.timeout",
            EnumerationConfiguration.DEFAULT_GET_PER_TIMEOUT);

    return new EnumerationConfiguration(getPerAttemptsNum, getPerTimeout);
}

From source file:com.microrisc.simply.iqrf.dpa.v201.init.DPA_InitializerConfigurationFactory.java

private static DiscoveryConfiguration createDiscoveryConfiguration(Configuration configuration) {
    int doDiscovery = configuration.getInt("initialization.type.dpa.discovery", 0);
    if (doDiscovery == 0) {
        return null;
    }/* w  ww .ja  v a  2 s.com*/

    long discoveryTimeout = configuration.getLong("initialization.type.dpa.discovery.timeout", -1);

    int discoveryTxPower = configuration.getInt("initialization.type.dpa.discovery.txPower", -1);

    // if user explicitly sets to do discovery
    if (doDiscovery > 0) {
        if (discoveryTimeout == -1) {
            discoveryTimeout = DiscoveryConfiguration.DEFAULT_DISCOVERY_TIMEOUT;
        }

        if (discoveryTxPower == -1) {
            discoveryTxPower = DiscoveryConfiguration.DEFAULT_DISCOVERY_TX_POWER;
        }
    }

    return new DiscoveryConfiguration(discoveryTimeout, discoveryTxPower);
}

From source file:com.microrisc.simply.iqrf.dpa.v201.init.DPA_InitializerConfigurationFactory.java

private static BondedNodesConfiguration createBondedNodesConfiguration(Configuration configuration) {

    int processBondedNodes = configuration.getInt("initialization.type.dpa.getBondedNodes", 0);
    if (processBondedNodes == 0) {
        return null;
    }/*from   w w  w  .  java2 s . c  o m*/

    int getBondedNodesAttemptsNum = configuration.getInt("initialization.type.dpa.getBondedNodes.num_attempts",
            -1);

    long getBondeNodesTimeout = configuration.getLong("initialization.type.dpa.getBondedNodes.timeout", -1);

    // if user explicitly sets to process bonded nodes
    if (processBondedNodes > 0) {
        if (getBondedNodesAttemptsNum == -1) {
            getBondedNodesAttemptsNum = BondedNodesConfiguration.DEFAULT_GET_BONDED_NODES_ATTEMPTS_NUM;
        }

        if (getBondeNodesTimeout == -1) {
            getBondeNodesTimeout = BondedNodesConfiguration.DEFAULT_GET_BONDED_NODES_TIMEOUT;
        }
    }

    return new BondedNodesConfiguration(getBondedNodesAttemptsNum, getBondeNodesTimeout);
}

From source file:com.senseidb.indexing.activity.ActivityConfig.java

private static int getInt(Configuration configuration, String key, int defaultValue) {
    String compoundKey = "sensei.activity.config." + key;
    return configuration.getInt(compoundKey, defaultValue);
}