Example usage for org.apache.commons.configuration ConfigurationException printStackTrace

List of usage examples for org.apache.commons.configuration ConfigurationException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Usage

From source file:org.mot.core.MyOpenTraderCore.java

/**
 * This method is used to start all internal schedulers. It uses the Quartz scheduling engine for this. 
 * Make sure the configuration in the conf/scheduler.conf is up2date. 
 * /*from   ww  w. j a  v  a2  s  .co  m*/
 * @param name
 */
private void startScheduler(String name) {

    int seconds = 60;
    PropertiesFactory pf = PropertiesFactory.getInstance();
    String pathToConfigDir = pf.getConfigDir();
    try {
        PropertiesConfiguration config = new PropertiesConfiguration(pathToConfigDir + "/scheduler.properties");

        // Make sure the scheduler only runs on the designated node. 
        // Otherwise with multiple nodes running, each job will run several times! 
        String runOn;
        if (!name.equals("ALL")) {
            runOn = config.getString("scheduler.runOn", "mot1");
        } else {
            // For development (single node) purposes - just overwrite the value to be identical!
            runOn = "ALL";
        }
        seconds = config.getInt("watchdog.frequency.seconds", 60);
        boolean enabled = config.getBoolean("scheduler.enabled", true);

        if ((enabled) && (name.equals(runOn))) {
            QuartzScheduler qs = QuartzScheduler.getInstance();

            boolean watchDogEnabled = config.getBoolean("watchdog.enabled", true);
            String wdClass = config.getString("watchdog.class", "org.mot.core.scheduler.WatchDog");

            if (watchDogEnabled) {
                qs.scheduleNewRepeatingJob(wdClass, "WatchDog", "base", seconds);
            }

            String archiverClass = config.getString("tickarchiver.class",
                    "org.mot.core.scheduler.TickArchiver");
            boolean archiverEnabled = config.getBoolean("tickarchiver.enabled", true);

            if (archiverEnabled) {
                qs.scheduleNewJob(archiverClass, "Archiver", "base");
            }

            String sdrClass = config.getString("staticdatareader.class",
                    "org.mot.core.scheduler.StaticDataCollector");
            boolean sdrEnabled = config.getBoolean("staticdatareader.enabled", true);
            int sdrFrequency = config.getInt("staticdatareader.frequency", 360000);

            if (sdrEnabled) {
                qs.scheduleNewRepeatingJob(sdrClass, "StaticDataReader", "base", sdrFrequency);
            }

            String simClass = config.getString("backtest.simulator.class",
                    "org.mot.core.scheduler.BackTestSimulator");
            boolean simEnabled = config.getBoolean("backtest.simulator.enabled", true);

            if (simEnabled) {
                qs.scheduleNewJob(simClass, "Simulator", "base");
            }

            boolean emailEnabled = config.getBoolean("email.engine.enabled", true);

            if (emailEnabled) {
                String emailClass = config.getString("email.engine.class",
                        "org.mot.core.scheduler.EmailEngine");
                String cronExpression = config.getString("email.engine.cronExpression", "0 1 * * *");
                qs.scheduleCronJob(emailClass, "EmailEngine", "base", cronExpression);
            }

        }

    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.mot.core.scheduler.BackTestSimulator.java

private void init() {

    PropertiesFactory pf = PropertiesFactory.getInstance();

    Configuration simulationProperties;
    try {/* w  ww.  j  a v  a  2 s  .c  o  m*/
        simulationProperties = new PropertiesConfiguration(pf.getConfigDir() + "/simulation.properties");

        frequency = simulationProperties.getString("simulation.default.frequency", "TICK");
        quantity = simulationProperties.getInt("simulation.default.quantity", 10);
        minProfit = simulationProperties.getDouble("simulation.default.minProfit", 2.0);
        className = simulationProperties.getString("simulation.default.class",
                "org.mot.client.sg.mvgAvg.SimpleMvgAvgComparison");
        txnpct = simulationProperties.getDouble("simulation.order.txncost.pct", 0.0024);

    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Map<Integer, String> instruments = new Hashtable<Integer, String>();

    WatchListDAO wld = new WatchListDAO();
    instruments = wld.getWatchlistAsTable("STK");

    Iterator<Entry<Integer, String>> it = instruments.entrySet().iterator();

    while (it.hasNext()) {
        final Map.Entry<Integer, String> entry = it.next();
        String symbol = entry.getValue();

        this.triggerYesterdaysReplay(symbol);
        this.triggerLastWeekReplay(symbol);
        //this.triggerLastMonthReplay(symbol);

    }
}

From source file:org.mot.core.scheduler.TickArchiver.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    // TODO Auto-generated method stub

    String pattern = "yyyy-MM-dd";
    int daysToArchive = 90; //Default to 90 days

    // check the configuration for how many days to archive
    PropertiesFactory pf = PropertiesFactory.getInstance();
    String pathToConfigDir = pf.getConfigDir();
    try {/*from   w  w  w  . j  av  a 2s  .c o m*/
        PropertiesConfiguration config = new PropertiesConfiguration(pathToConfigDir + "/scheduler.properties");

        daysToArchive = config.getInt("tickarchiver.archiveAfterDays", 90);
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String archiveUpTo = db.subtractDaysFromDate(db.getTimeStampWithPattern(pattern), pattern, daysToArchive);

    tpd.archiveTicks(archiveUpTo);

}

From source file:org.mot.core.scheduler.WatchDog.java

public WatchDog() {
    PropertiesFactory pf = PropertiesFactory.getInstance();
    String pathToConfigDir = pf.getConfigDir();
    try {/*from w  w w  .  j  a v a 2  s.  co m*/
        PropertiesConfiguration config = new PropertiesConfiguration(pathToConfigDir + "/scheduler.properties");
        enabled = config.getBoolean("watchdog.enabled", true);
        difference = config.getInt("watchdog.sellAtDifference.pct", -5);

        // Make sure to set the difference to -1 by default. Positive values could be damaging
        if (difference >= 0) {
            difference = -1;
        }

        this.strategyWatchdog();

    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.mot.core.simulation.SimulationLoader.java

public static void main(String[] args) {

    Options options = new Options();
    options.addOption("c", true, "Config directory");
    options.addOption("n", true, "Provide the name of the simulation class");
    options.addOption("l", true, "List of instruments - separated by comma (no spaces!).");
    options.addOption("t", true, "Transaction costs - normally 0.0024 bps");
    options.addOption("s", true, "Start date in the format of 2014-07-01");
    options.addOption("e", true, "End date in the format of 2014-07-31");
    options.addOption("w", true, "Week of Year to process - this will ignore -s / -e flag");

    if (args.length == 0) {
        System.out.println("*** Missing arguments: ***");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("runSimulationLoader.sh|.bat", options);
        System.exit(0);/* ww w .  j av a2  s . c om*/
    }

    long t1 = System.currentTimeMillis();

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        PropertiesFactory pf = PropertiesFactory.getInstance();

        if (cmd.getOptionValue("c") != null) {
            // First make sure to set the config directory
            pf.setConfigDir(cmd.getOptionValue("c"));
        }

        System.setProperty("PathToConfigDir", pf.getConfigDir());

        logger.debug("Starting a new Simulation ...");

        // Read in properties from file
        Configuration simulationProperties;

        simulationProperties = new PropertiesConfiguration(pf.getConfigDir() + "/simulation.properties");

        final String frequency = simulationProperties.getString("simulation.default.frequency", "TICK");
        final int quantity = simulationProperties.getInt("simulation.default.quantity", 10);
        final Double minProfit = simulationProperties.getDouble("simulation.default.minProfit", 2.0);
        String className = simulationProperties.getString("simulation.default.class",
                "org.mot.client.sg.mvgAvg.SimpleMvgAvgComparison");

        Double txnpct;
        // Get the transaction percentage
        if (cmd.getOptionValue("t") != null) {
            txnpct = Double.valueOf(cmd.getOptionValue("t"));
        } else {
            txnpct = simulationProperties.getDouble("simulation.order.txncost.pct", 0.0024);
        }

        // Make sure to overwrite the className if provided in the command line
        if (cmd.getOptionValue("n") != null) {
            className = cmd.getOptionValue("n");
        }

        String[] symbols;
        // Array for the list of instruments
        if (cmd.getOptionValues("l") != null) {
            symbols = cmd.getOptionValues("l");

        } else {
            symbols = simulationProperties.getStringArray("simulation.default.instruments");
        }

        String startDate = null;
        String endDate = null;

        if (cmd.getOptionValue("w") != null) {

            DateBuilder db = new DateBuilder();
            String pattern = "yyyy-MM-dd";
            startDate = db.getDateForWeekOfYear(Integer.valueOf(cmd.getOptionValue("w")), pattern);
            endDate = db.addDaysToDate(startDate, pattern, 5);

        } else {

            // Get the start date
            if (cmd.getOptionValue("s") != null) {
                startDate = cmd.getOptionValue("s");
            } else {
                startDate = simulationProperties.getString("simulation.default.date.start", "2014-07-01");
            }

            // get the End date
            if (cmd.getOptionValue("e") != null) {
                endDate = cmd.getOptionValue("e");
            } else {
                endDate = simulationProperties.getString("simulation.default.date.end", "2014-07-31");
            }
        }

        System.out.println("*** Loading new values to simulation pipeline: *** ");
        System.out.println("* Using configuration from: " + pf.getConfigDir());
        System.out.println("* for Symbol: " + symbols.toString());
        System.out.println("* Start date: " + startDate);
        System.out.println("* End date: " + endDate);
        System.out.println("* Transaction costs: " + txnpct);
        System.out.println("* Using class file: " + className);
        System.out.println("************************************************** ");

        PropertyConfigurator.configure(pf.getConfigDir() + "/log4j.properties");

        Map<Integer, String> instruments = new Hashtable<Integer, String>();
        if (symbols[0].equals("ALL")) {
            WatchListDAO wld = new WatchListDAO();
            instruments = wld.getWatchlistAsTable("STK");

        } else {
            for (int p = 0; p < symbols.length; p++) {
                instruments.put(p, symbols[p].trim());
            }
        }

        Iterator<Entry<Integer, String>> it = instruments.entrySet().iterator();

        while (it.hasNext()) {
            final Map.Entry<Integer, String> entry = it.next();

            SimulationLoader msa = new SimulationLoader();
            //msa.loadSimulationRequests(entry.getValue(), className, frequency, quantity,  rangemin, rangemax, maxIncrement, startDate, endDate, txnpct);

            // (String symbol, String className, String frequency, int quantity, String startDate, String endDate, Double txnPct, Double minProfit ) {
            msa.loadSimulationRequests(entry.getValue(), className, frequency, quantity, startDate, endDate,
                    txnpct, minProfit);

        }

        System.out.println("*** FINISHED *** ");

    } catch (ConfigurationException e1) {
        // TODO Auto-generated catch block

        e1.printStackTrace();

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("runSimulationLoader.sh|.bat", options);

    } catch (Exception e) {
        // TODO Auto-generated catch block

        e.printStackTrace();

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("runSimulationLoader.sh|.bat", options);

    }

    long totalTime = (System.currentTimeMillis() - t1);

    logger.debug("End... Run took: " + totalTime + " msecs");
    System.exit(0);

}

From source file:org.mot.core.simulation.SimulationRunner.java

public static void main(String[] args) {

    // Run with -w 1-42 -l TSLA -1 581 -2 730 -d

    Options options = new Options();
    options.addOption("c", true, "Config directory");
    options.addOption("l", true, "Single instrument/symbol.");
    options.addOption("1", true, "Moving Average 1");
    options.addOption("2", true, "Moving Average 2");
    options.addOption("w", true, "Week of Year to process");
    options.addOption("d", false, "Write results to DB (default: false)");

    if (args.length == 0) {
        System.out.println("*** Missing arguments: ***");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("runSimulator.sh|.bat", options);
        System.exit(0);/*from  w  w  w  .  j a  v  a2  s  .com*/
    }

    try {
        // Setting command line options
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        PropertiesFactory pf = PropertiesFactory.getInstance();

        if (cmd.hasOption("c")) {
            // First make sure to set the config directory
            pf.setConfigDir(cmd.getOptionValue("c"));
        } else {
            // Default the configuration directory to <ROOT>/conf
            pf.setConfigDir("conf");
        }

        System.setProperty("PathToConfigDir", pf.getConfigDir());

        // Read in properties from file
        Configuration simulationProperties;

        simulationProperties = new PropertiesConfiguration(pf.getConfigDir() + "/simulation.properties");
        final String className = simulationProperties.getString("simulation.default.class",
                "org.mot.core.esper.AdvancedMvgAvgComparisonListenerG4");

        Double txnpct;
        // Get the transaction percentage
        if (cmd.getOptionValue("t") != null) {
            txnpct = Double.valueOf(cmd.getOptionValue("t"));
        } else {
            txnpct = simulationProperties.getDouble("simulation.order.txncost.pct", 0.0024);
        }

        String symbol = null;
        // Array for the list of instruments
        if (cmd.getOptionValue("l") != null) {
            symbol = cmd.getOptionValue("l");
        }

        Configuration genericProperties = new PropertiesConfiguration(pf.getConfigDir() + "/config.properties");
        PropertyConfigurator.configure(pf.getConfigDir() + "/log4j.properties");
        final int quantity = simulationProperties.getInt("simulation.default.quantity", 10);

        SimulationRunner rmas = new SimulationRunner();

        if (cmd.getOptionValue("w") != null) {

            String week = cmd.getOptionValue("w");
            Boolean writeToDB = false;

            if (cmd.hasOption("d")) {
                writeToDB = true;
            }

            int m1 = Integer.valueOf(cmd.getOptionValue("1"));
            int m2 = Integer.valueOf(cmd.getOptionValue("2"));

            if (week.contains("-")) {

                String[] weekList = week.split("-");
                int start = Integer.valueOf(weekList[0]);
                int end = Integer.valueOf(weekList[1]);

                for (int u = start; u < end; u++) {
                    rmas.processSingleRequestByWeek(m1, m2, txnpct, symbol, quantity, u, writeToDB, className);
                }

            } else {
                rmas.processSingleRequestByWeek(m1, m2, txnpct, symbol, quantity, Integer.valueOf(week),
                        writeToDB, className);
            }

            System.exit(0);

        } else {
            rmas.startThreads(genericProperties);

            while (true) {
                Thread.sleep(1000);
            }
        }

    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("runMovingAverageSimulator.sh|.bat", options);

    } catch (ConfigurationException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("runMovingAverageSimulator.sh|.bat", options);// TODO Auto-generated catch block

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.onosproject.driver.netconf.XmlConfigParser.java

protected static String createControllersConfig(HierarchicalConfiguration cfg,
        HierarchicalConfiguration actualCfg, String target, String netconfOperation, String controllerOperation,
        List<ControllerInfo> controllers) {
    //cfg.getKeys().forEachRemaining(key -> System.out.println(key));
    cfg.setProperty("edit-config.target", target);
    cfg.setProperty("edit-config.default-operation", netconfOperation);
    cfg.setProperty("edit-config.config.capable-switch.id", parseCapableSwitchId(actualCfg));
    cfg.setProperty("edit-config.config.capable-switch." + "logical-switches.switch.id",
            parseSwitchId(actualCfg));//from  w  ww . j  ava 2 s.  co m
    List<ConfigurationNode> newControllers = new ArrayList<>();
    for (ControllerInfo ci : controllers) {
        XMLConfiguration controller = new XMLConfiguration();
        controller.setRoot(new HierarchicalConfiguration.Node("controller"));
        String id = ci.type() + ":" + ci.ip() + ":" + ci.port();
        controller.setProperty("id", id);
        controller.setProperty("ip-address", ci.ip());
        controller.setProperty("port", ci.port());
        controller.setProperty("protocol", ci.type());
        newControllers.add(controller.getRootNode());
    }
    cfg.addNodes("edit-config.config.capable-switch.logical-switches." + "switch.controllers", newControllers);
    XMLConfiguration editcfg = (XMLConfiguration) cfg;
    StringWriter stringWriter = new StringWriter();
    try {
        editcfg.save(stringWriter);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
    String s = stringWriter.toString().replaceAll("<controller>",
            "<controller nc:operation=\"" + controllerOperation + "\">");
    s = s.replace("<target>" + target + "</target>", "<target><" + target + "/></target>");
    return s;

}

From source file:org.oryxeditor.server.ExportServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    res.setContentType("text/html");
    try {// www .j a v  a  2  s  . com
        if (config == null) {
            config = new PropertiesConfiguration("pnengine.properties");
        }
    } catch (ConfigurationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    String postVariable = config.getString("pnengine.post_variable");
    String engineURL = config.getString("pnengine.url") + "/petrinets";
    String engineURL_host = config.getString("pnengine.url");
    String modelURL = config.getString("pnengine.default_model_url");
    //      String formURL = null;
    //      String bindingsURL = null;

    String rdf = req.getParameter("data");
    String diagramTitle = req.getParameter("title");

    DocumentBuilder builder;
    BPMNDiagram diagram;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        builder = factory.newDocumentBuilder();
        Document document = builder.parse(new ByteArrayInputStream(rdf.getBytes()));
        BPMNRDFImporter importer = new BPMNRDFImporter(document);
        diagram = (BPMNDiagram) importer.loadBPMN();

        String basefilename = String.valueOf(System.currentTimeMillis());
        String tmpPNMLFile = this.getServletContext().getRealPath("/") + "tmp" + File.separator + basefilename
                + ".pnml";
        BufferedWriter out1 = new BufferedWriter(new FileWriter(tmpPNMLFile));

        // URL only for testing purposes...
        ExecConverter converter = new ExecConverter(diagram, modelURL,
                this.getServletContext().getRealPath("/"));
        converter.setBaseFileName(
                this.getServletContext().getRealPath("/") + "tmp" + File.separator + basefilename);
        PetriNet net = converter.convert();
        ExecPetriNet execnet = (ExecPetriNet) net;
        Document pnmlDoc = builder.newDocument();

        ExecPNPNMLExporter exp = new ExecPNPNMLExporter();
        execnet.setName(diagramTitle);
        exp.savePetriNet(pnmlDoc, execnet);

        OutputFormat format = new OutputFormat(pnmlDoc);
        XMLSerializer serial = new XMLSerializer(out1, format);
        serial.asDOMSerializer();
        serial.serialize(pnmlDoc.getDocumentElement());
        out1.close();

        StringWriter stringOut = new StringWriter();
        XMLSerializer serial2 = new XMLSerializer(stringOut, format);
        serial2.asDOMSerializer();

        serial2.serialize(pnmlDoc.getDocumentElement());

        URL url_engine = new URL(engineURL);
        HttpURLConnection connection_engine = (HttpURLConnection) url_engine.openConnection();
        connection_engine.setRequestMethod("POST");
        String encoding = new String(Base64.encodeBase64(("testuser:" + ":").getBytes()));
        ;
        connection_engine.setRequestProperty("Authorization", "Basic " + encoding);

        connection_engine.setUseCaches(false);
        connection_engine.setDoInput(true);
        connection_engine.setDoOutput(true);

        String escaped_content = postVariable + "=" + URLEncoder.encode(stringOut.toString(), "UTF-8");

        connection_engine.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection_engine.setRequestProperty("Accept",
                "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");

        // connection_engine.setRequestProperty("Content-Length",
        // ""+escaped_content.getBytes().length);
        String errorMessage = null;
        try {
            connection_engine.getOutputStream().write(escaped_content.getBytes());
            connection_engine.connect();
        } catch (ConnectException e) {
            errorMessage = e.getMessage();
        }

        // output link address
        res.getWriter().print("tmp/" + basefilename + ".pnml" + "\">View PNML</a><br/><br/>");
        if (errorMessage == null && connection_engine.getResponseCode() == 200) {
            res.getWriter().println("Deployment to Engine <a href=\"" + engineURL_host
                    + "/worklist\" target=\"_blank\">" + engineURL_host + "</a><br/><b>successful</b>!");
        } else {
            res.getWriter().println("Deployment to Engine <a href=\"" + engineURL + "\" target=\"_blank\">"
                    + engineURL + "</a><br/><b>failed</b> with message: \n" + errorMessage + "!");
        }

    } catch (ParserConfigurationException e1) {
        res.getWriter().println(e1.getMessage());
    } catch (SAXException e1) {
        res.getWriter().println(e1.getMessage());
    }

}

From source file:org.osbo.configuration.OsboConfigurationFiles.java

public OsboConfigurationFiles(String ruta, long tiempo) {
    // Exists only to defeat instantiation.
    file = ruta;//from  ww w  .  j  a va  2s  .  c  om
    config = null;
    try {
        config = new PropertiesConfiguration(file);
    } catch (ConfigurationException ex) {
        ex.printStackTrace();
    }
    FileChangedReloadingStrategy conf = new FileChangedReloadingStrategy();
    conf.setRefreshDelay(tiempo);
    config.setReloadingStrategy(conf);
}

From source file:org.ow2.aspirerfid.programmableengine.client.ProgrammableEngineClient.java

ProgrammableEngineClient() {

    String peEndPoint = null;// w w w.  ja va 2 s . com

    // read parameters from configuration file
    config = new XMLConfiguration();
    config.setListDelimiter(',');
    URL fileurl = this.getClass().getResource("/PeClientParameters.xml");
    // sets the parameters according to the properties file

    try {
        config.load(fileurl);
    } catch (ConfigurationException e) {
        String message = "Couldn't get WarehouseParameters at: " + fileurl.getFile() + "\n" + e.getMessage();
        LOG.debug(message);
        e.printStackTrace();
    }

    peEndPoint = config.getString("PeEndPoint");

    if (peEndPoint.equals(null) || peEndPoint.equals("") || peEndPoint == null) {
        this.peOLCBProcControlEndpoint = DEFAULT_peEndpoint + "/olcbproccontrol";
        this.peCLCBProcControlEndpoint = DEFAULT_peEndpoint + "/clcbproccontrol";
        this.peEBProcControlEndpoint = DEFAULT_peEndpoint + "/ebproccontrol";

    } else if (!peEndPoint.endsWith("/")) {
        this.peOLCBProcControlEndpoint = peEndPoint + "olcbproccontrol";
        this.peCLCBProcControlEndpoint = peEndPoint + "clcbproccontrol";
        this.peEBProcControlEndpoint = peEndPoint + "ebproccontrol";

    } else if (peEndPoint.endsWith("/")) {
        this.peOLCBProcControlEndpoint = peEndPoint + "/olcbproccontrol";
        this.peCLCBProcControlEndpoint = peEndPoint + "/clcbproccontrol";
        this.peEBProcControlEndpoint = peEndPoint + "/ebproccontrol";
    }

    initializeWS();

}