Example usage for org.apache.commons.configuration SubnodeConfiguration getDouble

List of usage examples for org.apache.commons.configuration SubnodeConfiguration getDouble

Introduction

In this page you can find the example usage for org.apache.commons.configuration SubnodeConfiguration getDouble.

Prototype

public double getDouble(String key) 

Source Link

Usage

From source file:eu.itesla_project.dymola.DymolaAdaptersMatParamsWriter.java

public void write(String indexName, Path outputMatFile) {
    LOGGER.info("writing input parameters for index '{}' to file  {}", indexName, outputMatFile);
    List<MLArray> mlarray = null;
    switch (indexName) {
    case OVERLOAD: {
        SubnodeConfiguration sc = configuration.getSection(OVERLOAD);
        mlarray = overloadMLArray(sc.getDouble("p"), sc.getDouble("d"));
        break;/*  w  ww.  j a v a  2s .  co m*/
    }
    case UNDEROVERVOLTAGE: {
        SubnodeConfiguration sc = configuration.getSection(UNDEROVERVOLTAGE);
        mlarray = underovervoltageMLArray(sc.getDouble("p"), sc.getDouble("d"));
        break;
    }
    case SMALLSIGNAL: {
        SubnodeConfiguration sc = configuration.getSection(SMALLSIGNAL);
        mlarray = smallsignalMLArray(sc.getDouble("step_min"), sc.getDouble("var_min"), sc.getDouble("f_1"),
                sc.getDouble("f_2"), sc.getDouble("d_1"), sc.getDouble("d_2"), sc.getDouble("d_3"),
                sc.getDouble("nm"), sc.getDouble("f_instant"), sc.getDouble("f_duration"));
        break;
    }
    case TRANSIENT: {
        SubnodeConfiguration sc = configuration.getSection(TRANSIENT);
        mlarray = transientMLArray();
        break;
    }
    default:
        throw new RuntimeException("index " + indexName + " not handled");
    }
    try {
        writeMLArrayToPath(outputMatFile, mlarray);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    }
}

From source file:com.oltpbenchmark.benchmarks.smallworldbank.SWBankWorker.java

@SuppressWarnings("unchecked")
@Override//from  ww w  . ja  v  a2  s.c  o m
protected TransactionStatus executeWork(TransactionType txnType) throws UserAbortException, SQLException {
    // LOG.info("Num Proc. "+Runtime.getRuntime().availableProcessors());
    long txid = -1;
    boolean isMalicous = false;

    try {

        if (txnType.getProcedureClass().equals(Balance.class)) {
            // LOG.info("Executing Balance transaction");
            Balance proc = getProcedure(Balance.class);
            assert (proc != null);

            long acctId = rdg.nextLong(acctIdMin + 1, acctIdMax);
            // LOG.info("Executing "+txnType.getProcedureClass().getName());
            proc.run(conn, acctId);

            AIMSLogger.logTransactionSpecs(1, String.format("%d,%d", acctId, this.getId()));

        } else if (txnType.getProcedureClass().equals(SendPayment.class)
                || txnType.getProcedureClass().equals(MSendPayment.class)) {

            if (txnType.getProcedureClass().equals(MSendPayment.class)) {
                isMalicous = true;
            }

            // generate random parameters
            long srcCustId = rdg.nextLong(custIdMin, custIdMax);
            long destCustId = rdg.nextLong(custIdMin, custIdMax);

            // make sure that it is not a self transfer
            while (destCustId == srcCustId) {
                destCustId = rdg.nextLong(custIdMin, custIdMax);
            }

            if (lastCustId > 0) { // this is not the first transaction
                                  // executed
                int coinflip = rdg.nextBinomial(1, tdp);
                if (coinflip == 1) {
                    // connect
                    srcCustId = lastCustId;
                    // LOG.info(String.format("coinflip = %d",coinflip));
                }
            }

            float balv = (float) rdg.nextUniform(0, 1) * 100;

            SendPayment proc = getProcedure(SendPayment.class);
            assert (proc != null);

            // LOG.info("Executing "+txnType.getProcedureClass().getName());
            txid = proc.run(conn, srcCustId, destCustId, balv, isMalicous);

            // lastCustIds.add(destCustId);
            lastCustId = srcCustId;
            AIMSLogger.logTransactionSpecs(2,
                    String.format("%d,%d,%3f,%d", srcCustId, destCustId, balv, this.getId()));

        } else if (txnType.getProcedureClass().equals(Distribute.class)
                || txnType.getProcedureClass().equals(MDistribute.class)) {
            List<SubnodeConfiguration> sncs = this.getBenchmarkModule().getWorkloadConfiguration()
                    .getXmlConfig().configurationsAt("transactiontypes/transactiontype[name='Distribute']");

            if (txnType.getProcedureClass().equals(MDistribute.class)) {
                isMalicous = true;
            }

            if (sncs.size() != 1) {
                throw new RuntimeException("Duplicate transaction types: Distribute");
            }

            assert (sncs.size() == 1);
            // LOG.info("size of sncs:"+sncs.size());

            SubnodeConfiguration snc = sncs.get(0);

            int fanout_min = snc.getInt("fanout_min");
            int fanout_max = snc.getInt("fanout_max");

            // int fanout_mu = snc.getInt("fanout_mu");
            // int fanout_sigma = snc.getInt("fanout_sigma");

            int fanout_n = snc.getInt("fanout_n");
            double fanout_p = snc.getDouble("fanout_p");

            // LOG.info("Distribute:" + snc.getInt("fanout_mu"));
            // LOG.info("Distribute:" + snc.getInt("fanout_sigma"));
            // LOG.info(String.format("n = %d, p= %f",fanout_n, fanout_p));
            int fanout_val = rdg.nextBinomial(fanout_n, fanout_p);
            // LOG.info(String.format("max = %d, min= %d", fanout_max,
            // fanout_min));
            // int fanout_val = rdg.nextInt(fanout_min, fanout_max);
            // LOG.info("here");

            if (fanout_val < fanout_min) {
                fanout_val = fanout_min;
            }

            if (fanout_val > fanout_max) {
                fanout_val = fanout_max;
            }

            // LOG.info("Random Fanout = " + fanout_val);

            long[] accIds = nextDistinctKLongs(acctIdMin, acctIdMax, fanout_val + 1);
            long[] dest_accids = Arrays.copyOfRange(accIds, 1, accIds.length);
            double[] dest_vals = nextKDoubles(0, 1, 100, fanout_val);

            Distribute proc = getProcedure(Distribute.class);

            txid = proc.run(conn, accIds[0], dest_accids, dest_vals, isMalicous);

            // LOG.info(snc.getString("name"));
            // LOG.info(snc.getInt("id"));
            // if (snc.getString("name").equalsIgnoreCase("Distribute")) {
            // LOG.info("Distribute:" + snc.getInt("fanin"));
            // LOG.info("Distribute:" + snc.getInt("fanout"));
            // }
            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            for (int i = 0; i < dest_vals.length; i++) {
                if (i != 0) {
                    sb1.append(':');
                    sb2.append(':');
                }
                sb1.append(dest_accids[i]);
                sb2.append(String.format("%3f", dest_vals[i]));
            }

            AIMSLogger.logTransactionSpecs(3,
                    String.format("%d,%s,%s,%d", accIds[0], sb1.toString(), sb2.toString(), this.getId()));

        } else if (txnType.getProcedureClass().equals(Collect.class)
                || txnType.getProcedureClass().equals(MCollect.class)) {

            if (txnType.getProcedureClass().equals(MCollect.class)) {
                isMalicous = true;
            }
            List<SubnodeConfiguration> sncs = this.getBenchmarkModule().getWorkloadConfiguration()
                    .getXmlConfig().configurationsAt("transactiontypes/transactiontype[name='Collect']");

            if (sncs.size() != 1) {
                throw new RuntimeException("Duplicate transaction types: Collect");
            }
            assert (sncs.size() == 1);
            SubnodeConfiguration snc = sncs.get(0);

            int fanin_min = snc.getInt("fanin_min");
            int fanin_max = snc.getInt("fanin_max");

            int fanin_n = snc.getInt("fanin_n");
            double fanin_p = snc.getDouble("fanin_p");

            int fanin_val = rdg.nextBinomial(fanin_n, fanin_p);

            if (fanin_val < fanin_min) {
                fanin_val = fanin_min;
            }

            if (fanin_val > fanin_max) {
                fanin_val = fanin_max;
            }

            // LOG.info("Random Fanin = " + fanin_val);

            long[] accIds = nextDistinctKLongs(acctIdMin, acctIdMax, fanin_val + 1);
            long[] src_accids = Arrays.copyOfRange(accIds, 1, accIds.length);
            double[] src_vals = nextKDoubles(0, 1, 100, fanin_val);

            Collect proc = getProcedure(Collect.class);

            txid = proc.run(conn, src_accids, accIds[0], src_vals, isMalicous);

            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            for (int i = 0; i < src_vals.length; i++) {
                if (i != 0) {
                    sb1.append(':');
                    sb2.append(':');
                }
                sb1.append(src_accids[i]);
                sb2.append(String.format("%3f", src_vals[i]));
            }

            AIMSLogger.logTransactionSpecs(4,
                    String.format("%s,%d,%s,%d", sb1.toString(), accIds[0], sb2.toString(), this.getId()));

        } else if (txnType.getProcedureClass().equals(ReportCheckingPerBranch.class)) {
            ReportCheckingPerBranch proc = getProcedure(ReportCheckingPerBranch.class);
            long b_count = (Math.round(
                    SWBankConstants.BRANCH_PER_COUNTRY * this.getWorkloadConfiguration().getScaleFactor())
                    * 100);
            // LOG.info("CHECK: b_count = "+b_count);
            proc.run(conn, b_count);

        } else if (txnType.getProcedureClass().equals(ReportCheckingPerBranch2.class)) {
            ReportCheckingPerBranch2 proc = getProcedure(ReportCheckingPerBranch2.class);
            long b_count = (Math.round(
                    SWBankConstants.BRANCH_PER_COUNTRY * this.getWorkloadConfiguration().getScaleFactor())
                    * 100);
            // LOG.info("CHECK: b_count = "+b_count);
            proc.run(conn, b_count);

        } else if (txnType.getProcedureClass().equals(ReportSavingPerBranch.class)) {

            ReportSavingPerBranch proc = getProcedure(ReportSavingPerBranch.class);
            long b_count = (Math.round(
                    SWBankConstants.BRANCH_PER_COUNTRY * this.getWorkloadConfiguration().getScaleFactor())
                    * 100);

            // LOG.info("SAV: b_count = "+b_count);
            proc.run(conn, b_count);

        } else if (txnType.getProcedureClass().equals(ReportActiveCustomers.class)) {
            ReportActiveCustomers proc = getProcedure(ReportActiveCustomers.class);
            proc.run(conn);

        } else if (txnType.getProcedureClass().equals(ListCountries.class)) {
            ListCountries proc = getProcedure(ListCountries.class);
            proc.run(conn);
        } else {

            throw new InvalidTransactionTypeException(
                    "Invalid transaction type: " + txnType.getProcedureClass().getName());

        }
    } catch (InvalidTransactionTypeException e) {

        e.printStackTrace();
        return TransactionStatus.RETRY_DIFFERENT;

    } catch (RuntimeException e) {
        conn.rollback();
        // LOG.info("Unknown transaction type");
        e.printStackTrace();
        return TransactionStatus.RETRY;
    }

    conn.commit();

    // send ids message after commiting transaction
    if (isMalicous) {
        LOG.info(String.format("Sending alert in %d msec", mddelay));
        exservice.schedule(new IDMessageSender(conn, txid), mddelay, TimeUnit.MILLISECONDS);
    }
    return TransactionStatus.SUCCESS;

}