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);

Source Link

Document

Get a int associated with the given configuration key.

Usage

From source file:com.kixeye.chassis.bootstrap.configuration.zookeeper.CuratorFrameworkBuilder.java

private CuratorFramework buildCuratorWithExhibitor(Configuration configuration) {
    LOGGER.debug("configuring zookeeper connection through Exhibitor...");
    ExhibitorEnsembleProvider ensembleProvider = new KixeyeExhibitorEnsembleProvider(exhibitors,
            new KixeyeExhibitorRestClient(configuration.getBoolean(EXHIBITOR_USE_HTTPS.getPropertyName())),
            configuration.getString(EXHIBITOR_URI_PATH.getPropertyName()),
            configuration.getInt(EXHIBITOR_POLL_INTERVAL.getPropertyName()),
            new ExponentialBackoffRetry(configuration.getInt(EXHIBITOR_INITIAL_SLEEP_MILLIS.getPropertyName()),
                    configuration.getInt(EXHIBITOR_MAX_RETRIES.getPropertyName()),
                    configuration.getInt(EXHIBITOR_RETRIES_MAX_MILLIS.getPropertyName())));

    //without this (undocumented) step, curator will attempt (and fail) to connect to a local instance of zookeeper (default behavior if no zookeeper connection string is provided) for
    //several seconds until the EnsembleProvider polls to get the SERVER list from Exhibitor. Polling before staring curator
    //ensures that the SERVER list from Exhibitor is already downloaded before curator attempts to connect to zookeeper.
    try {//  w  w w .  j  a va 2 s. c om
        ensembleProvider.pollForInitialEnsemble();
    } catch (Exception e) {
        try {
            Closeables.close(ensembleProvider, true);
        } catch (IOException e1) {
        }
        throw new BootstrapException("Failed to initialize Exhibitor with host(s) " + exhibitors.getHostnames(),
                e);
    }

    CuratorFramework curator = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider)
            .retryPolicy(buildZookeeperRetryPolicy(configuration)).build();
    curator.getConnectionStateListenable().addListener(new ConnectionStateListener() {
        public void stateChanged(CuratorFramework client, ConnectionState newState) {
            LOGGER.debug("Connection state to ZooKeeper changed: " + newState);
        }
    });

    return curator;
}

From source file:com.springrts.springls.ServerThread.java

@Override
public void started() {

    // As DateFormats are generally not-thread save,
    // we always create a new one.
    DateFormat dateTimeFormat = new SimpleDateFormat("yyyy.MM.dd 'at' hh:mm:ss z");

    LOG.info("{} {} started on {}", new Object[] { Server.getApplicationName(), Misc.getAppVersionNonNull(),
            dateTimeFormat.format(new Date()) });

    // add server notification
    ServerNotification sn = new ServerNotification("Server started");
    Configuration conf = getContext().getService(Configuration.class);
    int port = conf.getInt(ServerConfiguration.PORT);
    sn.addLine(String.format("Server has been started on port %d." + " There are %d accounts. "
            + "See server log for more info.", port, context.getAccountsService().getAccountsSize()));
    context.getServerNotifications().addNotification(sn);

    createAdminIfNoUsers();/*ww w .  j  a v a 2s.  c o m*/
}

From source file:com.springrts.springls.ServerThread.java

public boolean startServer() {

    context.starting();/*from   w  w  w  .j av  a  2  s.co  m*/

    Configuration configuration = getContext().getService(Configuration.class);
    int port = configuration.getInt(ServerConfiguration.PORT);

    try {
        context.getServer().setCharset("ISO-8859-1");

        // open a non-blocking server socket channel
        sSockChan = ServerSocketChannel.open();
        sSockChan.configureBlocking(false);

        // bind to localhost on designated port
        //***InetAddress addr = InetAddress.getLocalHost();
        //***sSockChan.socket().bind(new InetSocketAddress(addr, port));
        sSockChan.socket().bind(new InetSocketAddress(port));

        // get a selector for multiplexing the client channels
        readSelector = Selector.open();

    } catch (IOException ex) {
        LOG.error("Could not listen on port: " + port, ex);
        return false;
    }

    LOG.info("Listening for connections on TCP port {} ...", port);

    context.started();

    return true;
}

From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.mutationStrategy.DEMutationStrategy.java

public void configure(Configuration conf) {

    try {//from w w  w  . j  a v  a2 s  .com
        if (conf.containsKey("F.Class")) {
            this.F_plugin = (Parameter) Class.forName(conf.getString("F.Class")).newInstance();
            this.F_plugin.configure(conf.subset("F"));
        } else {
            ConfWarning w = new ConfWarning(this.getClass().getSimpleName() + ".F",
                    this.F_plugin.getClass().getSimpleName());

            w.warn();
        }

        if (conf.containsKey("DiffVector")) {
            this.diffVector = conf.getInt("DiffVector");
        } else {
            ConfWarning w = new ConfWarning(this.getClass().getSimpleName() + ".DiffVector", this.diffVector);

            w.warn();
        }

    } catch (Exception ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }

}

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

@Test
public void testInt() throws Exception {
    Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test");

    final String key = UUID.randomUUID().toString();
    final Random random = new Random();
    final int val1 = random.nextInt();
    final Integer val2 = random.nextInt();

    assertThat(config.getProperty(key), nullValue());

    config.setProperty(key, val1);
    assertEquals(val1, config.getInt(key));
    assertEquals(new Integer(val1), config.getInteger(key, val2));

    config.setProperty(key, val2);
    assertEquals(val2.intValue(), config.getInt(key));
    assertEquals(val2, config.getInteger(key, val1));
}

From source file:com.impetus.kundera.ycsb.runner.YCSBRunner.java

public YCSBRunner(final String propertyFile, final Configuration config) {
    this.propertyFile = propertyFile;
    ycsbJarLocation = config.getString("ycsbjar.location");
    clientjarlocation = config.getString("clientjar.location");
    host = config.getString("hosts");
    schema = config.getString("schema");
    columnFamilyOrTable = config.getString("columnfamilyOrTable");
    releaseNo = config.getDouble("release.no");
    runType = config.getString("run.type", "load");
    port = config.getInt("port");
    password = config.getString("password");
    clients = config.getStringArray("clients");
    isUpdate = config.containsKey("update");
    crudUtils = new HibernateCRUDUtils();
}

From source file:com.cisco.oss.foundation.monitoring.RMIMonitoringAgent.java

private boolean isServiceExported(Configuration configuration, String serviceName) {
    boolean isJmxServiceExported = RMIRegistryManager.isServiceExported(configuration,
            configuration.getInt(FoundationMonitoringConstants.MX_PORT), serviceName);
    return isJmxServiceExported;
}

From source file:ezbake.IntentQuery.Sample.MongoDatasource.Server.MongoExternalDataSourceHandler.java

/***********
<tablesMetaData>//from   w  w  w. jav a2 s  .co m
   <num_table>1</num_table>
   <tables>
 <table>
    <name>impalaTest_users</name>
    <num_columns>6</num_columns>
    <init_string></init_string>
    <columns>
       <column>
          <name>user_id</name>
          <primitiveType>INT</primitiveType>
          <len></len>
          <precision></precision>
          <scale></scale>
          <ops>LT,LE,EQ,NEQ,GE,GT</ops>
       </column>
       ...
       <column>
       </column>
    <columns>
 </table>
 <table>
 </table>
   </tables>
</tablesMetaData>
***********/

private void parseDataSourceMetadata() {

    table_metadata_map = new HashMap<String, TableMetadata>();

    try {
        Configuration xmlConfig = new XMLConfiguration(impalaExternalDsConfigFile);

        dbHost = xmlConfig.getString("mongodb.host");
        dbPort = xmlConfig.getInt("mongodb.port");
        dbName = xmlConfig.getString("mongodb.database_name");

        String key = null;
        String table_name = null;
        int num_columns = -1;
        String init_str = null;
        List<TableColumnDesc> table_col_desc_list = new ArrayList<TableColumnDesc>();

        int total_tables = xmlConfig.getInt("tablesMetaData.num_table");
        for (int i = 0; i < total_tables; i++) {
            // get table name
            key = String.format("tablesMetaData.tables.table(%d).name", i);
            table_name = xmlConfig.getString(key);
            // get table number of columns
            key = String.format("tablesMetaData.tables.table(%d).num_columns", i);
            num_columns = xmlConfig.getInt(key);
            // get table init_string
            key = String.format("tablesMetaData.tables.table(%d).init_string", i);
            init_str = xmlConfig.getString(key);

            // get columns
            String col_name = null;
            String col_type = null;
            int col_len = 0;
            int col_precision = 0;
            int col_scale = 0;
            Set<String> col_ops = null;

            for (int j = 0; j < num_columns; j++) {
                key = String.format("tablesMetaData.tables.table(%d).columns.column(%d).name", i, j);
                col_name = xmlConfig.getString(key);
                key = String.format("tablesMetaData.tables.table(%d).columns.column(%d).primitiveType", i, j);
                col_type = xmlConfig.getString(key);
                if (col_type.equals("CHAR")) {
                    key = String.format("tablesMetaData.tables.table(%d).columns.column(%d).len", i, j);
                    col_len = xmlConfig.getInt(key);
                } else if (col_type.equals("DECIMAL")) {
                    key = String.format("tablesMetaData.tables.table(%d).columns.column(%d).precision", i, j);
                    col_precision = xmlConfig.getInt(key);
                    key = String.format("tablesMetaData.tables.table(%d).columns.column(%d).scale", i, j);
                    col_scale = xmlConfig.getInt(key);
                }

                key = String.format("tablesMetaData.tables.table(%d).columns.column(%d).ops", i, j);
                //List<String>   opsList = xmlConfig.getList(key);
                String[] opsArray = xmlConfig.getStringArray(key);
                col_ops = new HashSet<String>(Arrays.asList(opsArray));

                TableColumnDesc tableColumnDesc = new TableColumnDesc(col_name, col_type, col_len,
                        col_precision, col_scale, col_ops);

                table_col_desc_list.add(tableColumnDesc);
            }

            TableMetadata tableMetadata = new TableMetadata(table_name, num_columns, init_str,
                    table_col_desc_list);

            System.out.println(tableMetadata);

            table_metadata_map.put(table_name, tableMetadata);
        }
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:es.bsc.demiurge.monitoring.ganglia.Ganglia.java

public Ganglia() {
    //read the configuration variables to create the testing VM from the config.properties file

    Configuration config = Config.INSTANCE.getConfiguration();

    if (!config.containsKey(GANGLIA_COLLECTOR_IP) && !config.containsKey(GANGLIA_FRONT_END_PATH)
            && !config.containsKey(GANGLIA_PORT) && !config.containsKey(GANGLIA_PORT_QUERY)) {
        throw new RuntimeException("The configuration file " + Config.INSTANCE.getConfigurationFileName()
                + " must contain the next properties: " + GANGLIA_COLLECTOR_IP + ", " + GANGLIA_FRONT_END_PATH
                + ", " + GANGLIA_PORT + ", " + GANGLIA_PORT_QUERY);
    }/*from   w w  w  . j a  v  a 2 s .  co m*/
    this.gangliaCollectorIP = config.getString(GANGLIA_COLLECTOR_IP);
    this.gangliaPort = config.getInt(GANGLIA_PORT);
    this.gangliaPortQuery = config.getInt(GANGLIA_PORT_QUERY);
    this.gangliaFrontEndPath = config.getString(GANGLIA_FRONT_END_PATH);

}

From source file:com.yahoo.ads.pb.PistachiosServer.java

public boolean init() {
    boolean initialized = false;

    logger.info("Initializing profile server...........");
    try {/*from w ww.  jav  a2 s. co m*/
        // open profile store
        Configuration conf = ConfigurationManager.getConfiguration();
        profileStore = new TLongKyotoCabinetStore(conf.getString(PROFILE_BASE_DIR), 0, 8,
                conf.getInt("Profile.RecordsPerServer"), conf.getLong("Profile.MemoryPerServer"));

        /*
        */
        //profileStore.open();
        /*
        hostname = InetAddress.getLocalHost().getHostName();
        if(conf.getBoolean("Profile.Redesign.Firstload", false)){
           String fileName = "profileMapping.json";
           String refDir = "/home/y/libexec/server/refdata/";
           String fullName = refDir + File.separator + fileName;
           FileReader fr = new FileReader(fullName);
           JSONParser parser = new JSONParser();
           ContainerFactory containerFactory = new ContainerFactory() {
              public List creatArrayContainer() {
          return new LinkedList();
              }
                
              public Map createObjectContainer() {
          return new LinkedHashMap();
              }
                
           };
                   
           Map<String,List<String>> partition2Server = (Map<String,List<String>>) parser.parse(fr,containerFactory);
           Set<String> keys = partition2Server.keySet();
           Set<Integer> partitions = new TreeSet<Integer>();
           for(String key:keys){
              if(partition2Server.get(key).contains(hostname)){
          partitions.add(Integer.parseInt(key));
              }
           }
           String profilePath = "/home/y/libexec/server/profile/store_";
           String profileFilePrefix = "db_";
           String profileFileSurfix = ".kch";
           String profileWalFileSurfix = ".wal";
           int index = 0;
           for(int partition: partitions){
              File partitionDir = new File(profilePath+index);
              if(partitionDir.isDirectory()){
          logger.info("rename from {} to {}",profilePath+index,profilePath+partition);
          partitionDir.renameTo( new File(profilePath+partition));
              }
              File storeFile = new File(profilePath+partition+File.separator+profileFilePrefix+index+profileFileSurfix);
              if(storeFile.isFile()){
          logger.info("rename from {} to {}",profilePath+partition+File.separator+profileFilePrefix+index+profileFileSurfix, profilePath+partition+File.separator+profileFilePrefix+partition+profileFileSurfix);
          storeFile.renameTo(new File(profilePath+partition+File.separator+profileFilePrefix+partition+profileFileSurfix));
              }
              File storeFileWal =  new File(profilePath+partition+File.separator+profileFilePrefix+index+profileFileSurfix+profileWalFileSurfix);
              if(storeFileWal.isFile()){
          logger.info("rename from {} to {}",profilePath+partition+File.separator+profileFilePrefix+index+profileFileSurfix+profileWalFileSurfix,profilePath+partition+File.separator+profileFilePrefix+partition+profileFileSurfix+profileWalFileSurfix);
          storeFileWal.renameTo(new File(profilePath+partition+File.separator+profileFilePrefix+partition+profileFileSurfix+profileWalFileSurfix));
              }
                      
              index++;
           }
                   
        }
        */
        /*
        ModuleManager
           .registerMBean(
          ProfileServer.getInstance(),
          new ObjectName(
             "com.yahoo.ads.pb.platform.profile:name=ProfileServer"));
           */

        // initialize performance counter
        /*
        lookupCounter = new InflightCounter(counterGroupName, "Lookup");
        lookupCounter.register();
        noDataCounter = new IncrementCounter(counterGroupName, "LookupNoData");
        noDataCounter.register();
        */

        //         storeCounter = new InflightCounter(counterGroupName, "Store");
        //         storeCounter.register();
        //         failedStoreCounter = new IncrementCounter(counterGroupName,
        //                 "FailedStore");
        //         failedStoreCounter.register();

        //         boolean enableStorePartition = conf.getBoolean(
        //                 Constant.PROFILE_STORING_PARTITION_ENABLE, false);
        //         if (enableStorePartition) {

        logger.info("creating helix partition sepctator {} {} {}", conf.getString(ZOOKEEPER_SERVER, "EMPTY"),
                PistachiosConstants.CLUSTER_NAME, conf.getString(PROFILE_HELIX_INSTANCE_ID, "EMPTY"));
        helixPartitionSpectator = new HelixPartitionSpectator(conf.getString(ZOOKEEPER_SERVER), // zkAddr
                PistachiosConstants.CLUSTER_NAME, InetAddress.getLocalHost().getHostName() //conf.getString(PROFILE_HELIX_INSTANCE_ID) // instanceName
        );
        // Partition Manager for line spending
        manager = new HelixPartitionManager<>(conf.getString(ZOOKEEPER_SERVER), // zkAddr
                PistachiosConstants.CLUSTER_NAME, InetAddress.getLocalHost().getHostName() //conf.getString(PROFILE_HELIX_INSTANCE_ID) // instanceName
        );
        //manager.start("BootstrapOnlineOffline", new BootstrapOnlineOfflineStateModelFactory(new StorePartitionHandlerFactory()));
        manager.start(PistachiosConstants.PARTITION_MODEL,
                new BootstrapOnlineOfflineStateModelFactory(new StorePartitionHandlerFactory()));
        //         }

        initialized = true;
    } catch (Exception e) {
        logger.error("Failed to initialize ProfileServerModule", e);
    }
    logger.info("Finished initializing profile server...........");

    return initialized;
}