List of usage examples for java.lang Thread.UncaughtExceptionHandler Thread.UncaughtExceptionHandler
Thread.UncaughtExceptionHandler
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();//from w w w . j a va 2 s .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: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();// www . ja v a 2 s.c o 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.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 ava 2 s . 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:edu.umn.cs.sthadoop.operations.HSPKNNQ.java
public static void main(String[] args) throws IOException { //./hadoop jar /export/scratch/louai/idea-stHadoop/st-hadoop-uber.jar pknn /mntgIndex/yyyy-MM-dd/2017-08-03 /pknn k:2 point:-78.9659,35.7998 shape:edu.umn.cs.sthadoop.mntg.STPointMntg -overwrite // args = new String[8]; // args[0] = "/export/scratch/mntgData/mntgIndex"; // args[1] = "/export/scratch/mntgData/pknn"; // args[2] = "-overwrite"; // args[3] = "k:10"; // args[4] = "point:-78.9659063204100,35.7903907684998"; // args[5] = "shape:edu.umn.cs.sthadoop.trajectory.STPointTrajectory"; // args[6] = "interval:2017-08-03,2017-08-04"; // args[7] = "-overwrite"; final OperationsParams params = new OperationsParams(new GenericOptionsParser(args)); Path[] paths = params.getPaths(); if (paths.length <= 1 && !params.checkInput()) { printUsage();/* www . j av a 2 s.co m*/ System.exit(1); } if (paths.length > 1 && !params.checkInputOutput()) { printUsage(); System.exit(1); } if (params.get("interval") == null) { System.err.println("Temporal range missing"); printUsage(); System.exit(1); } TextSerializable inObj = params.getShape("shape"); if (!(inObj instanceof STPoint)) { if (!(inObj instanceof STRectangle)) { LOG.error("Shape is not instance of STPoint or instance of STRectangle"); printUsage(); System.exit(1); } } // path to the spatio-temporal index. List<Path> STPaths = new ArrayList<Path>(); try { STPaths = STRangeQuery.getIndexedSlices(params); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (Path input : STPaths) { final Path inputFile = input; 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 ? new Path(paths[1].toUri() + "-" + input.getName()) : 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:com.nuvolect.deepdive.probe.DecompileApk.java
/** * Build a new DEX file excluding classes in the OPTIMIZED_CLASS_EXCLUSION file * @return// w ww . j a v a2 s . c o m */ private JSONObject optimizeDex() { final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { LogUtil.log(LogUtil.LogType.DECOMPILE, "Uncaught exception: " + e.toString()); m_progressStream.putStream("Uncaught exception: " + t.getName()); m_progressStream.putStream("Uncaught exception: " + e.toString()); } }; m_optimize_dex_time = System.currentTimeMillis(); // Save start time for tracking m_optimizeDexThread = new Thread(m_threadGroup, new Runnable() { @Override public void run() { m_progressStream = new ProgressStream( new OmniFile(m_volumeId, m_appFolderPath + DEX_OPTIMIZATION_LOG_FILE)); m_progressStream .putStream("Optimizing classes, reference: " + OPTIMIZED_CLASSES_EXCLUSION_FILENAME); Scanner s = null; try { OmniFile omniFile = new OmniFile(m_volumeId, m_appFolderPath + OPTIMIZED_CLASSES_EXCLUSION_FILENAME); s = new Scanner(omniFile.getStdFile()); while (s.hasNext()) { String excludeClass = s.next(); ignoredLibs.add(excludeClass); m_progressStream.putStream("Exclude class: " + excludeClass); } } catch (Exception e) { LogUtil.logException(LogUtil.LogType.DECOMPILE, e); } if (s != null) s.close(); ArrayList<OmniFile> dexFiles = new ArrayList<>(); for (String fileName : m_dexFileNames) { OmniFile dexFile = new OmniFile(m_volumeId, m_appFolderPath + fileName + ".dex"); if (dexFile.exists() && dexFile.isFile()) { dexFiles.add(dexFile);// Keep track for summary List<ClassDef> classes = new ArrayList<>(); m_progressStream.putStream("Processing: " + fileName + ".dex"); org.jf.dexlib2.iface.DexFile memoryDexFile = null; try { memoryDexFile = DexFileFactory.loadDexFile(dexFile.getStdFile(), Opcodes.forApi(19)); } catch (Exception e) { m_progressStream.putStream("The app DEX file cannot be decompiled."); LogUtil.logException(LogUtil.LogType.DECOMPILE, e); continue; } int excludedClassCount = 0; Set<? extends ClassDef> origClassSet = memoryDexFile.getClasses(); memoryDexFile = null; // Release memory for (org.jf.dexlib2.iface.ClassDef classDef : origClassSet) { final String currentClass = classDef.getType(); if (isIgnored(currentClass)) { ++excludedClassCount; m_progressStream.putStream("Excluded class: " + currentClass); } else { m_progressStream.putStream("Included class: " + currentClass); classes.add(classDef); } } origClassSet = null; // Release memory m_progressStream.putStream("Excluded classes #" + excludedClassCount); m_progressStream.putStream("Included classes #" + classes.size()); m_progressStream.putStream("Rebuilding immutable dex: " + fileName + ".dex"); if (classes.size() > 0) { DexFile optDexFile = new ImmutableDexFile(Opcodes.forApi(19), classes); classes = null; // Release memory try { if (dexFile.delete()) m_progressStream.putStream("Fat DEX file delete success: " + dexFile.getName()); else m_progressStream.putStream("Fat DEX file delete FAILED: " + dexFile.getName()); DexPool.writeTo(dexFile.getStdFile().getAbsolutePath(), optDexFile); String size = NumberFormat.getNumberInstance(Locale.US).format(dexFile.length()); m_progressStream.putStream( "Optimized DEX file created: " + dexFile.getName() + ", size: " + size); } catch (IOException e) { m_progressStream.putStream("DEX IOException, write error: " + dexFile.getName()); LogUtil.logException(LogUtil.LogType.DECOMPILE, e); } catch (Exception e) { m_progressStream.putStream("DEX Exception, write error: " + dexFile.getName()); LogUtil.logException(LogUtil.LogType.DECOMPILE, e); } optDexFile = null; // release memory } else { m_progressStream .putStream("All classes excluded, DEX file not needed: " + dexFile.getName()); m_progressStream.putStream("Deleting: " + dexFile.getName()); dexFile.delete(); } } } for (OmniFile f : dexFiles) { if (f.exists()) { String formatted_count = String.format(Locale.US, "%,d", f.length()) + " bytes"; m_progressStream.putStream("DEX optimized: " + f.getName() + ": " + formatted_count); } else { m_progressStream.putStream("DEX deleted: " + f.getName() + ", all classes excluded"); } } dexFiles = new ArrayList<>();// Release memory m_progressStream .putStream("Optimize DEX complete: " + TimeUtil.deltaTimeHrMinSec(m_optimize_dex_time)); m_progressStream.close(); m_optimize_dex_time = 0; } }, UNZIP_APK_THREAD, STACK_SIZE); m_optimizeDexThread.setPriority(Thread.MAX_PRIORITY); m_optimizeDexThread.setUncaughtExceptionHandler(uncaughtExceptionHandler); m_optimizeDexThread.start(); return new JSONObject(); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
@Test @DisplayName("Cross-Browser test") void crossBrowserTest() throws Exception { setupBrowser("chrome"); log.info("Cross-Browser test"); Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { System.out.println("Uncaught exception: " + ex); synchronized (lock) { OpenViduTestAppE2eTest.ex = new Exception(ex); }// w w w. j a v a 2s . c om } }; Thread t = new Thread(() -> { MyUser user2 = new MyUser(new FirefoxUser("TestUser", 30)); otherUsers.add(user2); user2.getDriver().get(APP_URL); WebElement urlInput = user2.getDriver().findElement(By.id("openvidu-url")); urlInput.clear(); urlInput.sendKeys(OPENVIDU_URL); WebElement secretInput = user2.getDriver().findElement(By.id("openvidu-secret")); secretInput.clear(); secretInput.sendKeys(OPENVIDU_SECRET); user2.getEventManager().startPolling(); user2.getDriver().findElement(By.id("add-user-btn")).click(); user2.getDriver().findElement(By.className("join-btn")).click(); try { user2.getEventManager().waitUntilEventReaches("connectionCreated", 2); user2.getEventManager().waitUntilEventReaches("accessAllowed", 1); user2.getEventManager().waitUntilEventReaches("streamCreated", 2); user2.getEventManager().waitUntilEventReaches("streamPlaying", 2); final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); user2.getEventManager().waitUntilEventReaches("streamDestroyed", 1); user2.getEventManager().waitUntilEventReaches("connectionDestroyed", 1); user2.getDriver().findElement(By.id("remove-user-btn")).click(); user2.getEventManager().waitUntilEventReaches("sessionDisconnected", 1); } catch (Exception e) { e.printStackTrace(); user2.dispose(); Thread.currentThread().interrupt(); } user2.dispose(); }); t.setUncaughtExceptionHandler(h); t.start(); user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.className("join-btn")).click(); user.getEventManager().waitUntilEventReaches("connectionCreated", 2); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); gracefullyLeaveParticipants(1); t.join(); synchronized (lock) { if (OpenViduTestAppE2eTest.ex != null) { throw OpenViduTestAppE2eTest.ex; } } }
From source file:org.ut.biolab.medsavant.MedSavantClient.java
private static void setExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override//from w w w. j a v a2 s . c o m public void uncaughtException(Thread t, Throwable e) { LOG.info("Global exception handler caught: " + t.getName() + ": " + e); if (e instanceof InvocationTargetException) { e = ((InvocationTargetException) e).getCause(); } if (e instanceof SessionExpiredException) { SessionExpiredException see = (SessionExpiredException) e; MedSavantExceptionHandler.handleSessionExpiredException(see); return; } if (e instanceof LockException) { DialogUtils.displayMessage("Cannot modify database", "<html>Another process is making changes.<br/>Please try again later.</html>"); return; } e.printStackTrace(); DialogUtils.displayException("Error", e.getLocalizedMessage(), e); } }); }
From source file:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Log.e(TAG, "Uncaught exception of type " + e.getClass()); e.printStackTrace();/* ww w .ja v a 2s .com*/ } }); // The following piece of code allows networking in main thread. // e.g. Restart Tango button calls a ROS service in UI thread. if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); mRunLocalMaster = mSharedPref.getBoolean(getString(R.string.pref_master_is_local_key), false); mMasterUri = mSharedPref.getString(getString(R.string.pref_master_uri_key), getResources().getString(R.string.pref_master_uri_default)); mCreateNewMap = mSharedPref.getBoolean(getString(R.string.pref_create_new_map_key), false); String logFileName = mSharedPref.getString(getString(R.string.pref_log_file_key), getString(R.string.pref_log_file_default)); setupUI(); mLogger = new Logger(this, mLogTextView, TAGS_TO_LOG, logFileName, LOG_TEXT_MAX_LENGTH); }
From source file:pt.ua.tm.neji.cli.Main.java
private static void installUncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override//ww w . j a v a2 s . c o m public void uncaughtException(Thread thread, Throwable thrwbl) { if (thrwbl instanceof ThreadDeath) { logger.warn("Ignoring uncaught ThreadDead exception."); return; } logger.error("Uncaught exception on cli thread, aborting.", thrwbl); System.exit(0); } }); }
From source file:org.mailster.MailsterSWT.java
private static void startApplication(String[] args) { MailsterSWT main = getInstance();//from ww w . j a v a2 s . co m main.smtpService = new MailsterSmtpService(); MailsterPrefStore store = ConfigurationManager.CONFIG_STORE; try { store.load(); } catch (IOException e) { LOG.debug("Unable to read preferences file. Loading defaults ..."); // Set default preferences store.setValue(ConfigurationManager.MAIL_QUEUE_REFRESH_INTERVAL_KEY, "300000"); //$NON-NLS-1$ store.setValue(ConfigurationManager.ASK_ON_REMOVE_MAIL_KEY, true); store.setValue(ConfigurationManager.APPLY_MAIN_WINDOW_PARAMS_KEY, true); store.setValue(ConfigurationManager.PREFERRED_BROWSER_KEY, Messages.getString("MailsterSWT.default.browser")); //$NON-NLS-1$ store.setValue(ConfigurationManager.PREFERRED_CONTENT_TYPE_KEY, "text/html"); //$NON-NLS-1$ store.setValue(ConfigurationManager.NOTIFY_ON_NEW_MESSAGES_RECEIVED_KEY, true); store.setValue(ConfigurationManager.AUTO_HIDE_NOTIFICATIONS_KEY, true); store.setValue(ConfigurationManager.LANGUAGE_KEY, "en"); store.setValue(ConfigurationManager.EXECUTE_ENCLOSURE_ON_CLICK_KEY, true); store.setValue(ConfigurationManager.DEFAULT_ENCLOSURES_DIRECTORY_KEY, System.getProperty("user.home")); //$NON-NLS-1$ store.setValue(ConfigurationManager.START_POP3_ON_SMTP_START_KEY, true); store.setValue(ConfigurationManager.POP3_SERVER_KEY, ""); store.setValue(ConfigurationManager.POP3_PORT_KEY, MailsterPop3Service.POP3_PORT); store.setValue(ConfigurationManager.POP3_SPECIAL_ACCOUNT_KEY, MailBoxManager.POP3_SPECIAL_ACCOUNT_LOGIN); store.setValue(ConfigurationManager.POP3_ALLOW_APOP_AUTH_METHOD_KEY, true); store.setValue(ConfigurationManager.POP3_REQUIRE_SECURE_AUTH_METHOD_KEY, true); store.setValue(ConfigurationManager.POP3_PASSWORD_KEY, UserManager.DEFAULT_PASSWORD); store.setValue(ConfigurationManager.POP3_CONNECTION_TIMEOUT_KEY, Pop3ProtocolHandler.DEFAULT_TIMEOUT_SECONDS); store.setValue(ConfigurationManager.AUTH_SSL_CLIENT_KEY, true); store.setValue(ConfigurationManager.PREFERRED_SSL_PROTOCOL_KEY, SSLProtocol.TLS.toString()); store.setValue(ConfigurationManager.CRYPTO_STRENGTH_KEY, 512); store.setValue(ConfigurationManager.SMTP_SERVER_KEY, ""); store.setValue(ConfigurationManager.SMTP_PORT_KEY, MailsterSMTPServer.DEFAULT_SMTP_PORT); store.setValue(ConfigurationManager.SMTP_CONNECTION_TIMEOUT_KEY, MailsterSMTPServer.DEFAULT_TIMEOUT / 1000); } String localeInfo = store.getString(ConfigurationManager.LANGUAGE_KEY); if (localeInfo != null && !"".equals(localeInfo)) { if (localeInfo.indexOf('_') != -1) Messages.setLocale(new Locale(localeInfo.substring(0, 2), localeInfo.substring(3))); else Messages.setLocale(new Locale(localeInfo)); } main.smtpService .setQueueRefreshTimeout(store.getLong(ConfigurationManager.SMTP_CONNECTION_TIMEOUT_KEY) / 1000); main.smtpService.setAutoStart(store.getBoolean(ConfigurationManager.START_SMTP_ON_STARTUP_KEY)); if (args.length > 3) usage(); { for (int i = 0, max = args.length; i < max; i++) { if ("-autostart".equals(args[i])) main.smtpService.setAutoStart(true); else if (args[i].startsWith("-lang=")) { Messages.setLocale(new Locale(args[i].substring(6))); } else { try { main.smtpService.setQueueRefreshTimeout(Long.parseLong(args[i])); } catch (NumberFormatException e) { usage(); } } } } final MailsterSWT _main = main; Thread.UncaughtExceptionHandler exHandler = new Thread.UncaughtExceptionHandler() { public void uncaughtException(final Thread t, final Throwable ex) { ex.printStackTrace(); Display.getDefault().asyncExec(new Runnable() { public void run() { _main.log(Messages.getString("MailsterSWT.exception.log1") + t.getName() //$NON-NLS-1$ + Messages.getString("MailsterSWT.exception.log2") //$NON-NLS-1$ + ex.getMessage()); } }); _main.smtpService.shutdownServer(false); } }; Thread.setDefaultUncaughtExceptionHandler(exHandler); Thread.currentThread().setUncaughtExceptionHandler(exHandler); LOG.debug("Creating shell ..."); main.createSShell(); main.applyPreferences(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { _main.smtpService.shutdownServer(true); if (_main.trayItem != null) _main.trayItem.dispose(); } catch (Exception ex) { ex.printStackTrace(); } }; }); }