Example usage for org.apache.commons.configuration AbstractFileConfiguration load

List of usage examples for org.apache.commons.configuration AbstractFileConfiguration load

Introduction

In this page you can find the example usage for org.apache.commons.configuration AbstractFileConfiguration load.

Prototype

public void load(InputStream in) throws ConfigurationException 

Source Link

Document

Load the configuration from the specified stream, using the encoding returned by #getEncoding() .

Usage

From source file:main.java.entry.ReadConfig.java

public static void readConfigFile(String file_name) {
    FileInputStream config_file = null;
    AbstractFileConfiguration config_param = null;

    Global.LOGGER.info("-----------------------------------------------------------------------------");
    Global.LOGGER.info("Reading simulation aspects from file ...");

    try {/*from   w ww  . j  av a2 s .  com*/
        // Access configuration file
        try {
            config_file = new FileInputStream(file_name);
            Global.LOGGER
                    .info("Simulation configuration file \"sim.cnf\" is found in the root directory and read.");

        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(
                    "Simulation configuration file \"sim.cnf\" is missing in the working directory !!");
            System.exit(0);
        }

        // Load configuration parameters
        config_param = new PropertiesConfiguration();
        config_param.load(config_file);

        //Read the number of servers, partitions and replicas
        Global.simulation = (String) config_param.getProperty("simulation.name");
        Global.setup = (String) config_param.getProperty("setup");
        Global.servers = Integer.parseInt((String) config_param.getProperty("initial.servers"));
        Global.serverSSD = Integer.parseInt((String) config_param.getProperty("server.ssd"));
        Global.serverSSDCapacity = Integer.parseInt((String) config_param.getProperty("server.ssd.capacity"));
        Global.partitions = Integer.parseInt((String) config_param.getProperty("fixed.partitions"));
        Global.partitionCapacity = Integer
                .parseInt((String) config_param.getProperty("fixed.partition.capacity"));
        Global.replicas = Integer.parseInt((String) config_param.getProperty("number.of.replicas"));

        Global.LOGGER.info("-----------------------------------------------------------------------------");
        Global.LOGGER.info("Initial number of servers: " + Global.servers);
        Global.LOGGER.info(
                "Number of SSD in each server: " + Global.serverSSD + " " + Global.serverSSDCapacity + "GB");
        Global.LOGGER.info("Individual server's capacity: "
                + ((Global.serverSSD * Global.serverSSDCapacity) / 1000) + "GB");
        Global.LOGGER.info("Fixed number of partitions: " + Global.partitions);
        Global.LOGGER.info("Individual partition's capacity: " + (Global.partitionCapacity / 1000) + "GB");
        Global.LOGGER.info("Replication value: " + Global.replicas);

        // Workload execution parameters --  will be used in Workload Executor
        Global.simulationPeriod = Double.parseDouble((String) config_param.getProperty("simulation.period"));
        Global.warmupPeriod = Double.parseDouble((String) config_param.getProperty("warmup.period"));

        Global.meanInterArrivalTime = Double
                .parseDouble((String) config_param.getProperty("inverse.of.mean.inter.arrival.time"));
        Global.meanServiceTime = Double
                .parseDouble((String) config_param.getProperty("inverse.of.mean.service.time"));

        Global.percentageChangeInWorkload = Double
                .parseDouble((String) config_param.getProperty("percentage.change.in.workload"));
        //Global.adjustment = Double.parseDouble((String) config_param.getProperty("adjustment"));         
        Global.observationWindow = Integer
                .parseInt((String) config_param.getProperty("observation.window.size"));
        Global.uniqueMaxFixed = Integer.parseInt((String) config_param.getProperty("unique.max.fixed"));
        Global.expAvgWt = Double.parseDouble((String) config_param.getProperty("exponential.Avg.Weight"));
        Global.uniqueEnabled = Boolean.parseBoolean((String) config_param.getProperty("unique.enable"));

        Global.LOGGER.info("-----------------------------------------------------------------------------");
        Global.LOGGER.info("Simulation name: " + Global.simulation);
        Global.LOGGER
                .info("Simulation Period: " + (Global.simulationPeriod / Global.observationWindow) + " hrs");
        Global.LOGGER.info("Warmup time: " + (Global.warmupPeriod / Global.observationWindow) + " hrs");
        Global.LOGGER.info("-----------------------------------------------------------------------------");
        Global.LOGGER.info("Probability of Transaction birth and death: " + Global.percentageChangeInWorkload);
        Global.LOGGER.info("Mean inter Transaction arrival time: " + Global.meanInterArrivalTime);
        Global.LOGGER.info("Mean Transaction service time: " + Global.meanServiceTime);

        // Read configuration parameters
        Global.workloadAware = Boolean.parseBoolean((String) config_param.getProperty("workload.aware"));
        Global.workloadRepresentation = (String) config_param.getProperty("workload.representation");

        Global.LOGGER.info("-----------------------------------------------------------------------------");
        Global.LOGGER.info("Workload aware: " + Global.workloadAware);
        Global.LOGGER.info("Workload representation: " + Global.workloadRepresentation);

        if (Global.workloadAware) {

            Global.incrementalRepartitioning = Boolean
                    .parseBoolean((String) config_param.getProperty("incremental.repartitioning"));
            Global.graphcutBasedRepartitioning = Boolean
                    .parseBoolean((String) config_param.getProperty("graphcutbased.repartitioning"));

            Global.dynamicPartitioning = Boolean
                    .parseBoolean((String) config_param.getProperty("dynamic.partitioning"));
            Global.dynamicPartitions = Global.partitions; // Initialisation

            Global.repartStatic = Boolean
                    .parseBoolean((String) config_param.getProperty("static.repartitioning"));
            Global.repartHourly = Boolean
                    .parseBoolean((String) config_param.getProperty("hourly.repartitioning"));
            Global.repartThreshold = Boolean
                    .parseBoolean((String) config_param.getProperty("threshold.repartitioning"));

            Global.streamCollection = Boolean
                    .parseBoolean((String) config_param.getProperty("stream.collection"));
            Global.streamCollectorSizeFactor = Integer
                    .parseInt((String) config_param.getProperty("stream.collector.size.factor"));

            if (Global.streamCollection) {
                Global.dsm = new DataStreamMining();
                Global.associative = Boolean.parseBoolean((String) config_param.getProperty("associative"));
                Global.adaptive = Boolean.parseBoolean((String) config_param.getProperty("adaptive"));
            }

            Global.enableTrClassification = Boolean
                    .parseBoolean((String) config_param.getProperty("transaction.classification"));
            Global.trClassificationStrategy = (String) config_param
                    .getProperty("transaction.classification.strategy");

            Global.dataMigrationStrategy = (String) config_param.getProperty("data.migration.strategy");

            Global.compressionEnabled = Boolean
                    .parseBoolean((String) config_param.getProperty("compression.enabled"));
            Global.compressionBeforeSetup = Boolean
                    .parseBoolean((String) config_param.getProperty("compression.before.setup"));

            if (!Global.compressionBeforeSetup)
                Global.swordInitial = false;

            if (Global.incrementalRepartitioning) {
                Global.userDefinedIDtThreshold = Double
                        .parseDouble((String) config_param.getProperty("idt.threshold"));

                Global.spanReduction = Boolean
                        .parseBoolean((String) config_param.getProperty("span.reduction"));

                if (Global.spanReduction)
                    Global.spanReduce = Integer.parseInt((String) config_param.getProperty("span.reduce"));

                Global.lambda = Double.parseDouble((String) config_param.getProperty("lambda"));

                if (Global.lambda < 0 || Global.lambda > 1) {
                    Global.LOGGER.error("Wrong value set for 'lambda' !!");
                    System.exit(400);
                }
            }

            Global.LOGGER.info("-----------------------------------------------------------------------------");
            Global.LOGGER.info("Incremental repartitioning: " + Global.incrementalRepartitioning);
            Global.LOGGER.info("Static repartitioning: " + Global.repartStatic);
            Global.LOGGER.info("Hourly repartitioning: " + Global.repartHourly);
            Global.LOGGER.info("Threshold-based repartitioning: " + Global.repartThreshold);

            Global.LOGGER.info("-----------------------------------------------------------------------------");
            Global.LOGGER.info("Transaction classification: " + Global.enableTrClassification);
            Global.LOGGER.info("Transaction classification strategy: " + Global.trClassificationStrategy);

            Global.LOGGER.info("-----------------------------------------------------------------------------");
            Global.LOGGER.info("Data migration strategy: " + Global.dataMigrationStrategy);

            Global.LOGGER.info("-----------------------------------------------------------------------------");
            Global.LOGGER.info("Workload compression enabled: " + Global.compressionEnabled);
            Global.LOGGER.info("Compression before setup enabled: " + Global.compressionBeforeSetup);

            if (Global.compressionEnabled) {
                Global.compressionRatio = Double
                        .parseDouble((String) config_param.getProperty("compression.ratio"));
                Global.LOGGER.info("Compression ratio: " + Global.compressionRatio);
            }
        }
    } catch (ConfigurationException e) {
        Global.LOGGER.error("Failed to read the configurations from sim.cnf file !!", e);
    } finally {
        if (config_file != null) {
            try {
                config_file.close();
            } catch (IOException e) {
                Global.LOGGER.error("Failed to close the sim.cnf file !!", e);
            }
        }
    }
}

From source file:com.moneydance.modules.features.importlist.util.Settings.java

Settings() {
    final AbstractFileConfiguration abstractFileConfiguration = new PropertiesConfiguration();

    try {/*  ww w.j  a  v a 2s.c om*/
        InputStream inputStream = Helper.getInputStreamFromResource(PROPERTIES_RESOURCE);
        abstractFileConfiguration.load(inputStream);
    } catch (ConfigurationException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
    this.config = abstractFileConfiguration;
}

From source file:main.java.workload.Workload.java

protected Workload(String file) {
    setFile_name(file);/* ww  w  . j a v a 2s.  c o  m*/
    BufferedReader config_file = null;
    AbstractFileConfiguration parameters = null;

    try {
        config_file = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(getFile_name())));

        Global.LOGGER
                .info("Configuration file " + getFile_name() + " is found under src/main/resources and read.");

        //Load configuration parameters
        parameters = new PropertiesConfiguration();
        parameters.load(config_file);

        //Read the number of tables and types of transactions
        tbl = parameters.getInt("tables");
        tr_types = parameters.getInt("transaction.types");

        Global.LOGGER.info("Number of database tables: " + tbl);
        Global.LOGGER.info("Types of workload transactions: " + tr_types);

    } catch (ConfigurationException e) {
        e.printStackTrace();
    } finally {
        if (config_file != null) {
            try {
                config_file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //Initialize other variables
    this.warmingup = false;
    this.tbl_types = new HashMap<Integer, Integer>();
    this.schema = new HashMap<Integer, ArrayList<Integer>>();
    this.tr_proportions = new HashMap<Integer, Double>();
    this.tr_tuple_distributions = new HashMap<Integer, ArrayList<Integer>>();
    this.tr_changes = new HashMap<Integer, ArrayList<Integer>>();

    this._cache = new HashMap<Integer, ArrayList<Integer>>();
    this._cache_keys = new ArrayList<Integer>();
    this._cache_id = 0;
}

From source file:main.java.workload.twitter.TwitterWorkload.java

public void readConfig() {
    BufferedReader config_file = null;
    AbstractFileConfiguration parameters = null;
    int i, j = 0;

    try {/*from  w  w  w  .  j  a va 2  s.  co m*/
        config_file = new BufferedReader(
                new InputStreamReader(getClass().getResourceAsStream(this.getFile_name())));

        //Load configuration parameters
        parameters = new PropertiesConfiguration();
        parameters.load(config_file);

        //Read Twitter scale
        //WorkloadConstants.SCALE_FACTOR = parameters.getDouble("twitter.scale");
        WorkloadConstants.SCALE_FACTOR = Global.scaleFactor;
        Global.LOGGER.info("Twitter scale (as the number of users): " + WorkloadConstants.SCALE_FACTOR);

        //Read Twitter table types
        i = 1;
        for (Object param : parameters.getList("twitter.tbl.type")) {
            tbl_types.put(i, Integer.parseInt((String) param));
            ++i;
        }

        Global.LOGGER.info("Twitter tables types: " + tbl_types);

        //Read Twitter schema
        i = j = 0;
        ArrayList<Integer> temp = null;
        for (Object param : parameters.getList("twitter.schema")) {
            if (j >= tbl_types.size() || j == 0) {
                ++i;
                j = 0;
                temp = new ArrayList<Integer>();
                schema.put(i, temp);
            }

            schema.get(i).add(Integer.parseInt((String) param));
            ++j;
        }

        Global.LOGGER.info("Twitter table-level schema: " + schema);

        //Read Twitter transaction proportion
        i = 0;
        //new 
        this.trTypes = new int[tr_types];
        this.trProbabilities = new double[tr_types];

        for (Object param : parameters.getList("twitter.trs.proportions")) {
            ++i;
            tr_proportions.put(i, Double.parseDouble((String) param));

            this.trTypes[i - 1] = i;
            this.trProbabilities[i - 1] = Double.parseDouble((String) param);
        }

        Global.LOGGER.info("Twitter transaction proportions: " + tr_proportions);

    } catch (ConfigurationException e) {
        e.printStackTrace();
    } finally {
        if (config_file != null) {
            try {
                config_file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:main.java.workload.tpcc.TpccWorkload.java

public void readConfig() {
    BufferedReader config_file = null;
    AbstractFileConfiguration parameters = null;
    int i, j = 0;

    try {/*from   w w  w. ja va2 s .c  om*/
        config_file = new BufferedReader(
                new InputStreamReader(getClass().getResourceAsStream(this.getFile_name())));

        //Load configuration parameters
        parameters = new PropertiesConfiguration();
        parameters.load(config_file);

        //Read TPCC scale
        //WorkloadConstants.SCALE_FACTOR = parameters.getDouble("tpcc.scale");
        WorkloadConstants.SCALE_FACTOR = Global.scaleFactor;
        Global.LOGGER.info("TPCC scale: " + WorkloadConstants.SCALE_FACTOR);

        //Read TPCC warehouses
        TpccConstants.NUM_WAREHOUSES = parameters.getInt("tpcc.warehouses");
        Global.LOGGER.info("TPCC warehouses: " + TpccConstants.NUM_WAREHOUSES);

        //Read TPCC table types
        i = 1;
        for (Object param : parameters.getList("tpcc.tbl.type")) {
            tbl_types.put(i, Integer.parseInt((String) param));
            ++i;
        }
        Global.LOGGER.info("TPCC tables types: " + tbl_types);

        //Read TPCC schema
        i = j = 0;
        ArrayList<Integer> temp = null;
        for (Object param : parameters.getList("tpcc.schema")) {
            if (j >= 9 || j == 0) {
                ++i;
                j = 0;
                temp = new ArrayList<Integer>();
                schema.put(i, temp);
            }

            schema.get(i).add(Integer.parseInt((String) param));
            ++j;
        }
        Global.LOGGER.info("TPCC table-level schema: " + schema);

        //Read TPCC transaction proportion
        i = 0;
        //new 
        this.trTypes = new int[tr_types];
        this.trProbabilities = new double[tr_types];

        for (Object param : parameters.getList("tpcc.trs.proportions")) {
            ++i;
            tr_proportions.put(i, Double.parseDouble((String) param));

            // new
            this.trTypes[i - 1] = i;
            this.trProbabilities[i - 1] = Double.parseDouble((String) param);
        }
        Global.LOGGER.info("TPCC transaction proportions: " + tr_proportions);

        //Read TPCC transactions
        i = j = 0;
        temp = null;
        for (Object param : parameters.getList("tpcc.trs.tbl_data")) {
            if (j >= 9 || j == 0) {
                ++i;
                j = 0;
                temp = new ArrayList<Integer>();
                tr_tuple_distributions.put(i, temp);
            }

            tr_tuple_distributions.get(i).add(Integer.parseInt((String) param));
            ++j;
        }
        Global.LOGGER.info("TPCC transaction table-level data distributions: " + tr_tuple_distributions);

        //Read TPCC transactional changes
        i = j = 0;
        temp = null;
        for (Object param : parameters.getList("tpcc.trs.tbl_changes")) {
            if (j >= 9 || j == 0) {
                ++i;
                j = 0;
                temp = new ArrayList<Integer>();
                tr_changes.put(i, temp);
            }

            tr_changes.get(i).add(Integer.parseInt((String) param));
            ++j;
        }
        Global.LOGGER.info("TPCC table-level transactional changes: " + tr_changes);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    } finally {
        if (config_file != null) {
            try {
                config_file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}