List of usage examples for java.lang RuntimeException RuntimeException
public RuntimeException(Throwable cause)
From source file:de.huberlin.cuneiform.main.Main.java
public static void main(String[] args) throws ParseException, IOException, NotDerivableException, InterruptedException, JSONException { GnuParser gnuParser;//from ww w . ja v a2 s .co m CommandLine cmdline; Options opt; String value; int platform; File outputDir; String[] fileList; StringBuffer buf; String line; String dagid; File logFile; opt = new Options(); opt.addOption("p", "platform", true, "The platform to perform the Cuneiform script's interpretation. " + "Possible platforms are: 'dot', 'local', and 'debug'. Default is 'local'."); opt.addOption("d", "directory", true, "The output directory, to put the interpretation intermediate and output result as well as the default location to store the log."); opt.addOption("c", "clean", false, "If set, the execution engine ignores all cached results and starts a clean workflow run."); opt.addOption("r", "runid", true, "If set, a custom id is set for this workflow run. By default a UUID string is used."); opt.addOption("f", "file", true, "Override the default location of the log file and use the specified filename instead. If the platform is 'dot', this option sets the name of the output dot-file."); opt.addOption("h", "help", false, "Print help text."); gnuParser = new GnuParser(); cmdline = gnuParser.parse(opt, args); if (cmdline.hasOption("help")) { System.out.println("CUNEIFORM - A Functional Workflow Language\n" + LABEL_VERSION); new HelpFormatter().printHelp("java -jar cuneiform.jar [OPTION]*", opt); return; } if (cmdline.hasOption("platform")) { value = cmdline.getOptionValue("platform"); if (value.equals("dot")) platform = PLATFORM_DOT; else if (value.equals("local")) platform = PLATFORM_LOCAL; else if (value.equals("debug")) platform = PLATFORM_DEBUG; else throw new RuntimeException("Specified platform '" + value + "' not recognized."); } else platform = PLATFORM_LOCAL; if (cmdline.hasOption('d')) { value = cmdline.getOptionValue('d'); } else value = "build"; outputDir = new File(value); if (outputDir.exists()) { if (!outputDir.isDirectory()) throw new IOException( "Output directory '" + outputDir.getAbsolutePath() + "' exists but is not a directory."); else if (cmdline.hasOption('c')) { FileUtils.deleteDirectory(outputDir); if (!outputDir.mkdirs()) throw new IOException( "Could not create output directory '" + outputDir.getAbsolutePath() + "'"); } } else if (!outputDir.mkdirs()) throw new IOException("Could not create output directory '" + outputDir.getAbsolutePath() + "'"); if (cmdline.hasOption('r')) dagid = cmdline.getOptionValue('r'); else dagid = UUID.randomUUID().toString(); if (cmdline.hasOption('f')) logFile = new File(cmdline.getOptionValue('f')); else logFile = null; fileList = cmdline.getArgs(); buf = new StringBuffer(); if (fileList.length == 0) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { while ((line = reader.readLine()) != null) buf.append(line).append('\n'); } switch (platform) { case PLATFORM_DOT: createDot(buf.toString(), outputDir, logFile); break; case PLATFORM_LOCAL: runLocal(buf.toString(), outputDir, logFile, dagid); break; case PLATFORM_DEBUG: runDebug(buf.toString(), outputDir, logFile, dagid); break; default: throw new RuntimeException("Platform not recognized."); } } else switch (platform) { case PLATFORM_DOT: createDot(fileList, outputDir, logFile); break; case PLATFORM_LOCAL: runLocal(fileList, outputDir, logFile, dagid); break; case PLATFORM_DEBUG: runDebug(fileList, outputDir, logFile, dagid); break; default: throw new RuntimeException("Platform not recognized."); } }
From source file:com.act.lcms.ExtractFromNetCDFAroundMass.java
public static void main(String[] args) throws Exception { if (args.length != 4 || !args[0].endsWith(".nc")) { throw new RuntimeException( "Needs (1) NetCDF .nc file, " + "(2) mass value, e.g., 132.0772 for debugging, " + "(3) how many timepoints to process (-1 for all), " + "(4) prefix for .data and rendered .pdf, '-' for stdout"); }//from w w w. j ava 2 s.c o m String netCDF = args[0]; Double mz = Double.parseDouble(args[1]); Integer numSpectraToProcess = Integer.parseInt(args[2]); String outPrefix = args[3]; String outPDF = outPrefix.equals("-") ? null : outPrefix + ".pdf"; String outDATA = outPrefix.equals("-") ? null : outPrefix + ".data"; ExtractFromNetCDFAroundMass e = new ExtractFromNetCDFAroundMass(); List<Triple<Double, Double, Double>> window = e.get2DWindow(netCDF, mz, numSpectraToProcess); // Write data output to outfile PrintStream whereTo = outDATA == null ? System.out : new PrintStream(new FileOutputStream(outDATA)); for (Triple<Double, Double, Double> xyz : window) { whereTo.format("%.4f\t%.4f\t%.4f\n", xyz.getLeft(), xyz.getMiddle(), xyz.getRight()); whereTo.flush(); } if (outDATA != null) { // if outDATA is != null, then we have written to .data file // now render the .data to the corresponding .pdf file // first close the .data whereTo.close(); // render outDATA to outPDF using gnuplo Gnuplotter plotter = new Gnuplotter(); plotter.plot3D(outDATA, outPDF, netCDF, mz); } }
From source file:edu.ksu.cis.indus.xmlizer.JimpleXMLizerCLI.java
/** * The entry point to execute this xmlizer from command prompt. * /* www . j a v a2 s . com*/ * @param s is the command-line arguments. * @throws RuntimeException when jimple xmlization fails. * @pre s != null */ public static void main(final String[] s) { final Scene _scene = Scene.v(); final Options _options = new Options(); Option _o = new Option("d", "dump directory", true, "The directory in which to write the xml files. " + "If unspecified, the xml output will be directed standard out."); _o.setArgs(1); _o.setArgName("path"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("h", "help", false, "Display message."); _options.addOption(_o); _o = new Option("p", "soot-classpath", true, "Prepend this to soot class path."); _o.setArgs(1); _o.setArgName("classpath"); _o.setOptionalArg(false); _options.addOption(_o); final HelpFormatter _help = new HelpFormatter(); try { final CommandLine _cl = (new BasicParser()).parse(_options, s); final String[] _args = _cl.getArgs(); if (_cl.hasOption('h')) { final String _cmdLineSyn = "java " + JimpleXMLizerCLI.class.getName() + "<options> <class names>"; _help.printHelp(_cmdLineSyn.length(), _cmdLineSyn, "", _options, "", true); } else { if (_args.length > 0) { if (_cl.hasOption('p')) { _scene.setSootClassPath( _cl.getOptionValue('p') + File.pathSeparator + _scene.getSootClassPath()); } final NamedTag _tag = new NamedTag("JimpleXMLizer"); for (int _i = 0; _i < _args.length; _i++) { final SootClass _sc = _scene.loadClassAndSupport(_args[_i]); _sc.addTag(_tag); } final IProcessingFilter _filter = new TagBasedProcessingFilter(_tag.getName()); writeJimpleAsXML(new Environment(_scene), _cl.getOptionValue('d'), null, new UniqueJimpleIDGenerator(), _filter); } else { System.out.println("No classes were specified."); } } } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:edu.umass.cs.gigapaxos.PaxosServer.java
/** * @param args//from w ww . j av a 2 s .co m * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0) throw new RuntimeException( "At least one node ID must be specified as a command-line argument for starting " + PaxosServer.class.getSimpleName()); Config.register(args); if (Config.getGlobalBoolean(PC.EMULATE_DELAYS)) AbstractPacketDemultiplexer.emulateDelays(); PaxosConfig.load(); PaxosConfig.setConsoleHandler(); NodeConfig<String> nodeConfig = PaxosConfig.getDefaultNodeConfig(); PaxosConfig.sanityCheck(nodeConfig); System.out.print("Starting paxos servers [ "); for (String server : processArgs(args, nodeConfig)) { new PaxosServer(server, nodeConfig, args); System.out.print(server + " "); } System.out.println("] done"); }
From source file:org.apache.flink.benchmark.Runner.java
public static void main(String[] args) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.getConfig().enableObjectReuse(); env.getConfig().disableSysoutLogging(); ParameterTool parameters = ParameterTool.fromArgs(args); if (!(parameters.has("p") && parameters.has("types") && parameters.has("algorithms"))) { printUsage();/*from w ww .jav a 2 s . c o m*/ System.exit(-1); } int parallelism = parameters.getInt("p"); env.setParallelism(parallelism); Set<IdType> types = new HashSet<>(); if (parameters.get("types").equals("all")) { types.add(IdType.INT); types.add(IdType.LONG); types.add(IdType.STRING); } else { for (String type : parameters.get("types").split(",")) { if (type.toLowerCase().equals("int")) { types.add(IdType.INT); } else if (type.toLowerCase().equals("long")) { types.add(IdType.LONG); } else if (type.toLowerCase().equals("string")) { types.add(IdType.STRING); } else { printUsage(); throw new RuntimeException("Unknown type: " + type); } } } Queue<RunnerWithScore> queue = new PriorityQueue<>(); if (parameters.get("algorithms").equals("all")) { for (Map.Entry<String, Class> entry : AVAILABLE_ALGORITHMS.entrySet()) { for (IdType type : types) { AlgorithmRunner runner = (AlgorithmRunner) entry.getValue().newInstance(); runner.initialize(type, SAMPLES, parallelism); runner.warmup(env); queue.add(new RunnerWithScore(runner, 1.0)); } } } else { for (String algorithm : parameters.get("algorithms").split(",")) { double ratio = 1.0; if (algorithm.contains("=")) { String[] split = algorithm.split("="); algorithm = split[0]; ratio = Double.parseDouble(split[1]); } if (AVAILABLE_ALGORITHMS.containsKey(algorithm.toLowerCase())) { Class clazz = AVAILABLE_ALGORITHMS.get(algorithm.toLowerCase()); for (IdType type : types) { AlgorithmRunner runner = (AlgorithmRunner) clazz.newInstance(); runner.initialize(type, SAMPLES, parallelism); runner.warmup(env); queue.add(new RunnerWithScore(runner, ratio)); } } else { printUsage(); throw new RuntimeException("Unknown algorithm: " + algorithm); } } } JsonFactory factory = new JsonFactory(); while (queue.size() > 0) { RunnerWithScore current = queue.poll(); AlgorithmRunner runner = current.getRunner(); StringWriter writer = new StringWriter(); JsonGenerator gen = factory.createGenerator(writer); gen.writeStartObject(); gen.writeStringField("algorithm", runner.getClass().getSimpleName()); boolean running = true; while (running) { try { runner.run(env, gen); running = false; } catch (ProgramInvocationException e) { // only suppress job cancellations if (!(e.getCause() instanceof JobCancellationException)) { throw e; } } } JobExecutionResult result = env.getLastJobExecutionResult(); long runtime_ms = result.getNetRuntime(); gen.writeNumberField("runtime_ms", runtime_ms); current.credit(runtime_ms); if (!runner.finished()) { queue.add(current); } gen.writeObjectFieldStart("accumulators"); for (Map.Entry<String, Object> accumulatorResult : result.getAllAccumulatorResults().entrySet()) { gen.writeStringField(accumulatorResult.getKey(), accumulatorResult.getValue().toString()); } gen.writeEndObject(); gen.writeEndObject(); gen.close(); System.out.println(writer.toString()); } }
From source file:dataflow.examples.TransferFiles.java
public static void main(String[] args) throws IOException, URISyntaxException { Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class); List<FilePair> filePairs = new ArrayList<FilePair>(); URI ftpInput = new URI(options.getInput()); FTPClient ftp = new FTPClient(); ftp.connect(ftpInput.getHost());//ww w . ja v a 2 s . c o m // After connection attempt, you should check the reply code to verify // success. int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); logger.error("FTP server refused connection."); throw new RuntimeException("FTP server refused connection."); } ftp.login("anonymous", "someemail@gmail.com"); String ftpPath = ftpInput.getPath(); FTPFile[] files = ftp.listFiles(ftpPath); URI gcsUri = null; if (options.getOutput().endsWith("/")) { gcsUri = new URI(options.getOutput()); } else { gcsUri = new URI(options.getOutput() + "/"); } for (FTPFile f : files) { logger.info("File: " + f.getName()); FilePair p = new FilePair(); p.server = ftpInput.getHost(); p.ftpPath = f.getName(); // URI ftpURI = new URI("ftp", p.server, f.getName(), ""); p.gcsPath = gcsUri.resolve(FilenameUtils.getName(f.getName())).toString(); filePairs.add(p); } ftp.logout(); Pipeline p = Pipeline.create(options); PCollection<FilePair> inputs = p.apply(Create.of(filePairs)); inputs.apply(ParDo.of(new FTPToGCS()).named("CopyToGCS")) .apply(AvroIO.Write.withSchema(FilePair.class).to(options.getOutput())); p.run(); }
From source file:dr.math.distributions.ReflectedNormalDistribution.java
public static void main(String[] args) { // final ReflectedNormalDistribution rnd = new ReflectedNormalDistribution(2, 2, 0.5, 2, 1e-6); final ReflectedNormalDistribution rnd = new ReflectedNormalDistribution(2, 2, 1, 2, 1e-6); rnd.pdf(1);//w w w.j a va 2 s . co m UnivariateRealFunction f = new UnivariateRealFunction() { public double value(double v) throws FunctionEvaluationException { return rnd.pdf(v); } }; final UnivariateRealIntegrator integrator = new RombergIntegrator(); integrator.setAbsoluteAccuracy(1e-14); integrator.setMaximalIterationCount(16); // fail if it takes too much time double x; try { x = integrator.integrate(f, rnd.lower, rnd.upper); // ptotErr += cdf != 0.0 ? Math.abs(x-cdf)/cdf : x; // np += 1; //assertTrue("" + shape + "," + scale + "," + value + " " + Math.abs(x-cdf)/x + "> 1e-6", Math.abs(1-cdf/x) < 1e-6); System.out.println("Integrated pdf = " + x); //System.out.println(shape + "," + scale + " " + value); } catch (ConvergenceException e) { // can't integrate , skip test // System.out.println(shape + "," + scale + " skipped"); } catch (FunctionEvaluationException e) { throw new RuntimeException("I have no idea why I am here."); } }
From source file:com.tresys.jalop.utils.jnltest.JNLTest.java
/** * Main entry point for the JNLTest program. This takes a single argument, * the full path to a configuration file to use. * * @param args/*w ww.ja va 2 s . c o m*/ * The command line arguments * @throws BEEPException * @throws JNLException */ public static void main(final String[] args) throws JNLException, BEEPException { if (args.length != 1) { System.err.println("Must specify exactly one argument that is " + " the configuration file to use"); System.exit(1); } Config config; try { config = Config.parse(args[0]); } catch (final IOException e) { System.err.println("Caught IO exception: " + e.getMessage()); System.exit(1); throw new RuntimeException("Failed to call exit()"); } catch (final ParseException e) { System.err.print(e.toString()); System.exit(1); throw new RuntimeException("Failed to call exit()"); } catch (final ConfigurationException e) { System.err.println("Exception processing the config file: " + e.getMessage()); System.exit(1); throw new RuntimeException("Failed to call exit()"); } final JNLTest jt = new JNLTest(config); System.out.println("Started Connections"); jt.start(); }
From source file:io.s4.util.AvroSchemaSupplementer.java
public static void main(String args[]) { if (args.length < 1) { System.err.println("No schema filename specified"); System.exit(1);//w w w. ja va 2 s.co m } String filename = args[0]; FileReader fr = null; BufferedReader br = null; InputStreamReader isr = null; try { if (filename == "-") { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); } else { fr = new FileReader(filename); br = new BufferedReader(fr); } String inputLine = ""; StringBuffer jsonBuffer = new StringBuffer(); while ((inputLine = br.readLine()) != null) { jsonBuffer.append(inputLine); } JSONObject jsonRecord = new JSONObject(jsonBuffer.toString()); JSONObject keyPathElementSchema = new JSONObject(); keyPathElementSchema.put("name", "KeyPathElement"); keyPathElementSchema.put("type", "record"); JSONArray fieldsArray = new JSONArray(); JSONObject fieldRecord = new JSONObject(); fieldRecord.put("name", "index"); JSONArray typeArray = new JSONArray("[\"int\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyName"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); keyPathElementSchema.put("fields", fieldsArray); JSONObject keyInfoSchema = new JSONObject(); keyInfoSchema.put("name", "KeyInfo"); keyInfoSchema.put("type", "record"); fieldsArray = new JSONArray(); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyPath"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "fullKeyPath"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyPathElementList"); JSONObject typeRecord = new JSONObject(); typeRecord.put("type", "array"); typeRecord.put("items", keyPathElementSchema); fieldRecord.put("type", typeRecord); fieldsArray.put(fieldRecord); keyInfoSchema.put("fields", fieldsArray); JSONObject partitionInfoSchema = new JSONObject(); partitionInfoSchema.put("name", "PartitionInfo"); partitionInfoSchema.put("type", "record"); fieldsArray = new JSONArray(); fieldRecord = new JSONObject(); fieldRecord.put("name", "partitionId"); typeArray = new JSONArray("[\"int\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "compoundKey"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "compoundValue"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyInfoList"); typeRecord = new JSONObject(); typeRecord.put("type", "array"); typeRecord.put("items", keyInfoSchema); fieldRecord.put("type", typeRecord); fieldsArray.put(fieldRecord); partitionInfoSchema.put("fields", fieldsArray); fieldRecord = new JSONObject(); fieldRecord.put("name", "S4__PartitionInfo"); typeRecord = new JSONObject(); typeRecord.put("type", "array"); typeRecord.put("items", partitionInfoSchema); fieldRecord.put("type", typeRecord); fieldsArray = jsonRecord.getJSONArray("fields"); fieldsArray.put(fieldRecord); System.out.println(jsonRecord.toString(3)); } catch (Exception ioe) { throw new RuntimeException(ioe); } finally { if (br != null) try { br.close(); } catch (Exception e) { } if (isr != null) try { isr.close(); } catch (Exception e) { } if (fr != null) try { fr.close(); } catch (Exception e) { } } }
From source file:se.symsoft.codecamp.SmsTerminatorService.java
public static void main(String[] args) throws IOException, InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(1); SmsTerminatorService service = new SmsTerminatorService(); executor.execute(() -> {/*from w w w .j ava2 s. c om*/ try { service.start(); } catch (IOException e) { throw new RuntimeException(e); } }); }