List of usage examples for java.lang Throwable printStackTrace
public void printStackTrace()
From source file:org.tommy.stationery.moracle.core.client.load.StompWebSocketLoadTestClient.java
public static void main(String[] args) throws Exception { // Modify host and port below to match wherever StompWebSocketServer.java is running!! // When StompWebSocketServer starts it prints the selected available String host = "localhost"; if (args.length > 0) { host = args[0];//from w ww . j av a 2s . co m } int port = 59984; if (args.length > 1) { port = Integer.valueOf(args[1]); } String url = "http://" + host + ":" + port + "/home"; logger.debug("Sending warm-up HTTP request to " + url); HttpStatus status = new RestTemplate().getForEntity(url, Void.class).getStatusCode(); Assert.state(status == HttpStatus.OK); final CountDownLatch connectLatch = new CountDownLatch(NUMBER_OF_USERS); final CountDownLatch subscribeLatch = new CountDownLatch(NUMBER_OF_USERS); final CountDownLatch messageLatch = new CountDownLatch(NUMBER_OF_USERS); final CountDownLatch disconnectLatch = new CountDownLatch(NUMBER_OF_USERS); final AtomicReference<Throwable> failure = new AtomicReference<Throwable>(); Executor executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE); org.eclipse.jetty.websocket.client.WebSocketClient jettyClient = new WebSocketClient(executor); JettyWebSocketClient webSocketClient = new JettyWebSocketClient(jettyClient); webSocketClient.start(); HttpClient jettyHttpClient = new HttpClient(); jettyHttpClient.setMaxConnectionsPerDestination(1000); jettyHttpClient.setExecutor(new QueuedThreadPool(1000)); jettyHttpClient.start(); List<Transport> transports = new ArrayList<>(); transports.add(new WebSocketTransport(webSocketClient)); transports.add(new JettyXhrTransport(jettyHttpClient)); SockJsClient sockJsClient = new SockJsClient(transports); try { URI uri = new URI("ws://" + host + ":" + port + "/stomp"); WebSocketStompClient stompClient = new WebSocketStompClient(uri, null, sockJsClient); stompClient.setMessageConverter(new StringMessageConverter()); logger.debug("Connecting and subscribing " + NUMBER_OF_USERS + " users "); StopWatch stopWatch = new StopWatch("STOMP Broker Relay WebSocket Load Tests"); stopWatch.start(); List<ConsumerStompMessageHandler> consumers = new ArrayList<>(); for (int i = 0; i < NUMBER_OF_USERS; i++) { consumers.add(new ConsumerStompMessageHandler(BROADCAST_MESSAGE_COUNT, connectLatch, subscribeLatch, messageLatch, disconnectLatch, failure)); stompClient.connect(consumers.get(i)); } if (failure.get() != null) { throw new AssertionError("Test failed", failure.get()); } if (!connectLatch.await(5000, TimeUnit.MILLISECONDS)) { logger.info("Not all users connected, remaining: " + connectLatch.getCount()); } if (!subscribeLatch.await(5000, TimeUnit.MILLISECONDS)) { logger.info("Not all users subscribed, remaining: " + subscribeLatch.getCount()); } stopWatch.stop(); logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis"); logger.debug("Broadcasting " + BROADCAST_MESSAGE_COUNT + " messages to " + NUMBER_OF_USERS + " users "); stopWatch.start(); ProducerStompMessageHandler producer = new ProducerStompMessageHandler(BROADCAST_MESSAGE_COUNT, failure); stompClient.connect(producer); if (failure.get() != null) { throw new AssertionError("Test failed", failure.get()); } if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) { for (ConsumerStompMessageHandler consumer : consumers) { if (consumer.messageCount.get() < consumer.expectedMessageCount) { logger.debug(consumer); } } } if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) { logger.info("Not all handlers received every message, remaining: " + messageLatch.getCount()); } producer.session.disconnect(); if (!disconnectLatch.await(5000, TimeUnit.MILLISECONDS)) { logger.info("Not all disconnects completed, remaining: " + disconnectLatch.getCount()); } stopWatch.stop(); logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis"); System.out.println("\nPress any key to exit..."); System.in.read(); } catch (Throwable t) { t.printStackTrace(); } finally { webSocketClient.stop(); jettyHttpClient.stop(); } logger.debug("Exiting"); System.exit(0); }
From source file:com.tri_voltage.md.io.YoutubeVideoParser.java
public static void main(String[] args) { args = new String[] { "-dir" }; try {/* w ww.jav a 2 s .c om*/ new YoutubeVideoParser().run(args); } catch (Throwable t) { t.printStackTrace(); } }
From source file:io.s4.zeno.SiteTest.java
public static void main(String[] arg) throws JSONException, KeeperException, IOException, InterruptedException { PropertyConfigurator.configure("log4j.properties"); String name = arg[0];//www. j a va 2 s . c o m String zkaddr = arg[1]; String zkbase = arg[2]; String specStr = arg[3]; ConfigMap spec = new JSONConfigMap(specStr); ZooKeeper zk = new ZooKeeper(zkaddr, 3000, zkhandler); zookeeper = new ZooKeeperHelper(zk, 5, 5000); zkpath = new ZKPaths(zkbase); ZooKeeperInfo zkinfo = new ZooKeeperInfo(); zkinfo.zookeeper = zookeeper; zkinfo.zkpath = zkpath; zkinfo.taskHolder = new NonblockingLockset(zookeeper, zkpath.taskBase); zkinfo.partsHolder = new NonblockingLockset(zookeeper, zkpath.partsBase); zkinfo.standbySequence = new DistributedSequence(zookeeper, zkpath.standbyBase); final Site site = new Site(name, spec); ZKCluster cluster = new ZKCluster(zookeeper, zkpath); ZKJobList jobList = new ZKJobList(site, zkinfo); ZKPartList partList = new ZKPartList(site, zkinfo); SiteInitializer init = new SiteInitializer(); site.setCluster(cluster); site.setJobList(jobList); site.setPartList(partList); site.setInitializer(init); class ZenoThreadGroup extends ThreadGroup { public ZenoThreadGroup() { super("ZenoThreadGroup"); } public void uncaughtException(Thread t, Throwable e) { System.out.println("ZENOTHREADGROUP CAUGHT AND EXCEPTION FROM THREAD " + t + ". SO EXITING. DETAILS:" + e + "\nCAUSED BY: " + e.getCause() + "\n"); e.printStackTrace(); System.exit(1); } } Thread t = new Thread(new ZenoThreadGroup(), new Runnable() { public void run() { site.start(); } }, "zenorunthread"); t.start(); System.out.println(); t.join(); }
From source file:org.onebusaway.nyc.vehicle_tracking.utility.SensorModelVerificationMain.java
public static void main(String[] args) throws ParseException, ClassNotFoundException, CsvEntityIOException, IOException { Options options = new Options(); options.addOption(ARG_RULE, true, "sensor model rule class"); GnuParser parser = new GnuParser(); CommandLine cli = parser.parse(options, args); args = cli.getArgs();// w w w.ja v a 2 s .c o m if (args.length != 2) { System.err.println("usage: data-sources.xml tracesPath"); System.exit(-1); } ConfigurableApplicationContext context = ContainerLibrary.createContext( "classpath:org/onebusaway/nyc/vehicle_tracking/application-context.xml", "classpath:org/onebusaway/transit_data_federation/application-context.xml", args[0]); SensorModelVerificationMain m = new SensorModelVerificationMain(); context.getAutowireCapableBeanFactory().autowireBean(m); Collection<SensorModelRule> rules = Collections.emptyList(); if (cli.hasOption(ARG_RULE)) { Class<?> ruleClass = Class.forName(cli.getOptionValue(ARG_RULE)); rules = Arrays.asList((SensorModelRule) context.getBean(ruleClass)); } else { Map<String, SensorModelRule> rulesByName = context.getBeansOfType(SensorModelRule.class); rules = rulesByName.values(); } m.setRules(rules); File tracePath = new File(args[1]); List<File> traces = new ArrayList<File>(); getAllTraces(tracePath, traces); m.setTraces(traces); try { m.run(); } catch (Throwable ex) { ex.printStackTrace(); System.exit(-1); } System.exit(0); }
From source file:org.fcrepo.server.utilities.ServerUtility.java
/** * Command-line entry point to reload policies. Takes 3 args: protocol user * pass/*from w ww.j a va2 s .c o m*/ */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Parameters: method arg1 arg2 arg3 etc"); System.out.println(""); System.out.println("Methods:"); System.out.println(" reloadpolicies"); System.out.println(" migratedatastreamcontrolgroup"); System.exit(0); } String method = args[0].toLowerCase(); if (method.equals("reloadpolicies")) { if (args.length == 4) { try { reloadPolicies(args[1], args[2], args[3]); System.out.println("SUCCESS: Policies have been reloaded"); System.exit(0); } catch (Throwable th) { th.printStackTrace(); System.err.println("ERROR: Reloading policies failed; see above"); System.exit(1); } } else { System.err.println("ERROR: Three arguments required: " + "http|https username password"); System.exit(1); } } else if (method.equals("migratedatastreamcontrolgroup")) { // too many args if (args.length > 10) { System.err.println("ERROR: too many arguments provided"); System.exit(1); } // too few if (args.length < 7) { System.err.println("ERROR: insufficient arguments provided. Arguments are: "); System.err.println(" protocol [http|https]"); // 1; 0 is method System.err.println(" user"); // 2 System.err.println(" password"); // 3 System.err.println(" pid - either"); // 4 System.err.println(" a single pid, eg demo:object"); System.err.println(" list of pids separated by commas, eg demo:object1,demo:object2"); System.err.println(" name of file containing pids, eg file:///path/to/file"); System.err.println(" dsid - either"); // 5 System.err.println(" a single datastream id, eg DC"); System.err.println(" list of ids separated by commas, eg DC,RELS-EXT"); System.err.println(" controlGroup - target control group (note only M is implemented)"); // 6 System.err.println( " addXMLHeader - add an XML header to the datastream [true|false, default false]"); // 7 System.err.println(" reformat - reformat the XML [true|false, default false]"); // 8 System.err.println( " setMIMETypeCharset - add charset=UTF-8 to the MIMEType [true|false, default false]"); // 9 System.exit(1); } try { // optional args boolean addXMLHeader = getArgBoolean(args, 7, false); boolean reformat = getArgBoolean(args, 8, false); boolean setMIMETypeCharset = getArgBoolean(args, 9, false); ; InputStream is = modifyDatastreamControlGroup(args[1], args[2], args[3], args[4], args[5], args[6], addXMLHeader, reformat, setMIMETypeCharset); IOUtils.copy(is, System.out); is.close(); System.out.println("SUCCESS: Datastreams modified"); System.exit(0); } catch (Throwable th) { th.printStackTrace(); System.err.println("ERROR: migrating datastream control group failed; see above"); System.exit(1); } } else { System.err.println("ERROR: unrecognised method " + method); System.exit(1); } }
From source file:kilim.tools.Weaver.java
/** * <pre>/*from ww w. j av a 2s . c o m*/ * Usage: java kilim.tools.Weaver -d <output directory> {source classe, jar, directory ...} * </pre> * * If directory names or jar files are given, all classes in that container are processed. It is * perfectly fine to specify the same directory for source and output like this: * <pre> * java kilim.tools.Weaver -d ./classes ./classes * </pre> * Ensure that all classes to be woven are in the classpath. The output directory does not have to be * in the classpath during weaving. * * @see #weave(List) for run-time weaving. */ public static void main(String[] args) throws IOException { // System.out.println(System.getProperty("java.class.path")); Detector detector = Detector.DEFAULT; String currentName = null; for (String name : parseArgs(args)) { try { if (name.endsWith(".class")) { if (exclude(name)) continue; currentName = name; weaveFile(name, new BufferedInputStream(new FileInputStream(name)), detector); } else if (name.endsWith(".jar")) { for (FileLister.Entry fe : new FileLister(name)) { currentName = fe.getFileName(); if (currentName.endsWith(".class")) { currentName = currentName.substring(0, currentName.length() - 6).replace('/', '.'); if (exclude(currentName)) continue; weaveFile(currentName, fe.getInputStream(), detector); } } } else if (new File(name).isDirectory()) { for (FileLister.Entry fe : new FileLister(name)) { currentName = fe.getFileName(); if (currentName.endsWith(".class")) { if (exclude(currentName)) continue; weaveFile(currentName, fe.getInputStream(), detector); } } } else { weaveClass(name, detector); } } catch (KilimException ke) { log.error("Error weaving " + currentName + ". " + ke.getMessage()); // ke.printStackTrace(); System.exit(1); } catch (IOException ioe) { log.error("Unable to find/process '" + currentName + "'"); System.exit(1); } catch (Throwable t) { log.error("Error weaving " + currentName); t.printStackTrace(); System.exit(1); } } System.exit(err); }
From source file:com.acceleratedio.pac_n_zoom.UploadVideo.java
/** * Upload the user-selected video to the user's YouTube channel. The code * looks for the video in the application's project folder and uses OAuth * 2.0 to authorize the API request./* w w w . ja v a2 s .co m*/ * * @param args command line args (not used). */ public static void main(String[] args) { MakePostRequest get_video = new MakePostRequest(); get_video.execute(); // This OAuth 2.0 access scope allows an application to upload files // to the authenticated user's YouTube channel, but doesn't allow // other types of access. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.upload"); String vidFileName = PickAnmActivity.fil_nams[position].replace('/', '?') + ".mp4"; String httpAddrs = "http://www.pnzanimate.me/Droid/db_rd.php?"; httpAddrs += vidFileName; try { // Authorize the request. Credential credential = Auth.authorize(scopes, "uploadvideo"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-uploadvideo-sample").build(); System.out.println("Uploading: " + SAMPLE_VIDEO_FILENAME); // Add extra information to the video before uploading. Video videoObjectDefiningMetadata = new Video(); // Set the video to be publicly visible. This is the default // setting. Other supporting settings are "unlisted" and "private." VideoStatus status = new VideoStatus(); status.setPrivacyStatus("public"); videoObjectDefiningMetadata.setStatus(status); // Most of the video's metadata is set on the VideoSnippet object. VideoSnippet snippet = new VideoSnippet(); // This code uses a Calendar instance to create a unique name and // description for test purposes so that you can easily upload // multiple files. You should remove this code from your project // and use your own standard names instead. Calendar cal = Calendar.getInstance(); snippet.setTitle("Test Upload via Java on " + cal.getTime()); snippet.setDescription( "Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime()); // Set the keyword tags that you want to associate with the video. List<String> tags = new ArrayList<String>(); tags.add("test"); tags.add("example"); tags.add("java"); tags.add("YouTube Data API V3"); tags.add("erase me"); snippet.setTags(tags); // Add the completed snippet object to the video resource. videoObjectDefiningMetadata.setSnippet(snippet); InputStreamContent mediaContent = new InputStreamContent("mp4", UploadVideo.class.getResourceAsStream("/sample-video.mp4")); // Insert the video. The command sends three arguments. The first // specifies which information the API request is setting and which // information the API response should return. The second argument // is the video resource that contains metadata about the new video. // The third argument is the actual video content. YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent); // Set the upload type and add an event listener. MediaHttpUploader uploader = videoInsert.getMediaHttpUploader(); // Indicate whether direct media upload is enabled. A value of // "True" indicates that direct media upload is enabled and that // the entire media content will be uploaded in a single request. // A value of "False," which is the default, indicates that the // request will use the resumable media upload protocol, which // supports the ability to resume an upload operation after a // network interruption or other transmission failure, saving // time and bandwidth in the event of network failures. uploader.setDirectUploadEnabled(false); MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() { public void progressChanged(MediaHttpUploader uploader) throws IOException { switch (uploader.getUploadState()) { case INITIATION_STARTED: System.out.println("Initiation Started"); break; case INITIATION_COMPLETE: System.out.println("Initiation Completed"); break; case MEDIA_IN_PROGRESS: System.out.println("Upload in progress"); System.out.println("Upload percentage: " + uploader.getProgress()); break; case MEDIA_COMPLETE: System.out.println("Upload Completed!"); break; case NOT_STARTED: System.out.println("Upload Not Started!"); break; } } }; uploader.setProgressListener(progressListener); // Call the API and upload the video. Video returnedVideo = videoInsert.execute(); // Print data about the newly inserted video from the API response. System.out.println("\n================== Returned Video ==================\n"); System.out.println(" - Id: " + returnedVideo.getId()); System.out.println(" - Title: " + returnedVideo.getSnippet().getTitle()); System.out.println(" - Tags: " + returnedVideo.getSnippet().getTags()); System.out.println(" - Privacy Status: " + returnedVideo.getStatus().getPrivacyStatus()); System.out.println(" - Video Count: " + returnedVideo.getStatistics().getViewCount()); } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } catch (Throwable t) { System.err.println("Throwable: " + t.getMessage()); t.printStackTrace(); } }
From source file:com.google.api.services.samples.analytics.cmdline.CoreReportingApiReferenceSample.java
/** * Main demo. This first initializes an Analytics service object. It then queries for the top 25 * organic search keywords and traffic sources by visits. Finally each important part of the * response is printed to the screen.//from w w w . j av a 2s .c o m * * @param args command line args. */ public static void main(String[] args) { try { if (args.length == 2) { // Start and end date are supplied startDate = new SimpleDateFormat("yyyy-MM-dd").parse(args[0]); endDate = new SimpleDateFormat("yyyy-MM-dd").parse(args[1]); } System.out.println("Retrieving for dates " + startDate + " " + endDate); HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Analytics analytics = initializeAnalytics(); MongoClient mongo = new MongoClient("localhost", 27017); DB regus_analytics_db = mongo.getDB("regus_analytics"); DBCollection regus_visited_companies = regus_analytics_db.getCollection("ga"); DBCollection regus_visit_attributes = regus_analytics_db.getCollection("visit_attrs"); DBCollection centerMapping = regus_analytics_db.getCollection("center_mapping"); GaData gaData; for (Date d = startDate; !DateUtils.isSameDay(d, DateUtils.addDays(endDate, 1)); d = DateUtils .addDays(d, 1)) { int startIndex = 0; do { System.out.println("Executing data query for visited companies for date: " + d); gaData = executeDataQueryForVisitedCompanies(analytics, TABLE_ID, startIndex, d); insertVisitedCompaniesData(gaData, regus_visited_companies, d); startIndex = gaData.getQuery().getStartIndex() + gaData.getQuery().getMaxResults(); } while (gaData.getNextLink() != null && !gaData.getNextLink().isEmpty()); startIndex = 0; do { System.out.println("Executing data query for visit attributes for date: " + d); gaData = executeDataQueryForVisitAttributes(analytics, TABLE_ID, startIndex, d); insertVisitAttributesData(gaData, regus_visit_attributes, d, centerMapping); startIndex = gaData.getQuery().getStartIndex() + gaData.getQuery().getMaxResults(); } while (gaData.getNextLink() != null && !gaData.getNextLink().isEmpty()); } } catch (GoogleJsonResponseException e) { System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:it.cnr.icar.eric.client.xml.registry.InfomodelFactoryTest.java
public static void main(String[] args) { try {//from w ww. ja v a 2 s . c o m junit.textui.TestRunner.run(suite()); } catch (Throwable t) { System.out.println("\nThrowable: " + t.getClass().getName() + " Message: " + t.getMessage()); t.printStackTrace(); } }
From source file:org.apache.servicecomb.demo.springmvc.client.SpringmvcClient.java
public static void main(String[] args) throws Exception { try {/* ww w . j ava 2 s. c o m*/ Log4jUtils.init(); BeanUtils.init(); run(); TestMgr.summary(); } catch (Throwable e) { TestMgr.check("success", "failed"); System.err.println("-------------- test failed -------------"); e.printStackTrace(); System.err.println("-------------- test failed -------------"); } }