List of usage examples for java.lang Throwable printStackTrace
public void printStackTrace()
From source file:caarray.client.test.gui.GuiMain.java
/** * @param args// ww w . j a v a 2 s. c o m */ public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { try { new GuiMain(); } catch (Throwable t) { System.out.println("An unexpected error occurred during test execution."); t.printStackTrace(); log.error("Exception encountered:", t); } } }); }
From source file:hu.sztaki.lpds.pgportal.services.dspace.LNIclient.java
/** * Optional main for standalone testing, demonstrate usage. * *//*from w w w .j a v a 2 s.c om*/ public static void main(String[] argv) { // Args: -G | -P [ -i file ] [ -o file ] URL handle // -e eperson -p password [ -t type ] Options options = new Options(); options.addOption("h", "help", false, "show help message"); options.addOption("o", "output", true, "output file for GET"); options.addOption("i", "input", true, "input file for PUT"); options.addOption("G", "get", false, "GET contents of Handle"); options.addOption("P", "put", false, "PUT package into Handle"); options.addOption("e", "eperson", true, "eperson to authenticate as (required)"); options.addOption("p", "password", true, "password for eperson (required)"); options.addOption("t", "type", true, "package type for GET/PUT"); try { CommandLine line = (new PosixParser()).parse(options, argv); String eperson = line.getOptionValue("e"); String password = line.getOptionValue("p"); String type = line.getOptionValue("t"); String rest[] = line.getArgs(); if (eperson == null || password == null || rest.length < 2) Usage(options, 1, "Missing a required option or argument"); String url = rest[0]; String handle = rest[1]; LNIclient lni = new LNIclient(url, eperson, password); if (type == null) type = "METS"; if (line.hasOption("G")) { OutputStream pkg = System.out; if (line.hasOption("o")) pkg = new FileOutputStream(line.getOptionValue("o")); // TODO: add option to convey packager options here. try { InputStream g = lni.startGet(handle, type, null); copy(g, pkg); pkg.close(); } finally { lni.finishGet(); } } else if (line.hasOption("P")) { InputStream pkg = System.in; if (line.hasOption("i")) pkg = new FileInputStream(line.getOptionValue("i")); String result = lni.put(handle, type, null, pkg); System.err.println("LNI PUT created Handle: " + result); } else Usage(options, 1, "Missing required 'G' or 'P' option."); } catch (org.apache.commons.cli.ParseException pe) { Usage(options, 1, "Error in arguments: " + pe.toString()); } catch (Throwable e) { System.err.println("Got exception: " + e.toString()); e.printStackTrace(); } finally { System.exit(0); } }
From source file:com.yobidrive.diskmap.buckets.BucketTableManager.java
public static void main(String[] args) { try {/* w w w. j av a 2 s . c o m*/ BucketTableManager nw = new BucketTableManager("/Users/Francois/Documents/NEEDLES/0.TestStore", 100, 1000000, 3000L, true); nw.initialize(); System.out.println( "Bucket table initialization: " + (nw.getCheckPoint().isEmpty() ? " Repair required" : " OK")); Runtime runtime = Runtime.getRuntime(); long before = runtime.totalMemory() - runtime.freeMemory(); nw.getCheckPoint().copyFrom(new NeedlePointer()); // reset checkpoint Date startDate = new Date(); Date lapDate = new Date(); System.out.println("Start test for " + TEST_COUNT + " pointers"); long counter = 0; long lapCounter = 0; long offset = 0; BucketFNVHash hashFunc = new BucketFNVHash(1000000000L); while (counter < TEST_COUNT) { NeedlePointer needlePointer = new NeedlePointer(); String key = "MYVERYNICEKEY" + counter; long bucket = hashFunc.hash(key); needlePointer.setNeedleFileNumber(4); needlePointer.setNeedleOffset(offset++); nw.writeNeedlePointer(bucket, needlePointer); counter++; Date lapDate2 = new Date(); long spent = lapDate2.getTime() - lapDate.getTime(); if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps if (spent < 1000) { // pause when tps reached Thread.sleep(1000 - spent); System.out.print("."); } else System.out.print("*"); lapDate = lapDate2; // Reset lap time lapCounter = counter; // Reset tps copunter } } long timeSpent = new Date().getTime() - startDate.getTime(); System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n" + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT / timeSpent * 1000) + " tps"); timeSpent = new Date().getTime() - startDate.getTime(); System.out.println("\n\nProcessed writing of " + TEST_COUNT + " pointers \n" + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT / timeSpent * 1000) + " tps"); System.out.println("Max cycle time = " + (nw.getMaxCycleTimePass1() + nw.getMaxCycleTimePass2())); } catch (Throwable th) { th.printStackTrace(); } }
From source file:gov.nih.nci.caintegrator.application.gpvisualizer.CaIntegratorRunVisualizer.java
/** * args[0] = visualizer task name args[1] = command line args[2] = debug * flag args[3] = OS required for running args[4] = CPU type required for * running args[5] = libdir on server for this task args[6] = CSV list of * downloadable files for inputs args[7] = CSV list of input parameter names * args[8] = CSV list of support file names args[9] = CSV list of support * file modification dates args[10] = server URL args[11] = LSID of task * args[12...n] = optional input parameter arguments *///from w w w .j av a 2s . co m public static void main(String[] args) { String[] wellKnownNames = { RunVisualizerConstants.NAME, RunVisualizerConstants.COMMAND_LINE, RunVisualizerConstants.DEBUG, RunVisualizerConstants.OS, RunVisualizerConstants.CPU_TYPE, RunVisualizerConstants.LIBDIR, RunVisualizerConstants.DOWNLOAD_FILES, RunVisualizerConstants.LSID }; int PARAM_NAMES = 7; int SUPPORT_FILE_NAMES = PARAM_NAMES + 1; int SUPPORT_FILE_DATES = SUPPORT_FILE_NAMES + 1; int SERVER = SUPPORT_FILE_DATES + 1; int LSID = SERVER + 1; int TASK_ARGS = LSID + 1; try { HashMap params = new HashMap(); for (int i = 0; i < wellKnownNames.length; i++) { params.put(wellKnownNames[i], args[i]); } String name = (String) params.get(RunVisualizerConstants.NAME); StringTokenizer stParameterNames = new StringTokenizer(args[PARAM_NAMES], ", "); int argNum = TASK_ARGS; // when pulling parameters from the command line, don't assume that // all were provided. // some could be missing! while (stParameterNames.hasMoreTokens()) { String paramName = stParameterNames.nextToken(); if (argNum < args.length) { String paramValue = args[argNum++]; params.put(paramName, paramValue); } else { System.err.println("No value specified for " + paramName); } } URL source = new URL(args[SERVER]); StringTokenizer stFileNames = new StringTokenizer(args[SUPPORT_FILE_NAMES], ","); StringTokenizer stFileDates = new StringTokenizer(args[SUPPORT_FILE_DATES], ","); String[] supportFileNames = new String[stFileNames.countTokens()]; long[] supportFileDates = new long[supportFileNames.length]; String filename = null; String fileDate = null; int f = 0; while (stFileNames.hasMoreTokens()) { supportFileNames[f] = stFileNames.nextToken(); if (stFileDates.hasMoreTokens()) { supportFileDates[f] = Long.parseLong(stFileDates.nextToken()); } else { supportFileDates[f] = -1; } f++; } CaIntegratorRunVisualizer visualizer = new CaIntegratorRunVisualizer(params, supportFileNames, supportFileDates, new Applet()); visualizer.run(); } catch (Throwable t) { t.printStackTrace(); } }
From source file:com.yobidrive.diskmap.DiskMapStore.java
public static void main(String[] args) { try {//from w w w . j a v a2 s .com BasicConfigurator.configure(); // (String storeName, String logPath, String keyPath, long ckeckPointPeriod, long logSize, int keySize, // long mapSize, int packInterval, int readThreads, long needleCachedEntries, long bucketCachedBytes, short nodeId) /* String path = "/Users/david/Documents/NEEDLES"; if ( args.length > 0) { path = args[0]; } System.out.println("Using directory:" + path); */ DiskMapStore dms = new DiskMapStore("teststore", "/drive_hd1;/drive_hd2", "/drive_ssd/storage_indexes", 1000L, // Synching period 60000 * 5L, // Checkpointing period 2000000000L, // Log file size 100, // Key max size 2048, // Nb of buffers 32768, // Nb of entries (buckets) per buffer 60, // Compact interval 8, // Read threads TEST_COUNT / 3 * 2 * 140, // NeedleHeaderCachedEntries (1/20 in cache, 1/2 of typical data set) TEST_COUNT / 3 * 2 * 140, // NeedleCachedBytes (3% of Map, weights 120 bytes/entry) true, // Use needle average age instead of needle yougest age (short) 0, 1, 1, 1); // dmm.getBtm().getCheckPoint().copyFrom(new NeedlePointer()) ; // Removes checkpoint dms.initialize(); // System.out.println("Start read for "+TEST_COUNT+" pointers") ; Date startDate = new Date(); Date lapDate = new Date(); System.out.println("Start read test for " + TEST_COUNT + " pointers"); long counter = 0; long lapCounter = 0; startDate = new Date(); lapDate = new Date(); long failCount = 0; counter = 0; while (counter < TEST_COUNT) { String key = "MYVERYNICELEY" + counter; // System.out.println("key="+key+"...") ; List<Versioned<byte[]>> values = dms.get(new ByteArray(key.getBytes("UTF-8")), null); if (values.size() <= 0) { failCount++; } else { // Gets previous version byte[] value = values.get(0).getValue(); if (value == null) failCount++; else if (value[0] != (byte) ((short) counter % 128)) failCount++; } counter++; Date lapDate2 = new Date(); long spent = lapDate2.getTime() - lapDate.getTime(); if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps if (spent < 1000) { // pause when tps reached Thread.sleep(1000 - spent); // System.out.print(".") ; } else // System.out.print("*") ; lapDate = lapDate2; // Reset lap time lapCounter = counter; // Reset tps copunter } } long timeSpent = new Date().getTime() - startDate.getTime(); System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n" + "\tBad results: " + failCount); startDate = new Date(); lapDate = new Date(); System.out.println("Start write test for " + TEST_COUNT + " pointers"); counter = 0; lapCounter = 0; while (counter < TEST_COUNT) { String key = "MYVERYNICELEY" + counter; // System.out.println("key="+key+"...") ; byte[] value = new byte[128000]; value[0] = (byte) ((short) counter % 128); long chaseDurer = new Date().getTime(); List<Versioned<byte[]>> previousValues = dms.get(new ByteArray(key.getBytes("UTF-8")), null); long chaseDurer2 = new Date().getTime(); // System.out.println("Get in "+(chaseDurer2 -chaseDurer)+"ms") ; chaseDurer = chaseDurer2; Version newVersion = null; if (previousValues.size() <= 0) { newVersion = new VectorClock(); } else { // Gets previous version newVersion = previousValues.get(0).cloneVersioned().getVersion(); } // Increment version before writing ((VectorClock) newVersion).incrementVersion(0, new Date().getTime()); Versioned<byte[]> versionned = new Versioned<byte[]>( previousValues.size() <= 0 ? value : previousValues.get(0).cloneVersioned().getValue(), newVersion); dms.put(new ByteArray(key.getBytes("UTF-8")), versionned, null); chaseDurer2 = new Date().getTime(); // System.out.println("Put in "+(chaseDurer2 -chaseDurer)+"ms") ; // dmm.putValue(key.getBytes("UTF-8"), value) ; counter++; Date lapDate2 = new Date(); long spent = lapDate2.getTime() - lapDate.getTime(); if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps if (spent < 1000) { // pause when tps reached Thread.sleep(1000 - spent); // System.out.print("("+counter+")") ; } else // System.out.print("["+counter+"]") ; lapDate = lapDate2; // Reset lap time lapCounter = counter; // Reset tps copunter } } timeSpent = new Date().getTime() - startDate.getTime(); System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n" + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps"); System.out.println("Start read for " + TEST_COUNT + " pointers"); startDate = new Date(); lapDate = new Date(); failCount = 0; counter = 0; while (counter < TEST_COUNT) { String key = "MYVERYNICELEY" + counter; // System.out.println("key="+key+"...") ; List<Versioned<byte[]>> values = dms.get(new ByteArray(key.getBytes("UTF-8")), null); if (values.size() <= 0) { failCount++; } else { // Gets previous version byte[] value = values.get(0).getValue(); if (value == null) failCount++; else if (value[0] != (byte) ((short) counter % 128)) failCount++; } counter++; Date lapDate2 = new Date(); long spent = lapDate2.getTime() - lapDate.getTime(); if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps if (spent < 1000) { // pause when tps reached Thread.sleep(1000 - spent); // System.out.print(".") ; } else // System.out.print("*") ; lapDate = lapDate2; // Reset lap time lapCounter = counter; // Reset tps copunter } } timeSpent = new Date().getTime() - startDate.getTime(); System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n" + "\tBad results: " + failCount); dms.close(); // System.out.println("Max cycle time = "+ (dms.getBtm().getMaxCycleTimePass1()+dmm.getBtm().getMaxCycleTimePass2())) ; } catch (Throwable th) { th.printStackTrace(); } }
From source file:DDTTestRunner.java
/** * The starting point of the test run - use the args array or use defaults from DDTSettings.Settings() * @param args//from w w w .j a v a2 s. com */ public static void main(String[] args) { DDTSettings.reset(); DDTTestRunner inst = new DDTTestRunner(); String[] tmp; // args[] should be a ':' delimited string indicating the type of source input // A delimted string indicating the type of input used (at present File and Inline are the two options) followed by one or two other values // Example 1: File;DDTRoot.xls;Root // Example 2: Inline;InputGeneratorClassName;rootMethodName if (args.length == 1) { tmp = args[0].split(TestStringsProviderSpecs.SPLITTER); } else { // Use the default input tmp = DDTSettings.Settings().inputSpecsArray(); } try { // Get the initial test items specified in the properties file or the command line runOn(tmp); } catch (Exception ex) { System.out.println(ex.getMessage().toString()); } catch (Throwable throwable) { throwable.printStackTrace(); } finally { if (Driver.isInitialized()) { System.out.println("End of Test Session - Closing Driver"); Driver.getDriver().close(); } endSession(); } }
From source file:com.ricemap.spateDB.operations.RangeQuery.java
public static void main(String[] args) throws IOException { CommandLineArguments cla = new CommandLineArguments(args); final QueryInput query = cla.getQuery(); final Path[] paths = cla.getPaths(); if (paths.length == 0 || (cla.getPrism() == null && cla.getSelectionRatio() < 0.0f)) { printUsage();/*from w w w . java2s .co m*/ throw new RuntimeException("Illegal parameters"); } JobConf conf = new JobConf(FileMBR.class); final Path inputFile = paths[0]; final FileSystem fs = inputFile.getFileSystem(conf); if (!fs.exists(inputFile)) { printUsage(); throw new RuntimeException("Input file does not exist"); } final Path outputPath = paths.length > 1 ? paths[1] : null; final Prism[] queryRanges = cla.getPrisms(); int concurrency = cla.getConcurrency(); final Shape stockShape = cla.getShape(true); final boolean overwrite = cla.isOverwrite(); final long[] results = new long[queryRanges.length]; final Vector<Thread> threads = new Vector<Thread>(); final BooleanWritable exceptionHappened = new BooleanWritable(); Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { ex.printStackTrace(); exceptionHappened.set(true); } }; for (int i = 0; i < queryRanges.length; i++) { Thread t = new Thread() { @Override public void run() { try { int thread_i = threads.indexOf(this); long result_count = rangeQueryMapReduce(fs, inputFile, outputPath, queryRanges[thread_i], stockShape, overwrite, false, query); results[thread_i] = result_count; } catch (IOException e) { throw new RuntimeException(e); } } }; t.setUncaughtExceptionHandler(h); threads.add(t); } long t1 = System.currentTimeMillis(); do { // Ensure that there is at least MaxConcurrentThreads running int i = 0; while (i < concurrency && i < threads.size()) { Thread.State state = threads.elementAt(i).getState(); if (state == Thread.State.TERMINATED) { // Thread already terminated, remove from the queue threads.remove(i); } else if (state == Thread.State.NEW) { // Start the thread and move to next one threads.elementAt(i++).start(); } else { // Thread is still running, skip over it i++; } } if (!threads.isEmpty()) { try { // Sleep for 10 seconds or until the first thread terminates threads.firstElement().join(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } while (!threads.isEmpty()); long t2 = System.currentTimeMillis(); if (exceptionHappened.get()) throw new RuntimeException("Not all jobs finished correctly"); System.out.println("Time for " + queryRanges.length + " jobs is " + (t2 - t1) + " millis"); System.out.print("Result size: ["); for (long result : results) { System.out.print(result + ", "); } System.out.println("]"); }
From source file:edu.umn.cs.spatialHadoop.operations.KNN.java
public static void main(String[] args) throws IOException { final OperationsParams params = new OperationsParams(new GenericOptionsParser(args)); Path[] paths = params.getPaths(); if (paths.length <= 1 && !params.checkInput()) { printUsage();/* w ww . jav a 2s .c o m*/ System.exit(1); } if (paths.length > 1 && !params.checkInputOutput()) { printUsage(); System.exit(1); } final Path inputFile = params.getInputPath(); int count = params.getInt("count", 1); double closeness = params.getFloat("closeness", -1.0f); final Point[] queryPoints = closeness < 0 ? params.getShapes("point", new Point()) : new Point[count]; final FileSystem fs = inputFile.getFileSystem(params); final int k = params.getInt("k", 1); int concurrency = params.getInt("concurrency", 100); if (k == 0) { LOG.warn("k = 0"); } if (queryPoints.length == 0) { printUsage(); throw new RuntimeException("Illegal arguments"); } final Path outputPath = paths.length > 1 ? paths[1] : null; if (closeness >= 0) { // Get query points according to its closeness to grid intersections GlobalIndex<Partition> gindex = SpatialSite.getGlobalIndex(fs, inputFile); long seed = params.getLong("seed", System.currentTimeMillis()); Random random = new Random(seed); for (int i = 0; i < count; i++) { int i_block = random.nextInt(gindex.size()); int direction = random.nextInt(4); // Generate a point in the given direction // Get center point (x, y) Iterator<Partition> iterator = gindex.iterator(); while (i_block-- >= 0) iterator.next(); Partition partition = iterator.next(); double cx = (partition.x1 + partition.x2) / 2; double cy = (partition.y1 + partition.y2) / 2; double cw = partition.x2 - partition.x1; double ch = partition.y2 - partition.y1; int signx = ((direction & 1) == 0) ? 1 : -1; int signy = ((direction & 2) == 1) ? 1 : -1; double x = cx + cw * closeness / 2 * signx; double y = cy + ch * closeness / 2 * signy; queryPoints[i] = new Point(x, y); } } final BooleanWritable exceptionHappened = new BooleanWritable(); Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { ex.printStackTrace(); exceptionHappened.set(true); } }; // Run each query in a separate thread final Vector<Thread> threads = new Vector<Thread>(); for (int i = 0; i < queryPoints.length; i++) { Thread thread = new Thread() { @Override public void run() { try { Point query_point = queryPoints[threads.indexOf(this)]; OperationsParams newParams = new OperationsParams(params); OperationsParams.setShape(newParams, "point", query_point); Job job = knn(inputFile, outputPath, params); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }; thread.setUncaughtExceptionHandler(h); threads.add(thread); } long t1 = System.currentTimeMillis(); do { // Ensure that there is at least MaxConcurrentThreads running int i = 0; while (i < concurrency && i < threads.size()) { Thread.State state = threads.elementAt(i).getState(); if (state == Thread.State.TERMINATED) { // Thread already terminated, remove from the queue threads.remove(i); } else if (state == Thread.State.NEW) { // Start the thread and move to next one threads.elementAt(i++).start(); } else { // Thread is still running, skip over it i++; } } if (!threads.isEmpty()) { try { // Sleep for 10 seconds or until the first thread terminates threads.firstElement().join(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } while (!threads.isEmpty()); long t2 = System.currentTimeMillis(); if (exceptionHappened.get()) throw new RuntimeException("Not all jobs finished correctly"); System.out.println("Time for " + queryPoints.length + " jobs is " + (t2 - t1) + " millis"); System.out.println("Total iterations: " + TotalIterations); }
From source file:Proxy.java
public static void main(String[] args) { Proxy p;/*from w ww .j a v a2 s.c o m*/ InetAddress local = null, remote = null; int local_port = 0, remote_port = 0; String tmp, tmp_addr, tmp_port; boolean verbose = false, debug = false; int index; String mapping_file = null; try { for (int i = 0; i < args.length; i++) { tmp = args[i]; if ("-help".equals(tmp)) { help(); return; } if ("-verbose".equals(tmp)) { verbose = true; continue; } if ("-local".equals(tmp)) { tmp_addr = args[++i]; index = tmp_addr.indexOf(':'); if (index > -1) { // it is in the format address:port tmp_port = tmp_addr.substring(index + 1); local_port = Integer.parseInt(tmp_port); tmp_addr = tmp_addr.substring(0, index); local = InetAddress.getByName(tmp_addr); } else local = InetAddress.getByName(args[++i]); continue; } if ("-local_port".equals(tmp)) { local_port = Integer.parseInt(args[++i]); continue; } if ("-remote".equals(tmp)) { tmp_addr = args[++i]; index = tmp_addr.indexOf(':'); if (index > -1) { // it is in the format address:port tmp_port = tmp_addr.substring(index + 1); remote_port = Integer.parseInt(tmp_port); tmp_addr = tmp_addr.substring(0, index); remote = InetAddress.getByName(tmp_addr); } else remote = InetAddress.getByName(args[++i]); continue; } if ("-remote_port".equals(tmp)) { remote_port = Integer.parseInt(args[++i]); continue; } if ("-file".equals(tmp)) { mapping_file = args[++i]; continue; } if ("-debug".equals(tmp)) { debug = true; continue; } help(); return; } if (local == null) local = InetAddress.getLocalHost(); p = new Proxy(local, local_port, remote, remote_port, verbose, debug, mapping_file); p.start(); } catch (Throwable ex) { ex.printStackTrace(); } }
From source file:edu.umn.cs.sthadoop.trajectory.KNNDTW.java
public static void main(String[] args) throws IOException { args = new String[10]; args[0] = "/export/scratch/mntgData/geolifeGPS/geolife_Trajectories_1.3/HDFS/index_geolife/yyyy-MM/2008-05"; args[1] = "/export/scratch/mntgData/geolifeGPS/geolife_Trajectories_1.3/HDFS/knn-dis-result"; args[2] = "shape:edu.umn.cs.sthadoop.trajectory.GeolifeTrajectory"; args[3] = "interval:2008-05-01,2008-05-30"; args[4] = "time:month"; args[5] = "k:1"; args[6] = "traj:39.9119983,116.606835;39.9119783,116.6065483;39.9119599,116.6062649;39.9119416,116.6059899;39.9119233,116.6057282;39.9118999,116.6054783;39.9118849,116.6052366;39.9118666,116.6050099;39.91185,116.604775;39.9118299,116.604525;39.9118049,116.6042649;39.91177,116.6040166;39.9117516,116.6037583;39.9117349,116.6035066;39.9117199,116.6032666;39.9117083,116.6030232;39.9117,116.6027566;39.91128,116.5969383;39.9112583,116.5966766;39.9112383,116.5964232;39.9112149,116.5961699;39.9111933,116.5959249;39.9111716,116.5956883"; args[7] = "-overwrite"; args[8] = "-local";// "-no-local"; args[9] = "point:39.9119983,116.606835"; final OperationsParams params = new OperationsParams(new GenericOptionsParser(args)); Path[] paths = params.getPaths(); if (paths.length <= 1 && !params.checkInput()) { printUsage();/* w w w .j av a 2 s .c om*/ System.exit(1); } if (paths.length > 1 && !params.checkInputOutput()) { printUsage(); System.exit(1); } final Path inputFile = params.getInputPath(); int count = params.getInt("count", 1); double closeness = params.getFloat("closeness", -1.0f); final Point[] queryPoints = closeness < 0 ? params.getShapes("point", new Point()) : new Point[count]; final FileSystem fs = inputFile.getFileSystem(params); final int k = params.getInt("k", 1); int concurrency = params.getInt("concurrency", 100); if (k == 0) { LOG.warn("k = 0"); } if (queryPoints.length == 0) { printUsage(); throw new RuntimeException("Illegal arguments"); } final Path outputPath = paths.length > 1 ? paths[1] : null; if (closeness >= 0) { // Get query points according to its closeness to grid intersections GlobalIndex<Partition> gindex = SpatialSite.getGlobalIndex(fs, inputFile); long seed = params.getLong("seed", System.currentTimeMillis()); Random random = new Random(seed); for (int i = 0; i < count; i++) { int i_block = random.nextInt(gindex.size()); int direction = random.nextInt(4); // Generate a point in the given direction // Get center point (x, y) Iterator<Partition> iterator = gindex.iterator(); while (i_block-- >= 0) iterator.next(); Partition partition = iterator.next(); double cx = (partition.x1 + partition.x2) / 2; double cy = (partition.y1 + partition.y2) / 2; double cw = partition.x2 - partition.x1; double ch = partition.y2 - partition.y1; int signx = ((direction & 1) == 0) ? 1 : -1; int signy = ((direction & 2) == 1) ? 1 : -1; double x = cx + cw * closeness / 2 * signx; double y = cy + ch * closeness / 2 * signy; queryPoints[i] = new Point(x, y); } } final BooleanWritable exceptionHappened = new BooleanWritable(); Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { ex.printStackTrace(); exceptionHappened.set(true); } }; // Run each query in a separate thread final Vector<Thread> threads = new Vector<Thread>(); for (int i = 0; i < queryPoints.length; i++) { Thread thread = new Thread() { @Override public void run() { try { Point query_point = queryPoints[threads.indexOf(this)]; OperationsParams newParams = new OperationsParams(params); OperationsParams.setShape(newParams, "point", query_point); Job job = knn(inputFile, outputPath, params); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }; thread.setUncaughtExceptionHandler(h); threads.add(thread); } long t1 = System.currentTimeMillis(); do { // Ensure that there is at least MaxConcurrentThreads running int i = 0; while (i < concurrency && i < threads.size()) { Thread.State state = threads.elementAt(i).getState(); if (state == Thread.State.TERMINATED) { // Thread already terminated, remove from the queue threads.remove(i); } else if (state == Thread.State.NEW) { // Start the thread and move to next one threads.elementAt(i++).start(); } else { // Thread is still running, skip over it i++; } } if (!threads.isEmpty()) { try { // Sleep for 10 seconds or until the first thread terminates threads.firstElement().join(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } while (!threads.isEmpty()); long t2 = System.currentTimeMillis(); if (exceptionHappened.get()) throw new RuntimeException("Not all jobs finished correctly"); System.out.println("Time for " + queryPoints.length + " jobs is " + (t2 - t1) + " millis"); System.out.println("Total iterations: " + TotalIterations); }