List of usage examples for java.lang Exception getMessage
public String getMessage()
From source file:edu.umd.ujjwalgoel.AnalyzePMI.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;//from www . ja v a2 s . c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzePMI.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); BufferedReader br = null; int countPairs = 0; List<PairOfWritables<PairOfStrings, FloatWritable>> pmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>(); List<PairOfWritables<PairOfStrings, FloatWritable>> cloudPmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>(); List<PairOfWritables<PairOfStrings, FloatWritable>> lovePmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>(); PairOfWritables<PairOfStrings, FloatWritable> highestPMI = null; PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI = null; PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI2 = null; PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI3 = null; PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI = null; PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI2 = null; PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI3 = null; try { FileSystem fs = FileSystem.get(new Configuration()); FileStatus[] status = fs.listStatus(new Path(inputPath)); //PairOfStrings pair = new PairOfStrings(); for (int i = 0; i < status.length; i++) { br = new BufferedReader(new InputStreamReader(fs.open(status[i].getPath()))); String line = br.readLine(); while (line != null) { String[] words = line.split("\\t"); float value = Float.parseFloat(words[1].trim()); String[] wordPair = words[0].replaceAll("\\(", "").replaceAll("\\)", "").split(","); PairOfStrings pair = new PairOfStrings(); pair.set(wordPair[0].trim(), wordPair[1].trim()); if (wordPair[0].trim().equals("cloud")) { PairOfWritables<PairOfStrings, FloatWritable> cloudPmi = new PairOfWritables<PairOfStrings, FloatWritable>(); cloudPmi.set(pair, new FloatWritable(value)); cloudPmis.add(cloudPmi); if ((highestCloudPMI == null) || (highestCloudPMI.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) { highestCloudPMI = cloudPmi; } else if ((highestCloudPMI2 == null) || (highestCloudPMI2.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) { highestCloudPMI2 = cloudPmi; } else if ((highestCloudPMI3 == null) || (highestCloudPMI3.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) { highestCloudPMI3 = cloudPmi; } } if (wordPair[0].trim().equals("love")) { PairOfWritables<PairOfStrings, FloatWritable> lovePmi = new PairOfWritables<PairOfStrings, FloatWritable>(); lovePmi.set(pair, new FloatWritable(value)); lovePmis.add(lovePmi); if ((highestLovePMI == null) || (highestLovePMI.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) { highestLovePMI = lovePmi; } else if ((highestLovePMI2 == null) || (highestLovePMI2.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) { highestLovePMI2 = lovePmi; } else if ((highestLovePMI3 == null) || (highestLovePMI3.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) { highestLovePMI3 = lovePmi; } } PairOfWritables<PairOfStrings, FloatWritable> pmi = new PairOfWritables<PairOfStrings, FloatWritable>(); pmi.set(pair, new FloatWritable(value)); pmis.add(pmi); if (highestPMI == null) { highestPMI = pmi; } else if (highestPMI.getRightElement().compareTo(pmi.getRightElement()) < 0) { highestPMI = pmi; } countPairs++; line = br.readLine(); } } } catch (Exception ex) { System.out.println("ERROR" + ex.getMessage()); } /*Collections.sort(pmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { /*if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Collections.sort(cloudPmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Collections.sort(lovePmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); PairOfWritables<PairOfStrings, FloatWritable> highestPMI = pmis.get(0); PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI = cloudPmis.get(0); PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI2 = cloudPmis.get(1); PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI3 = cloudPmis.get(2); PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI = lovePmis.get(0); PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI2 = lovePmis.get(1); PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI3 = lovePmis.get(2);*/ System.out.println("Total Distinct Pairs : " + countPairs); System.out.println("Pair with highest PMI : (" + highestPMI.getLeftElement().getLeftElement() + ", " + highestPMI.getLeftElement().getRightElement()); System.out .println("Word with highest PMI with Cloud : " + highestCloudPMI.getLeftElement().getRightElement() + " with value : " + highestCloudPMI.getRightElement().get()); System.out.println( "Word with second highest PMI with Cloud : " + highestCloudPMI2.getLeftElement().getRightElement() + " with value : " + highestCloudPMI2.getRightElement().get()); System.out.println( "Word with third highest PMI with Cloud : " + highestCloudPMI3.getLeftElement().getRightElement() + " with value : " + highestCloudPMI3.getRightElement().get()); System.out.println("Word with highest PMI with Love : " + highestLovePMI.getLeftElement().getRightElement() + " with value : " + highestLovePMI.getRightElement().get()); System.out.println( "Word with second highest PMI with Love : " + highestLovePMI2.getLeftElement().getRightElement() + " with value : " + highestLovePMI2.getRightElement().get()); System.out.println( "Word with third highest PMI with Love : " + highestLovePMI3.getLeftElement().getRightElement() + " with value : " + highestLovePMI3.getRightElement().get()); }
From source file:it.jnrpe.server.CJNRPEServer.java
public static void main(String[] args) { CommandLine cl = parseCommandLine(args); if (cl.hasOption("help") && cl.getOptionValue("help") == null) printUsage();//w w w . j a v a 2 s . c o m if (cl.hasOption("version")) printVersion(); CJNRPEConfiguration.init(cl.getOptionValue("conf")); if (cl.hasOption("help") && cl.getOptionValue("help") != null) printHelp(cl.getOptionValue("help")); if (cl.hasOption("list")) printPluginList(); if (cl.hasOption("generateConfig")) generateScheletonConfig(cl.getOptionValue("generateConfig")); // // Configure the timeout watcher // m_ThreadTimeoutWatcher = new ThreadTimeoutWatcher(); // m_ThreadTimeoutWatcher.setThreadTimeout(CJNRPEConfiguration.getInstance().getThreadTimeout()); // m_ThreadTimeoutWatcher.start(); List vBindings = CJNRPEConfiguration.getInstance().getServerBindings(); for (Iterator iterator = vBindings.iterator(); iterator.hasNext();) { CBinding binding = (CBinding) iterator.next(); try { CBindingThread bt = new CBindingThread(binding); bt.setAcceptedHosts(CJNRPEConfiguration.getInstance().getAcceptedHosts()); bt.start(); m_vBindingThreads.add(bt); } catch (Exception e) { System.out.println("ERROR BINDING TO ADDRESS " + binding.getIP() + ":" + binding.getPort() + " - " + e.getMessage()); System.exit(-1); } } }
From source file:com.laudandjolynn.mytv.Main.java
public static void main(String[] args) { // ????//ww w .jav a 2 s .c o m startService(); com.laudandjolynn.mytv.Server hessian = new HessianServer(); try { hessian.start(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new MyTvException(e); } com.laudandjolynn.mytv.Server rmi = new RmiServer(); try { rmi.start(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new MyTvException(e); } logger.info("My TV Program Table Crawler is running."); }
From source file:kevin.gvmsgarch.App.java
public static void main(String[] args) throws HttpException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, JSONException, InterruptedException { System.out.println("Google Voice Message Archiver"); System.out.println("Copyright (C) 2013 Kevin Carter"); System.out.println("This program comes with ABSOLUTELY NO WARRANTY"); System.out.println("This is free software, and you are welcome to redistribute it"); System.out.println("under certain conditions. See the LICENSE file or"); System.out.println("http://www.gnu.org/licenses/gpl-3.0.txt for details"); try {//from w w w . j a va 2s .co m HttpClient c = new HttpClient(); String userName = getUserName(); String password = getPassword(); int locationChosenIndex = JOptionPane.CLOSED_OPTION; if (password != null) { locationChosenIndex = JOptionPane.showOptionDialog(null, "Message source", "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, Worker.ListLocation.values(), Worker.ListLocation.inbox); } if (locationChosenIndex != JOptionPane.CLOSED_OPTION) { int modeChosenIndex = 0; Worker.ArchiveMode modeChosen = null; Worker.ListLocation location = Worker.ListLocation.values()[locationChosenIndex]; Worker.ArchiveMode[] availableModes = location.getAllowedModes(); if (availableModes.length == 1) { modeChosen = availableModes[0]; } else { modeChosenIndex = JOptionPane.showOptionDialog(null, "Operation mode", "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, availableModes, Worker.ArchiveMode.archive); if (modeChosenIndex != JOptionPane.CLOSED_OPTION) { modeChosen = availableModes[modeChosenIndex]; } } ContactFilter filter = null; if (modeChosenIndex != JOptionPane.CLOSED_OPTION && locationChosenIndex != JOptionPane.CLOSED_OPTION) { filter = buildFilter(); } if (modeChosenIndex != JOptionPane.CLOSED_OPTION && locationChosenIndex != JOptionPane.CLOSED_OPTION && filter != null && areYouSure(modeChosen, location, filter)) { assert modeChosen != null : "ZOMG"; String authToken = getToken(userName, password); String rnrse = getRnrse(authToken); final ProgressMonitor pm = new ProgressMonitor(null, "Working", "", 0, App.parseMsgsLeft(extractInboxJson(authToken, location, 1))); pm.setMillisToDecideToPopup(0); pm.setMillisToPopup(0); Worker worker = new Worker(authToken, rnrse, pm, modeChosen, location, filter); worker.addPropertyChangeListener(new ProgressPropertyChangeListener(pm)); pm.setProgress(0); worker.execute(); } } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE); } }
From source file:com.kynetx.ParseRuleset.java
public static void main(String[] args) throws Exception { File f = new File(args[0]); int notparsed = 0; int parsed = 0; File[] files = null;//from w w w. ja v a 2 s . co m if (f.isDirectory()) { files = f.listFiles(); } else { files = new File[1]; files[0] = new File(args[0]); } for (int i = 0; i < files.length; i++) { File thefile = files[i]; long start = System.currentTimeMillis(); boolean skipfile = false; for (int ii = 0; ii < ignore.length; ii++) { if (thefile.getCanonicalPath().indexOf(ignore[ii] + ".krl") > 0) { skipfile = true; break; } } if (thefile.length() == 0 || thefile.length() == 31 || thefile.length() == 162 || skipfile) { notparsed = notparsed + 1; // System.out.println("Skipping: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." ); // System.out.println("Skipping " + thefile); continue; } parsed = parsed + 1; try { ANTLRFileStream input = new ANTLRFileStream(thefile.getCanonicalPath()); com.kynetx.RuleSetLexer lexer = new com.kynetx.RuleSetLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); com.kynetx.RuleSetParser parser = new com.kynetx.RuleSetParser(tokens); parser.ruleset(); JSONObject js = new JSONObject(parser.rule_json); if (parser.parse_errors.size() > 0) { for (int ii = 0; ii < parser.parse_errors.size(); ii++) { System.err .println("ERROR FOUND " + parser.parse_errors.get(ii) + " - " + thefile.toString()); } } // System.out.println("Parsed: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." ); //System.out.println(unescapeUnicode(js.toString())); System.out.println(js.toString()); //System.out.println("============="); //System.out.println(js.toString()); } catch (Exception e) { // System.out.println("Error: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." ); System.out.println("Error " + thefile + " " + e.getMessage()); e.printStackTrace(); } } // System.out.println("Not Parsed " + notparsed); // System.out.println("Parsed " + parsed); }
From source file:cx2x.Cx2x.java
/** * Main point of entry of the program.//from w w w .ja v a 2s . c o m * * @param args Arguments of the program. * @throws Exception if translation failed. */ public static void main(String[] args) throws Exception { String input; String xcodeMlOutput = null; String fortranOutput = null; String target_option = null; String directive_option = null; String configuration_path = null; String schema_path = null; int maxColumns = 0; boolean forcePure = false; CommandLine cmd; try { cmd = processCommandArgs(args); } catch (ParseException pex) { error(pex.getMessage()); return; } // Help option if (cmd.hasOption("h")) { usage(); return; } // Display target list option if (cmd.hasOption("tl")) { listTarget(); return; } // Display directive list option if (cmd.hasOption("dl")) { listDirectiveLanguage(); return; } // Target option if (cmd.hasOption("t")) { target_option = cmd.getOptionValue("t"); } // Directive option if (cmd.hasOption("dir")) { directive_option = cmd.getOptionValue("dir"); } // Suppressing line directive option if (cmd.hasOption("l")) { XmOption.setIsSuppressLineDirective(true); } // Debug option if (cmd.hasOption("d")) { XmOption.setDebugOutput(true); } // XcodeML/F output file option if (cmd.hasOption("o")) { xcodeMlOutput = cmd.getOptionValue("o"); } // FORTRAN output file option if (cmd.hasOption("f")) { fortranOutput = cmd.getOptionValue("f"); } if (cmd.hasOption("w")) { maxColumns = Integer.parseInt(cmd.getOptionValue("w")); } if (cmd.hasOption("c")) { configuration_path = cmd.getOptionValue("c"); } if (cmd.hasOption("s")) { schema_path = cmd.getOptionValue("s"); } // Check that configuration file exists if (configuration_path == null) { error("Configuration file missing."); return; } File configFile = new File(configuration_path); if (!configFile.exists()) { error("Configuration file not found. " + configuration_path); } if (cmd.hasOption("sc")) { showConfig(configuration_path, schema_path); return; } if (cmd.getArgs().length == 0) { error("no input file"); return; } else { input = cmd.getArgs()[0]; } // Module search path options if (cmd.hasOption("M")) { for (String value : cmd.getOptionValues("M")) { XcodeMLtools_Fmod.addSearchPath(value); } } // Read the configuration file Configuration config; try { config = new Configuration(configuration_path, schema_path); config.setUserDefinedTarget(target_option); config.setUserDefineDirective(directive_option); config.setMaxColumns(maxColumns); } catch (Exception ex) { error(ex.getMessage()); return; } // Force pure option if (cmd.hasOption("fp")) { config.setForcePure(); } // Call the translator to apply transformation on XcodeML/F ClawXcodeMlTranslator translator = new ClawXcodeMlTranslator(input, xcodeMlOutput, config); translator.analyze(); translator.transform(); translator.flush(config); // Produce report if (cmd.hasOption("r")) { ClawTransformationReport report = new ClawTransformationReport(cmd.getOptionValue("r")); report.generate(config, args, translator); } // Decompile XcodeML/F to Fortran FortranDecompiler decompiler = new FortranDecompiler(); if (!decompiler.decompile(fortranOutput, xcodeMlOutput, maxColumns, XmOption.isSuppressLineDirective())) { error("Unable to decompile XcodeML to Fortran"); } }
From source file:de.codesourcery.jasm16.compiler.Main.java
public static void main(String[] args) throws Exception { try {/*from w w w .j av a 2 s.c o m*/ System.exit(new Main().run(args)); } catch (Exception e) { System.out.println("\n\nERROR: " + e.getMessage() + "\n"); e.printStackTrace(); System.exit(1); } }
From source file:at.riemers.velocity2js.velocity.Velocity2Js.java
/** * @param args the command line arguments */// ww w. ja v a 2 s . c o m public static void main(String[] args) { try { if (args.length == 0) { printUsage(); return; } if (args[0].equals("-d") && args.length >= 3) { String resource = null; if (args.length >= 4) { resource = args[3]; } List<I18NBundle> bundles = getBundles(resource); Velocity2Js.generateDir(args[1], args[2], bundles); return; } if (args[0].equals("-f") && args.length >= 4) { Properties p = new Properties(); p.setProperty("resource.loader", "file"); p.setProperty("file.resource.loader.description", "Velocity File Resource Loader"); p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); p.setProperty("file.resource.loader.path", args[1]); Velocity2Js.init(p); String function = createFunctionName(args[2]); String resource = null; if (args.length >= 5) { resource = args[4]; } List<I18NBundle> bundles = getBundles(resource); for (I18NBundle bundle : bundles) { String fname = args[3]; int e = args[3].lastIndexOf('.'); if (e <= 0 || e > args[3].length()) e = args[3].length(); fname = args[3].substring(0, e) + bundle.getLocale() + args[3].substring(e); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(fname), "UTF8")); Velocity2Js.generate(args[2], function, writer, bundle.getBundle()); writer.flush(); writer.close(); } return; } printUsage(); return; } catch (ResourceNotFoundException rnfe) { log.error("[velocity2js] : cannot find template : " + rnfe.getMessage()); } catch (ParseErrorException pee) { log.error("[velocity2js] : Syntax error in template :" + pee); } catch (Exception ex) { System.out.flush(); log.error("[velocity2js] : unknown error " + ex.getMessage()); ex.printStackTrace(System.out); System.out.println(ex.getLocalizedMessage()); System.exit(1); } }
From source file:com.kactech.otj.examples.Faucet.java
public static void main(String[] args) throws Exception { String channel = "#opentransactions" //"#kactech_test" //// w w w. j av a2s . c o m ; CommandLineParser parser = new GnuParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println("Command-line parsing error: " + e.getMessage()); help(); System.exit(-1); } if (cmd.hasOption('h')) { help(); System.exit(0); } if (cmd.hasOption('c')) channel = cmd.getOptionValue('c'); Utils.init(); client = new EClient(new File("faucet_client"), ExamplesUtils.findServer("OT 8coin") //ExamplesUtils.findServer("van") ); client.setAssetType(ExamplesUtils.findAsset("silver").assetID); client.init(); PircBotX bot = new PircBotX(); bot.setName("OTjFaucet"); bot.setLogin("fast"); bot.setVerbose(true); bot.setAutoNickChange(true); bot.setCapEnabled(true); final IrcListener listener = new IrcListener(bot, client); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { if (client == null) return; client.saveState(); try { client.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { client = null; } try { listener.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } })); bot.getListenerManager().addListener(listener); try { bot.connect("irc.freenode.net"); bot.joinChannel(channel); if (false) while (true) { Thread.sleep(1000); } //bot.quitServer("end of test"); while (bot.isConnected()) Thread.sleep(100); } catch (Exception ex) { ex.printStackTrace(); } finally { System.out.println("finally"); bot.disconnect(); client.saveState(); client.close(); client = null; } }
From source file:net.orzo.App.java
/** * *//*w ww . j ava2 s . c om*/ public static void main(final String[] args) { final App app = new App(); Logger log = null; CommandLine cmd; try { cmd = app.init(args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "orzo [options] user_script [user_arg1 [user_arg2 [...]]]\n(to generate a template: orzo -t [file path])", app.cliOptions); } else if (cmd.hasOption("v")) { System.out.printf("Orzo.js version %s\n", app.props.get("orzo.version")); } else if (cmd.hasOption("t")) { String templateSrc = new ResourceLoader().getResourceAsString("net/orzo/template1.js"); File tplFile = new File(cmd.getOptionValue("t")); FileWriter tplWriter = new FileWriter(tplFile); tplWriter.write(templateSrc); tplWriter.close(); File dtsFile = new File( String.format("%s/orzojs.d.ts", new File(tplFile.getAbsolutePath()).getParent())); FileWriter dtsWriter = new FileWriter(dtsFile); String dtsSrc = new ResourceLoader().getResourceAsString("net/orzo/orzojs.d.ts"); dtsWriter.write(dtsSrc); dtsWriter.close(); } else if (cmd.hasOption("T")) { String templateSrc = new ResourceLoader().getResourceAsString("net/orzo/template1.js"); System.out.println(templateSrc); } else { // Logger initialization if (cmd.hasOption("g")) { System.setProperty("logback.configurationFile", cmd.getOptionValue("g")); } else { System.setProperty("logback.configurationFile", "./logback.xml"); } log = LoggerFactory.getLogger(App.class); if (cmd.hasOption("s")) { // Orzo.js as a REST and AMQP service FullServiceConfig conf = new Gson().fromJson(new FileReader(cmd.getOptionValue("s")), FullServiceConfig.class); Injector injector = Guice.createInjector(new CoreModule(conf), new RestServletModule()); HttpServer httpServer = new HttpServer(conf, new JerseyGuiceServletConfig(injector)); app.services.add(httpServer); if (conf.getAmqpResponseConfig() != null) { // response AMQP service must be initialized before receiving one app.services.add(injector.getInstance(AmqpResponseConnection.class)); } if (conf.getAmqpConfig() != null) { app.services.add(injector.getInstance(AmqpConnection.class)); app.services.add(injector.getInstance(AmqpService.class)); } if (conf.getRedisConf() != null) { app.services.add(injector.getInstance(RedisStorage.class)); } Runtime.getRuntime().addShutdownHook(new ShutdownHook(app)); app.startServices(); } else if (cmd.hasOption("d")) { // Demo mode final String scriptId = "demo"; final SourceCode demoScript = SourceCode.fromResource(DEMO_SCRIPT); System.err.printf("Running demo script %s.", demoScript.getName()); CmdConfig conf = new CmdConfig(scriptId, demoScript, null, cmd.getOptionValue("p", null)); TaskManager tm = new TaskManager(conf); tm.startTaskSync(tm.registerTask(scriptId, new String[0])); } else if (cmd.getArgs().length > 0) { // Command line mode File userScriptFile = new File(cmd.getArgs()[0]); String optionalModulesPath = null; String[] inputValues; SourceCode userScript; // custom CommonJS modules path if (cmd.hasOption("m")) { optionalModulesPath = cmd.getOptionValue("m"); } if (cmd.getArgs().length > 0) { inputValues = Arrays.copyOfRange(cmd.getArgs(), 1, cmd.getArgs().length); } else { inputValues = new String[0]; } userScript = SourceCode.fromFile(userScriptFile); CmdConfig conf = new CmdConfig(userScript.getName(), userScript, optionalModulesPath, cmd.getOptionValue("p", null)); TaskManager tm = new TaskManager(conf); String taskId = tm.registerTask(userScript.getName(), inputValues); tm.startTaskSync(taskId); if (tm.getTask(taskId).getStatus() == TaskStatus.ERROR) { tm.getTask(taskId).getFirstError().getErrors().stream().forEach(System.err::println); } } else { System.err.println("Invalid parameters. Try -h for more information."); System.exit(1); } } } catch (Exception ex) { System.err.printf("Orzo.js crashed with error: %s\nSee the log for details.\n", ex.getMessage()); if (log != null) { log.error(ex.getMessage(), ex); } else { ex.printStackTrace(); } } }