List of usage examples for java.lang NumberFormatException printStackTrace
public void printStackTrace()
From source file:IndexService.IndexServer_Old.java
public static void main(String[] args) throws IOException, HiveException { IndexServer_Old server = new IndexServer_Old(); server.start();// w w w. j a v a2 s. c o m BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; while (true) { try { str = br.readLine(); String[] strs = str.split(" "); if (strs[0].equals("setindexstatus")) { Path indexpath = new Path(strs[1]); server.db.setIndexStatus(indexpath.getParent().getParent().getName(), indexpath.getParent().getName(), indexpath.getName(), Integer.valueOf(strs[2])); } else if (str.equals("exit")) { server.close(); System.exit(0); break; } } catch (NumberFormatException e) { e.printStackTrace(); } catch (HiveException e) { e.printStackTrace(); } } }
From source file:com.zimbra.cs.mailbox.util.MetadataDump.java
public static void main(String[] args) { try {//from w ww. j a va 2 s . c om CliUtil.toolSetup("WARN"); int mboxId = 0; int itemId = 0; PrintStream out = new PrintStream(System.out, true, "utf-8"); CommandLine cl = parseArgs(args); if (cl.hasOption(OPT_HELP)) { usage(null); System.exit(0); } // Get data from file. String infileName = cl.getOptionValue(OPT_FILE); if (infileName != null) { File file = new File(infileName); if (file.exists()) { String encoded = loadFromFile(file); Metadata md = new Metadata(encoded); String pretty = md.prettyPrint(); out.println(pretty); return; } else { System.err.println("File " + infileName + " does not exist"); System.exit(1); } } // Get data from input String. String encoded = cl.getOptionValue(OPT_STR); if (!StringUtil.isNullOrEmpty(encoded)) { Metadata md = new Metadata(encoded); String pretty = md.prettyPrint(); out.println(pretty); return; } // Get data from db. DbPool.startup(); DbConnection conn = null; try { boolean fromDumpster = cl.hasOption(OPT_DUMPSTER); String mboxIdStr = cl.getOptionValue(OPT_MAILBOX_ID); String itemIdStr = cl.getOptionValue(OPT_ITEM_ID); if (mboxIdStr == null || itemIdStr == null) { usage(null); System.exit(1); return; } if (mboxIdStr.matches("\\d+")) { try { mboxId = Integer.parseInt(mboxIdStr); } catch (NumberFormatException e) { System.err.println("Invalid mailbox id " + mboxIdStr); System.exit(1); } } else { conn = DbPool.getConnection(); mboxId = lookupMailboxIdFromEmail(conn, mboxIdStr); } try { itemId = Integer.parseInt(itemIdStr); } catch (NumberFormatException e) { usage(null); System.exit(1); } if (conn == null) conn = DbPool.getConnection(); doDump(conn, mboxId, itemId, fromDumpster, out); } finally { DbPool.quietClose(conn); } } catch (Exception e) { System.err.println(e.getMessage()); System.err.println(); System.err.println(); e.printStackTrace(); System.exit(1); } }
From source file:org.jbpm.xes.XESExportMain.java
public static void main(String[] args) { // create the Options Options options = getOptions();/*w ww.j a v a2s . c o m*/ CommandLineParser parser = new DefaultParser(); try (BasicDataSource ds = new BasicDataSource()) { // parse the command line arguments CommandLine line = parser.parse(options, args); ds.setDriverClassName(line.getOptionValue("driver")); ds.setUrl(line.getOptionValue("url")); ds.setUsername(line.getOptionValue("user")); ds.setPassword(line.getOptionValue("password")); ds.setDefaultReadOnly(true); // Test connection ds.getConnection().close(); DataSetService dataSetService = new DataSetServiceImpl(() -> ds); XESExportServiceImpl service = new XESExportServiceImpl(); service.setDataSetService(dataSetService); final XESProcessFilter.Builder filter = XESProcessFilter.builder(); filter.withProcessId(line.getOptionValue("process")); if (line.hasOption("version")) { filter.withProcessVersion(line.getOptionValue("version")); } if (line.hasOption("status")) { List<Integer> status = new ArrayList<>(); for (String statusLine : line.getOptionValues("status")) { try { final Integer pStatus = Integer.valueOf(statusLine); //only add valid status if (pStatus >= 0 && pStatus <= 4) { status.add(pStatus); } } catch (NumberFormatException ex) { System.err.println("Invalid process status number for input: " + statusLine + ", valid status are number between 0 and 4."); } } if (status.isEmpty() == false) { filter.withStatus(status); } } if (line.hasOption("logtype")) { filter.withNodeInstanceLogType(Integer.valueOf(line.getOptionValue("logtype"))); } if (line.hasOption("nodetypes")) { filter.withAllNodeTypes(); } final String xml = service.export(filter.build()); if (line.hasOption("file")) { FileUtils.write(new File(line.getOptionValue("file")), xml, "UTF-8"); } else { System.out.println(xml); } } catch (ParseException exp) { System.err.println("Parsing options failed. Reason: " + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("xes", options, true); System.exit(-1); } catch (Exception ex) { System.err.println("Failed to execute export due to: " + ex.getMessage()); ex.printStackTrace(); System.exit(-1); } }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.BuildInMemFwdIndexApp.java
public static void main(String[] args) { Options options = new Options(); options.addOption(CommonParams.ROOT_DIR_PARAM, null, true, CommonParams.ROOT_DIR_DESC); options.addOption(CommonParams.SUB_DIR_TYPE_PARAM, null, true, CommonParams.SUB_DIR_TYPE_DESC); options.addOption(CommonParams.MAX_NUM_REC_PARAM, null, true, CommonParams.MAX_NUM_REC_DESC); options.addOption(CommonParams.SOLR_FILE_NAME_PARAM, null, true, CommonParams.SOLR_FILE_NAME_DESC); options.addOption(CommonParams.OUT_INDEX_PARAM, null, true, CommonParams.OUT_MINDEX_DESC); options.addOption(EXCLUDE_FIELDS_PARAM, null, true, EXCLUDE_FIELDS_DESC); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {/* ww w . j av a 2 s .com*/ CommandLine cmd = parser.parse(options, args); String rootDir = null; rootDir = cmd.getOptionValue(CommonParams.ROOT_DIR_PARAM); if (null == rootDir) Usage("Specify: " + CommonParams.ROOT_DIR_DESC, options); String outPrefix = cmd.getOptionValue(CommonParams.OUT_INDEX_PARAM); if (null == outPrefix) Usage("Specify: " + CommonParams.OUT_MINDEX_DESC, options); String subDirTypeList = cmd.getOptionValue(CommonParams.SUB_DIR_TYPE_PARAM); if (null == subDirTypeList || subDirTypeList.isEmpty()) Usage("Specify: " + CommonParams.SUB_DIR_TYPE_DESC, options); String solrFileName = cmd.getOptionValue(CommonParams.SOLR_FILE_NAME_PARAM); if (null == solrFileName) Usage("Specify: " + CommonParams.SOLR_FILE_NAME_DESC, options); int maxNumRec = Integer.MAX_VALUE; String tmp = cmd.getOptionValue(CommonParams.MAX_NUM_REC_PARAM); if (tmp != null) { try { maxNumRec = Integer.parseInt(tmp); if (maxNumRec <= 0) { Usage("The maximum number of records should be a positive integer", options); } } catch (NumberFormatException e) { Usage("The maximum number of records should be a positive integer", options); } } String[] exclFields = new String[0]; tmp = cmd.getOptionValue(EXCLUDE_FIELDS_PARAM); if (null != tmp) { exclFields = tmp.split(","); } String[] subDirs = subDirTypeList.split(","); for (int k = 0; k < FeatureExtractor.mFieldNames.length; ++k) { String field = FeatureExtractor.mFieldsSOLR[k]; String fieldName = FeatureExtractor.mFieldNames[k]; boolean bOk = !StringUtilsLeo.isInArrayNoCase(fieldName, exclFields); if (bOk) System.out.println("Processing field: " + field); else { System.out.println("Skipping field: " + field); continue; } String[] fileNames = new String[subDirs.length]; for (int i = 0; i < fileNames.length; ++i) fileNames[i] = rootDir + "/" + subDirs[i] + "/" + solrFileName; InMemForwardIndex indx = new InMemForwardIndex(field, fileNames, maxNumRec); indx.save(InMemIndexFeatureExtractor.indexFileName(outPrefix, fieldName)); } } catch (ParseException e) { Usage("Cannot parse arguments", options); } catch (Exception e) { e.printStackTrace(); System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:nl.mpi.tla.lat2fox.Main.java
public static void main(String[] args) { File rfile = null;/*from w ww . j av a 2 s . c o m*/ String dir = "."; String fdir = null; String idir = null; String bdir = null; String xdir = null; String pdir = null; String mdir = null; String cext = "cmdi"; String cfile = null; String dfile = null; String mfile = null; String oxp = null; String axp = null; String server = null; XdmNode collsDoc = null; boolean validateFOX = false; boolean laxResourceCheck = false; boolean createCMDObject = true; boolean relationCheck = true; int ndir = 0; // check command line OptionParser parser = new OptionParser("zhlve:r:f:i:x:p:q:n:c:d:m:o:a:s:b:?*"); OptionSet options = parser.parse(args); if (options.has("l")) laxResourceCheck = true; if (options.has("v")) validateFOX = true; if (options.has("h")) createCMDObject = false; if (options.has("z")) relationCheck = false; if (options.has("e")) cext = (String) options.valueOf("e"); if (options.has("r")) rfile = new File((String) options.valueOf("r")); if (options.has("f")) fdir = (String) options.valueOf("f"); if (options.has("i")) idir = (String) options.valueOf("i"); if (options.has("x")) xdir = (String) options.valueOf("x"); if (options.has("p")) pdir = (String) options.valueOf("p"); if (options.has("q")) mdir = (String) options.valueOf("q"); if (options.has("b")) bdir = (String) options.valueOf("b"); if (options.has("c")) { cfile = (String) options.valueOf("c"); File c = new File(cfile); if (!c.isFile()) { System.err.println("FTL: -c expects a <FILE> argument!"); showHelp(); System.exit(1); } if (!c.canRead()) { System.err.println("FTL: -c <FILE> argument isn't readable!"); showHelp(); System.exit(1); } try { collsDoc = SaxonUtils.buildDocument(new StreamSource(cfile)); } catch (Exception ex) { System.err.println("FTL: can't read collection <FILE>[" + cfile + "]: " + ex); ex.printStackTrace(System.err); } } if (options.has("d")) { dfile = (String) options.valueOf("d"); File d = new File(dfile); if (!d.isFile()) { System.err.println("FTL: -d expects a <FILE> argument!"); showHelp(); System.exit(1); } if (!d.canRead()) { System.err.println("FTL: -d <FILE> argument isn't readable!"); showHelp(); System.exit(1); } } if (options.has("m")) { mfile = (String) options.valueOf("m"); File m = new File(mfile); if (!m.isFile()) { System.err.println("FTL: -m expects a <FILE> argument!"); showHelp(); System.exit(1); } if (!m.canRead()) { System.err.println("FTL: -m <FILE> argument isn't readable!"); showHelp(); System.exit(1); } } if (options.has("n")) { try { ndir = Integer.parseInt((String) options.valueOf("n")); } catch (NumberFormatException e) { System.err.println("FTL: -n expects a numeric argument!"); showHelp(); System.exit(1); } } if (options.has("o")) { oxp = (String) options.valueOf("o"); } if (options.has("a")) { axp = (String) options.valueOf("a"); } if (options.has("s")) { server = (String) options.valueOf("s"); } if (options.has("?")) { showHelp(); System.exit(0); } List arg = options.nonOptionArguments(); if (arg.size() > 1) { System.err.println("FTL: only one source <DIR> argument is allowed!"); showHelp(); System.exit(1); } if (arg.size() == 1) dir = (String) arg.get(0); try { SaxonExtensionFunctions.registerAll(SaxonUtils.getProcessor().getUnderlyingConfiguration()); } catch (Exception e) { System.err.println("ERR: couldn't register the Saxon extension functions: " + e); e.printStackTrace(); } try { if (fdir == null) fdir = dir + "/fox"; if (xdir == null) xdir = dir + "/fox-error"; if (pdir == null) pdir = dir + "/policies"; if (mdir == null) mdir = dir + "/management"; XdmNode relsDoc = null; if (rfile != null && rfile.exists()) { relsDoc = SaxonUtils.buildDocument(new StreamSource(rfile)); System.err.println("DBG: loaded[" + rfile.getAbsolutePath() + "]"); } else { // create lookup document for relations XsltTransformer rels = SaxonUtils.buildTransformer(Main.class.getResource("/cmd2rels.xsl")).load(); rels.setParameter(new QName("ext"), new XdmAtomicValue(cext)); rels.setParameter(new QName("dir"), new XdmAtomicValue("file:" + dir)); rels.setSource(new StreamSource(Main.class.getResource("/null.xml").toString())); XdmDestination dest = new XdmDestination(); rels.setDestination(dest); rels.transform(); relsDoc = dest.getXdmNode(); if (rfile != null) { TransformerFactory.newInstance().newTransformer().transform(relsDoc.asSource(), new StreamResult(rfile)); System.err.println("DBG: saved[" + rfile.getAbsolutePath() + "]"); } } if (relationCheck) { // Check the relations XsltTransformer rcheck = SaxonUtils.buildTransformer(Main.class.getResource("/checkRels.xsl")) .load(); rcheck.setParameter(new QName("rels-doc"), relsDoc); rcheck.setSource(new StreamSource(Main.class.getResource("/null.xml").toString())); XdmDestination dest = new XdmDestination(); rcheck.setDestination(dest); rcheck.transform(); } //System.exit(0); // CMDI 2 FOX // create the fox dirs FileUtils.forceMkdir(new File(fdir)); FileUtils.forceMkdir(new File(xdir)); Collection<File> inputs = FileUtils.listFiles(new File(dir), new String[] { cext }, true); // if there is a CMD 2 DC or 2 other XSLT include it XsltExecutable cmd2fox = null; if (dfile != null || mfile != null) { XsltTransformer inclCMD2DC = SaxonUtils .buildTransformer(Main.class.getResource("/inclCMD2DCother.xsl")).load(); inclCMD2DC.setSource(new StreamSource(Main.class.getResource("/cmd2fox.xsl").toString())); if (dfile != null) inclCMD2DC.setParameter(new QName("cmd2dc"), new XdmAtomicValue("file://" + (new File(dfile)).getAbsolutePath())); if (mfile != null) inclCMD2DC.setParameter(new QName("cmd2other"), new XdmAtomicValue("file://" + (new File(mfile)).getAbsolutePath())); XdmDestination destination = new XdmDestination(); inclCMD2DC.setDestination(destination); inclCMD2DC.transform(); cmd2fox = SaxonUtils.buildTransformer(destination.getXdmNode()); } else cmd2fox = SaxonUtils.buildTransformer(Main.class.getResource("/cmd2fox.xsl")); int err = 0; int i = 0; int s = inputs.size(); for (File input : inputs) { i++; if (!input.isHidden() && !input.getAbsolutePath().matches(".*/(corpman|sessions)/.*")) { try { XsltTransformer fox = cmd2fox.load(); //fox.setParameter(new QName("rels-uri"), new XdmAtomicValue("file:"+map.getAbsolutePath())); fox.setParameter(new QName("rels-doc"), relsDoc); fox.setParameter(new QName("conversion-base"), new XdmAtomicValue(dir)); if (idir != null) fox.setParameter(new QName("import-base"), new XdmAtomicValue(idir)); fox.setParameter(new QName("fox-base"), new XdmAtomicValue(fdir)); fox.setParameter(new QName("lax-resource-check"), new XdmAtomicValue(laxResourceCheck)); if (collsDoc != null) fox.setParameter(new QName("collections-map"), collsDoc); if (server != null) fox.setParameter(new QName("repository"), new XdmAtomicValue(server)); if (oxp != null) fox.setParameter(new QName("oai-include-eval"), new XdmAtomicValue(oxp)); if (axp != null) { fox.setParameter(new QName("always-collection-eval"), new XdmAtomicValue(axp)); fox.setParameter(new QName("always-compound-eval"), new XdmAtomicValue(axp)); } if (bdir != null) fox.setParameter(new QName("icon-base"), new XdmAtomicValue(bdir)); if (pdir != null) fox.setParameter(new QName("policies-dir"), new XdmAtomicValue(pdir)); if (mdir != null) fox.setParameter(new QName("management-dir"), new XdmAtomicValue(mdir)); fox.setParameter(new QName("create-cmd-object"), new XdmAtomicValue(createCMDObject)); fox.setSource(new StreamSource(input)); XdmDestination destination = new XdmDestination(); fox.setDestination(destination); fox.transform(); String fid = SaxonUtils.evaluateXPath(destination.getXdmNode(), "/*/@PID").evaluateSingle() .getStringValue(); File out = new File(fdir + "/" + fid.replaceAll("[^a-zA-Z0-9]", "_") + "_CMD.xml"); if (out.exists()) { System.err.println( "ERR:" + i + "/" + s + ": FOX[" + out.getAbsolutePath() + "] already exists!"); out = new File(xdir + "/lat-error-" + (++err) + ".xml"); System.err.println("WRN:" + i + "/" + s + ": saved to FOX[" + out.getAbsolutePath() + "] instead!"); } TransformerFactory.newInstance().newTransformer() .transform(destination.getXdmNode().asSource(), new StreamResult(out)); System.err.println("DBG:" + i + "/" + s + ": created[" + out.getAbsolutePath() + "]"); } catch (Exception e) { System.err.println("ERR:" + i + "/" + s + ": " + e); System.err .println("WRN:" + i + "/" + s + ": skipping file[" + input.getAbsolutePath() + "]"); } } } if (ndir > 0) { int n = 0; int d = 0; inputs = FileUtils.listFiles(new File(fdir), new String[] { "xml" }, true); i = 0; s = inputs.size(); for (File input : inputs) { i++; if (n == ndir) n = 0; n++; FileUtils.moveFileToDirectory(input, new File(fdir + "/" + (n == 1 ? ++d : d)), true); if (n == 1) System.err.println("DBG:" + i + "/" + s + ": moved to dir[" + fdir + "/" + d + "]"); } } if (validateFOX) { SchemAnon tron = new SchemAnon(Main.class.getResource("/foxml1-1.xsd"), "ingest"); inputs = FileUtils.listFiles(new File(fdir), new String[] { "xml" }, true); i = 0; s = inputs.size(); for (File input : inputs) { i++; // validate FOX if (!tron.validate(input)) { System.err .println("ERR:" + i + "/" + s + ": invalid file[" + input.getAbsolutePath() + "]"); for (Message msg : tron.getMessages()) { System.out.println("" + (msg.isError() ? "ERR: " : "WRN: ") + i + "/" + s + ": " + (msg.getLocation() != null ? "at " + msg.getLocation() : "")); System.out.println( "" + (msg.isError() ? "ERR: " : "WRN: ") + i + "/" + s + ": " + msg.getText()); } } else System.err.println("DBG:" + i + "/" + s + ": valid file[" + input.getAbsolutePath() + "]"); } } } catch (Exception ex) { System.err.println("FTL: " + ex); ex.printStackTrace(System.err); } }
From source file:Bounce.java
/** * The main method./*from w ww .j a v a 2 s. c o m*/ */ public static void main(String[] args) { if (args.length < 3) { printUsage(); System.exit(1); } int localPort; try { localPort = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("Bad local port value: " + args[0]); printUsage(); System.exit(2); return; } String hostname = args[1]; int remotePort; try { remotePort = Integer.parseInt(args[2]); } catch (NumberFormatException e) { System.err.println("Bad remote port value: " + args[2]); printUsage(); System.exit(3); return; } boolean shouldLog = args.length > 3 ? Boolean.valueOf(args[3]).booleanValue() : false; int numConnections = 0; try { ServerSocket ssock = new ServerSocket(localPort); while (true) { Socket incomingSock = ssock.accept(); Socket outgoingSock = new Socket(hostname, remotePort); numConnections++; InputStream incomingIn = incomingSock.getInputStream(); InputStream outgoingIn = outgoingSock.getInputStream(); OutputStream incomingOut = incomingSock.getOutputStream(); OutputStream outgoingOut = outgoingSock.getOutputStream(); if (shouldLog) { String incomingLogName = "in-log-" + incomingSock.getInetAddress().getHostName() + "(" + localPort + ")-" + numConnections + ".dat"; String outgoingLogName = "out-log-" + hostname + "(" + remotePort + ")-" + numConnections + ".dat"; OutputStream incomingLog = new FileOutputStream(incomingLogName); incomingOut = new MultiOutputStream(incomingOut, incomingLog); OutputStream outgoingLog = new FileOutputStream(outgoingLogName); outgoingOut = new MultiOutputStream(outgoingOut, outgoingLog); } PumpThread t1 = new PumpThread(incomingIn, outgoingOut); PumpThread t2 = new PumpThread(outgoingIn, incomingOut); t1.start(); t2.start(); } } catch (IOException e) { e.printStackTrace(); System.exit(3); } }
From source file:dashboard.ImportCDN.java
public static void main(String[] args) { int n = 0;// w w w . j a v a2s . c o m String propertiesFileName = ""; // First argument - number of events to import if (args.length > 0) { try { n = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("First argument must be an integer"); System.exit(1); } } else { System.err.println("Please specify number of events to import."); System.exit(1); } // Second argument - properties file name if (args.length > 1) propertiesFileName = args[1]; else propertiesFileName = "gigaDashboard.properties"; // Read Properties file Properties prop = new Properties(); try { //load a properties file prop.load(new FileInputStream(propertiesFileName)); // Another option - load default properties from the Jar //prop.load(ImportCDN.class.getResourceAsStream("/gigaDashboard.properties")); //get the property values TOKEN = prop.getProperty("MIXPANEL_GIGA_PROJECT_TOKEN"); API_KEY = prop.getProperty("MIXPANEL_GIGA_API_KEY"); bucketName = prop.getProperty("S3_BUCKET_NAME"); AWS_USER = prop.getProperty("AWS_USER"); AWS_PASS = prop.getProperty("AWS_PASS"); DELETE_PROCESSED_LOGS = prop.getProperty("DELETE_PROCESSED_LOGS"); //System.out.println("MIXPANEL PROJECT TOKEN = " + TOKEN); //System.out.println("MIXPANEL API KEY = " + API_KEY); System.out.println("DELETE_PROCESSED_LOGS = " + DELETE_PROCESSED_LOGS); System.out.println("S3_BUCKET_NAME = " + prop.getProperty("S3_BUCKET_NAME")); //System.out.println("AWS_USER = " + prop.getProperty("AWS_USER")); //System.out.println("AWS_PASS = " + prop.getProperty("AWS_PASS")); System.out.println("==================="); } catch (IOException ex) { //ex.printStackTrace(); System.err.println("Can't find Propertie file - " + propertiesFileName); System.err.println("Second argument must be properties file name"); System.exit(1); } try { System.out.println("\n>>> Starting to import " + n + " events... \n"); readAmazonLogs(n); } catch (Exception e) { e.printStackTrace(); } }
From source file:SDRecord.java
public static void main(String[] args) { boolean recordToInf = false; long recordTo = 0, txsize = 0, wr = 0, max = 0; int sourcePort = 0, destPort = 0; String val; OutputStream writer = null;//from w w w . ja v a2s .c o m InetAddress rhost = null, lhost = null; DatagramSocket socket = null; //Default values int buffSize = 1500; try { lhost = InetAddress.getByName("0.0.0.0"); } catch (UnknownHostException e1) { System.err.println("ERROR!: Host not reconized"); System.exit(3); } recordToInf = true; sourcePort = 7355; Options options = new Options(); options.addOption("m", true, "Minutes to record, default is no limit"); options.addOption("l", true, "Bind to a specific local address, default is 0.0.0.0"); options.addOption("p", true, "Local port to use, default is 7355"); options.addOption("r", true, "Remote address where to send data"); options.addOption("d", true, "Remote port, to use with -r option"); options.addOption("f", true, "Output file where to save the recording"); options.addOption("s", true, "Stop recording when reaching specified MBs"); options.addOption("h", false, "Help"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e1) { System.err.println("ERROR!: Error while parsing the command line"); System.exit(1); } if (cmd.hasOption("m")) { val = cmd.getOptionValue("m"); try { if (Long.parseLong(val) < 0) { System.err.println("ERROR!: -m argument value cannot be negative"); System.exit(3); } recordTo = System.currentTimeMillis() + (Long.parseLong(val) * 60000); recordToInf = false; } catch (NumberFormatException e) { System.err.println("ERROR!: -m argument not an integer"); System.exit(3); } } if (cmd.hasOption("l")) { val = cmd.getOptionValue("l"); try { lhost = InetAddress.getByName(val); } catch (UnknownHostException e) { System.err.println("ERROR!: Host not reconized"); System.exit(3); } } if (cmd.hasOption("p")) { val = cmd.getOptionValue("p"); try { sourcePort = Integer.parseInt(val); } catch (NumberFormatException e) { System.err.println("ERROR!: -p argument not an integer"); System.exit(3); } } if (cmd.hasOption("r")) { val = cmd.getOptionValue("r"); try { rhost = InetAddress.getByName(val); } catch (UnknownHostException e) { System.err.println("ERROR!: Host not reconized"); System.exit(3); } } if (cmd.hasOption("d")) { val = cmd.getOptionValue("d"); try { destPort = Integer.parseInt(val); } catch (NumberFormatException e) { System.err.println("-ERROR!: -d argument not an integer"); System.exit(3); } } if (cmd.hasOption("f")) { val = cmd.getOptionValue("f"); try { writer = new FileOutputStream(val); } catch (FileNotFoundException e) { System.err.println("ERROR!: File not found"); System.exit(3); } } if (cmd.hasOption("s")) { val = cmd.getOptionValue("s"); try { max = (long) (Double.parseDouble(val) * 1000000); } catch (NumberFormatException e) { System.err.println("ERROR!: -s argument not valid"); System.exit(3); } if (Double.parseDouble(val) < 0) { System.err.println("ERROR!: -s argument value cannot be negative"); System.exit(3); } } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SDRecord", options); System.exit(0); } try { socket = new DatagramSocket(sourcePort, lhost); //socket options socket.setReuseAddress(true); } catch (SocketException e) { e.printStackTrace(); System.exit(3); } byte[] buffer = new byte[buffSize]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); System.err.println("Listening " + lhost.toString() + " on port " + sourcePort); while (recordToInf == true || System.currentTimeMillis() <= recordTo) { //Stop recording when reaching max bytes if (max != 0 && txsize >= max) break; packet.setData(buffer); try { socket.receive(packet); } catch (IOException e) { e.printStackTrace(); System.exit(4); } //Ignoring packets with no data if (basicFilter(packet) == null) continue; if (writer == null && rhost == null) wr = recordToStdout(packet); if (writer != null) wr = recordToFile(packet, writer); if (rhost != null) wr = recordToSocket(packet, socket, rhost, destPort); txsize += wr; System.err .print("\r" + formatSize(txsize) + " transferred" + "\033[K" + "\t Press Ctrl+c to terminate"); } //closing socket and exit System.err.print("\r" + formatSize(txsize) + " transferred" + "\033[K"); socket.close(); System.out.println(); System.exit(0); }
From source file:fresto.datastore.titan.TitanEventWriter.java
public static void main(String[] args) throws Exception { if (args.length < 4) { LOGGER.error(/*from w w w . j av a2 s. com*/ "Argumests needed : <streamer url> <storage backend> <storage hostname> <max commit count>"); System.exit(1); } else { STREAMER_URL = args[0]; STORAGE_BACKEND = args[1]; STORAGE_HOSTNAME = args[2]; try { MAX_COMMIT_COUNT = Integer.parseInt(args[3]); } catch (NumberFormatException e) { LOGGER.error("Commit count should be an integer"); } } final ZMQ.Context context = ZMQ.context(1); final FrestoEventQueue frestoEventQueue = new FrestoEventQueue(); final Thread queueMonitorThread = new Thread() { //Logger _LOGGER = Logger.getLogger("writerThread"); @Override public void run() { while (work) { try { LOGGER.info("frestoEventQueue size = " + frestoEventQueue.size()); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }; final Thread writerThread = new Thread() { //Logger _LOGGER = Logger.getLogger("writerThread"); @Override public void run() { //StopWatch _watch = new JavaLogStopWatch(_LOGGER); FrestoStopWatch _watch = new FrestoStopWatch(); FrestoStopWatch _durationWatch = new FrestoStopWatch(); TitanEventWriter eventWriter = new TitanEventWriter(); // Open database eventWriter.openTitanGraph(); ZMQ.Socket puller = context.socket(ZMQ.PULL); //puller.connect("tcp://" + frontHost + ":" + frontPort); puller.connect(STREAMER_URL); //Consume socket data frestoEventQueue.setPullerSocket(puller); frestoEventQueue.start(); int nextCommitCount = 0; int count = 0; long elapsedTime = 0; long duration = 0; _durationWatch.start(); while (work) { // To wait until at least one event in queue if (frestoEventQueue.isEmpty()) { try { Thread.sleep(SLEEP_TIME); continue; } catch (InterruptedException ie) { } } nextCommitCount = frestoEventQueue.size(); for (int i = 0; i < nextCommitCount; i++) { _watch.start(); count++; FrestoEvent frestoEvent = frestoEventQueue.poll(); try { eventWriter.writeEventData(frestoEvent.topic, frestoEvent.eventBytes); } catch (Exception e) { e.printStackTrace(); } finally { // } elapsedTime += _watch.stop(); duration += _durationWatch.stop(); if (count == MAX_COMMIT_COUNT) { eventWriter.commitGraph(); LOGGER.info(count + " events processed for " + elapsedTime + " ms. (total time " + duration + " ms.) Remaining events " + frestoEventQueue.size()); count = 0; elapsedTime = 0; duration = 0; // Stop FOR clause } } eventWriter.commitGraph(); LOGGER.info(count + " events processed for " + elapsedTime + " ms. (total time " + duration + " ms.) Remaining events " + frestoEventQueue.size()); count = 0; elapsedTime = 0; duration = 0; } LOGGER.info("Shutting down..."); if (g.isOpen()) { g.commit(); g.shutdown(); } puller.close(); context.term(); LOGGER.info("Good bye."); } }; Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Interrupt received, killing server"); // To break while clause frestoEventQueue.stopWork(); work = false; try { writerThread.join(); frestoEventQueue.join(); //queueMonitorThread.join(); } catch (InterruptedException e) { } } }); //queueMonitorThread.start(); writerThread.start(); }
From source file:apps.LuceneIndexer.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", null, true, "input file"); options.addOption("o", null, true, "output directory"); options.addOption("r", null, true, "optional output TREC-format QREL file"); options.addOption("bm25_b", null, true, "BM25 parameter: b"); options.addOption("bm25_k1", null, true, "BM25 parameter: k1"); options.addOption("bm25fixed", null, false, "use the fixed BM25 similarity"); Joiner commaJoin = Joiner.on(','); Joiner spaceJoin = Joiner.on(' '); options.addOption("source_type", null, true, "document source type: " + commaJoin.join(SourceFactory.getDocSourceList())); // If you increase this value, you may need to modify the following line in *.sh file // export MAVEN_OPTS="-Xms8192m -server" double ramBufferSizeMB = 1024 * 8; // 8 GB CommandLineParser parser = new org.apache.commons.cli.GnuParser(); IndexWriter indexWriter = null;//from w ww .j a v a 2 s. co m BufferedWriter qrelWriter = null; int docNum = 0; try { CommandLine cmd = parser.parse(options, args); String inputFileName = null, outputDirName = null, qrelFileName = null; if (cmd.hasOption("i")) { inputFileName = cmd.getOptionValue("i"); } else { Usage("Specify 'input file'", options); } if (cmd.hasOption("o")) { outputDirName = cmd.getOptionValue("o"); } else { Usage("Specify 'index directory'", options); } if (cmd.hasOption("r")) { qrelFileName = cmd.getOptionValue("r"); } String sourceName = cmd.getOptionValue("source_type"); if (sourceName == null) Usage("Specify document source type", options); if (qrelFileName != null) qrelWriter = new BufferedWriter(new FileWriter(qrelFileName)); File outputDir = new File(outputDirName); if (!outputDir.exists()) { if (!outputDir.mkdirs()) { System.out.println("couldn't create " + outputDir.getAbsolutePath()); System.exit(1); } } if (!outputDir.isDirectory()) { System.out.println(outputDir.getAbsolutePath() + " is not a directory!"); System.exit(1); } if (!outputDir.canWrite()) { System.out.println("Can't write to " + outputDir.getAbsolutePath()); System.exit(1); } boolean useFixedBM25 = cmd.hasOption("bm25fixed"); float bm25_k1 = UtilConst.BM25_K1_DEFAULT, bm25_b = UtilConst.BM25_B_DEFAULT; if (cmd.hasOption("bm25_k1")) { try { bm25_k1 = Float.parseFloat(cmd.getOptionValue("bm25_k1")); } catch (NumberFormatException e) { Usage("Wrong format for 'bm25_k1'", options); } } if (cmd.hasOption("bm25_b")) { try { bm25_b = Float.parseFloat(cmd.getOptionValue("bm25_b")); } catch (NumberFormatException e) { Usage("Wrong format for 'bm25_b'", options); } } EnglishAnalyzer analyzer = new EnglishAnalyzer(); FSDirectory indexDir = FSDirectory.open(Paths.get(outputDirName)); IndexWriterConfig indexConf = new IndexWriterConfig(analyzer); /* OpenMode.CREATE creates a new index or overwrites an existing one. https://lucene.apache.org/core/6_0_0/core/org/apache/lucene/index/IndexWriterConfig.OpenMode.html#CREATE */ indexConf.setOpenMode(OpenMode.CREATE); indexConf.setRAMBufferSizeMB(ramBufferSizeMB); System.out.println(String.format("BM25 parameters k1=%f b=%f ", bm25_k1, bm25_b)); if (useFixedBM25) { System.out.println(String.format("Using fixed BM25Simlarity, k1=%f b=%f", bm25_k1, bm25_b)); indexConf.setSimilarity(new BM25SimilarityFix(bm25_k1, bm25_b)); } else { System.out.println(String.format("Using Lucene BM25Similarity, k1=%f b=%f", bm25_k1, bm25_b)); indexConf.setSimilarity(new BM25Similarity(bm25_k1, bm25_b)); } indexWriter = new IndexWriter(indexDir, indexConf); DocumentSource inpDocSource = SourceFactory.createDocumentSource(sourceName, inputFileName); DocumentEntry inpDoc = null; TextCleaner textCleaner = new TextCleaner(null); while ((inpDoc = inpDocSource.next()) != null) { ++docNum; Document luceneDoc = new Document(); ArrayList<String> cleanedToks = textCleaner.cleanUp(inpDoc.mDocText); String cleanText = spaceJoin.join(cleanedToks); // System.out.println(inpDoc.mDocId); // System.out.println(cleanText); // System.out.println("=============================="); luceneDoc.add(new StringField(UtilConst.FIELD_ID, inpDoc.mDocId, Field.Store.YES)); luceneDoc.add(new TextField(UtilConst.FIELD_TEXT, cleanText, Field.Store.YES)); indexWriter.addDocument(luceneDoc); if (inpDoc.mIsRel != null && qrelWriter != null) { saveQrelOneEntry(qrelWriter, inpDoc.mQueryId, inpDoc.mDocId, inpDoc.mIsRel ? MAX_GRADE : 0); } if (docNum % 1000 == 0) System.out.println(String.format("Indexed %d documents", docNum)); } } catch (ParseException e) { e.printStackTrace(); Usage("Cannot parse arguments" + e, options); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } finally { System.out.println(String.format("Indexed %d documents", docNum)); try { if (null != indexWriter) indexWriter.close(); if (null != qrelWriter) qrelWriter.close(); } catch (IOException e) { System.err.println("IO exception: " + e); e.printStackTrace(); } } }