List of usage examples for java.lang InterruptedException toString
public String toString()
From source file:com.alibaba.jstorm.utils.SystemOperation.java
public static String exec(String cmd) throws IOException { LOG.debug("Shell cmd: " + cmd); Process process = new ProcessBuilder(new String[] { "/bin/bash", "-c", cmd }).start(); try {//from w ww . j a va 2s . co m process.waitFor(); String output = IOUtils.toString(process.getInputStream()); String errorOutput = IOUtils.toString(process.getErrorStream()); LOG.debug("Shell Output: " + output); if (errorOutput.length() != 0) { LOG.error("Shell Error Output: " + errorOutput); throw new IOException(errorOutput); } return output; } catch (InterruptedException ie) { throw new IOException(ie.toString()); } }
From source file:info.smartkit.hairy_batman.demo.MoniterWechatBrowser.java
/** * ?URLhtml?//from w w w .j ava 2 s. c o m */ @SuppressWarnings("deprecation") public static String getHttpClientHtml(String url, String code, String userAgent) { String html = null; @SuppressWarnings("deprecation") DefaultHttpClient httpClient = new DefaultHttpClient();// httpClient HttpGet httpget = new HttpGet(url);// get?URL // Pause for 4 seconds try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); System.out.println(e1.toString()); } // httpget.setHeader("User-Agent", userAgent); try { // responce HttpResponse responce = httpClient.execute(httpget); // ? int returnCode = responce.getStatusLine().getStatusCode(); // 200? ? if (returnCode == HttpStatus.SC_OK) { // HttpEntity entity = responce.getEntity(); if (entity != null) { html = new String(EntityUtils.toString(entity));// html?? } } } catch (Exception e) { System.out.println(""); e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } return html; }
From source file:Main.java
public static void shutdownNow(ExecutorService exec) { if (exec != null) { List<Runnable> tasks = exec.shutdownNow(); if (tasks.size() == 0) { System.out.println(// ww w. j a v a 2 s . c o m "Runnable tasks outlived thread pool executor service [" + ", tasks=" + tasks + ']'); } try { exec.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { System.out.println( "Got interrupted while waiting for executor service to stop.[" + e.toString() + "]"); } } }
From source file:Main.java
public static boolean isBuildPropertyAvaliable(Context c, String propName) { try {/*w ww . java2 s . c o m*/ Process p = runSuCommandAsync(c, "busybox grep \"" + propName + "=\" /system/build.prop"); try { p.waitFor(); Log.d("Helper", "isBuildPropAvali : exitValue is : " + String.valueOf(p.exitValue())); if (p.exitValue() == 0) return true; } catch (InterruptedException d) { Log.e("Helper", "Failed grep build.prop and waiting for process. errcode:" + d.toString()); } } catch (Exception d) { Log.e("Helper", "Failed grep build.prop. errcode:" + d.toString()); } return false; }
From source file:org.apache.hadoop.hbase.Waiter.java
/** * Makes the current thread sleep for the duration equal to the specified time in milliseconds * multiplied by the {@link #getWaitForRatio(Configuration)}. * @param conf the configuration/*w w w . java 2 s. c om*/ * @param time the number of milliseconds to sleep. */ public static void sleep(Configuration conf, long time) { try { Thread.sleep((long) (getWaitForRatio(conf) * time)); } catch (InterruptedException ex) { LOG.warn(MessageFormat.format("Sleep interrupted, {0}", ex.toString())); } }
From source file:eionet.cr.harvest.OnDemandHarvester.java
/** * * @param sourceUrl/*from www . ja va 2 s . c o m*/ * @param userName * @return Resolution * @throws HarvestException */ public static Resolution harvest(String sourceUrl, String userName) throws HarvestException { if (StringUtils.isBlank(sourceUrl)) throw new IllegalArgumentException("Source URL must not be null or blank!"); else if (StringUtils.isBlank(userName)) throw new IllegalArgumentException("Instant harvest user name must not be null or blank!"); if (CurrentHarvests.contains(sourceUrl)) { return Resolution.ALREADY_HARVESTING; } CurrentHarvests.addOnDemandHarvest(sourceUrl, userName); OnDemandHarvester instantHarvester = null; try { instantHarvester = new OnDemandHarvester(sourceUrl, userName); instantHarvester.start(); for (int loopCount = 0; instantHarvester.isAlive() && loopCount < 15; loopCount++) { try { Thread.sleep(1000); } catch (InterruptedException e) { throw new CRRuntimeException(e.toString(), e); } } if (!instantHarvester.isAlive() && instantHarvester.wasException()) { throw instantHarvester.getHarvestException(); } else { if (instantHarvester.isAlive()) { return Resolution.UNCOMPLETE; } else { if (!instantHarvester.isSourceAvailable()) return Resolution.SOURCE_UNAVAILABLE; else if (!instantHarvester.isRdfContentFound()) return Resolution.NO_STRUCTURED_DATA; // else if (!instantHarvester.isNeedsHarvesting()) // return Resolution.RECENTLY_HARVESTED; else return Resolution.COMPLETE; } } } finally { // if the instant harvester was never constructed or it isn't alive // any more, make sure the current-harvest-source-url is nullified if (instantHarvester == null || !instantHarvester.isAlive()) { CurrentHarvests.removeOnDemandHarvest(sourceUrl); } } }
From source file:com.nubits.nubot.trading.TradeUtils.java
public static boolean takeDownAndWait(String orderID, long timeoutMS, CurrencyPair pair) { ApiResponse deleteOrderResponse = Global.exchange.getTrade().cancelOrder(orderID, pair); if (deleteOrderResponse.isPositive()) { boolean delRequested = (boolean) deleteOrderResponse.getResponseObject(); if (delRequested) { LOG.warning("Order " + orderID + " delete request submitted"); } else {/* ww w . ja v a 2 s. c om*/ LOG.severe("Could not submit request to delete order" + orderID); } } else { LOG.severe(deleteOrderResponse.getError().toString()); } //Wait until the order is deleted or timeout boolean timedout = false; boolean deleted = false; long wait = 6 * 1000; long count = 0L; do { try { Thread.sleep(wait); count += wait; timedout = count > timeoutMS; ApiResponse orderDetailResponse = Global.exchange.getTrade().isOrderActive(orderID); if (orderDetailResponse.isPositive()) { deleted = !((boolean) orderDetailResponse.getResponseObject()); LOG.fine("Does order " + orderID + " still exist?" + !deleted); } else { LOG.severe(orderDetailResponse.getError().toString()); return false; } } catch (InterruptedException ex) { LOG.severe(ex.toString()); return false; } } while (!deleted && !timedout); if (timedout) { return false; } return true; }
From source file:FactFind.PersonalDetails.java
public static boolean CustomerPersonalDetails() { int MaxCustomerreached = 0; JSONArray CustomerInformation_Array = (JSONArray) TestExecution.JSONTestData.get("Customerinformation"); Iterator<JSONObject> CustomerInformationArray = CustomerInformation_Array.iterator(); String FirstCustomerFlag = "Yes"; try {// w w w . ja va 2 s .co m WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.elementToBeClickable(NextButtonTopofthePage)); while (CustomerInformationArray.hasNext()) { if (MaxCustomerreached >= 2) { break; } JSONObject CustomerInformation = CustomerInformationArray.next(); if ((FirstCustomerFlag.equals("Yes") || CustomerInformation.get("IsApplicant").equals("Yes")) && CustomerInformation.get("CustomerType").equals("Individual")) { if (FirstCustomerFlag.equals("Yes")) { Applicant1.click(); Thread.sleep(3000); MaxCustomerreached++; } else if (CustomerInformation.get("IsApplicant").equals("Yes")) { Applicant2.click(); Thread.sleep(3000); MaxCustomerreached++; } if (JSON.GetTestData(CustomerInformation, "CustomerNames").get("Title") != null && Integer.parseInt(JSON.GetTestData(CustomerInformation, "CustomerNames").get("Title") .toString()) >= 1) { Title.click(); Helper.Keystrokeup(9); Helper.Keystrokedown(Integer.parseInt( JSON.GetTestData(CustomerInformation, "CustomerNames").get("Title").toString())); } if (JSON.GetTestData(CustomerInformation, "CustomerNames").get("MiddleName") != null) { MiddleName.click(); MiddleName.clear(); MiddleName.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerNames").get("MiddleName") .toString()); } if (CustomerInformation.get("Gender") != null) { if (CustomerInformation.get("Gender").equals("Male") || CustomerInformation.get("Gender").equals("Female")) { Gender.click(); Gender.sendKeys(CustomerInformation.get("Gender").toString()); Helper.Keystrokeenter(1); } else { Gender.click(); Gender.sendKeys("Unspecified"); Helper.Keystrokeenter(1); } } if (CustomerInformation.get("DOB") != null) { if (FirstCustomerFlag.equals("Yes")) { DateOfbirth.click(); DateOfbirth.clear(); DateOfbirth.sendKeys(CustomerInformation.get("DOB").toString()); } else if (CustomerInformation.get("IsApplicant").equals("Yes")) { DateOfbirthSpouse.click(); DateOfbirthSpouse.clear(); DateOfbirthSpouse.sendKeys(CustomerInformation.get("DOB").toString()); } } if (CustomerInformation.get("ResidentialStatus") != null && Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) >= 1) { if (Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 1 || Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 2 || Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 3) { ResidencyStatus.click(); Helper.Keystrokeup(3); Helper.Keystrokedown(2); Helper.Keystrokeenter(1); } else if (Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 4) { ResidencyStatus.click(); Helper.Keystrokeup(3); Helper.Keystrokedown(1); Helper.Keystrokeenter(1); } else if (Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 5) { ResidencyStatus.click(); Helper.Keystrokeup(3); Helper.Keystrokedown(3); Helper.Keystrokeenter(1); } } if (JSON.GetTestData(CustomerInformation, "CustomerContactDetails").get("Mobile") != null) { Mobile.click(); Mobile.clear(); Mobile.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerContactDetails") .get("Mobile").toString()); } if (JSON.GetTestData(CustomerInformation, "CustomerContactDetails").get("HomePhone") != null) { HomePhone.click(); HomePhone.clear(); HomePhone.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerContactDetails") .get("HomePhone").toString()); } if (JSON.GetTestData(CustomerInformation, "CustomerContactDetails") .get("BusinessPhone") != null) { BusinessPhone.click(); BusinessPhone.clear(); BusinessPhone.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerContactDetails") .get("BusinessPhone").toString()); } JSONObject FactFind = JSON.GetTestData(CustomerInformation, "FactFind"); if (JSON.GetTestData(FactFind, "DriversLicense").get("DriversLicenceNumber") != null) { DriversLicenceNumber.click(); DriversLicenceNumber.clear(); DriversLicenceNumber.sendKeys(JSON.GetTestData(FactFind, "DriversLicense") .get("DriversLicenceNumber").toString()); } if (JSON.GetTestData(FactFind, "DriversLicense").get("LicenseState") != null) { LicenceState.click(); LicenceState.sendKeys( JSON.GetTestData(FactFind, "DriversLicense").get("LicenseState").toString()); Helper.Keystrokeenter(1); } if (JSON.GetTestData(FactFind, "DriversLicense").get("LicenceIssued") != null) { if (FirstCustomerFlag.equals("Yes")) { LicenceIssued.click(); LicenceIssued.clear(); LicenceIssued.sendKeys( JSON.GetTestData(FactFind, "DriversLicense").get("LicenceIssued").toString()); } else if (CustomerInformation.get("IsApplicant").equals("Yes")) { LicenceIssuedSpouse.click(); LicenceIssuedSpouse.clear(); LicenceIssuedSpouse.sendKeys( JSON.GetTestData(FactFind, "DriversLicense").get("LicenceIssued").toString()); } } if (JSON.GetTestData(FactFind, "DriversLicense").get("LicenceExpires") != null) { if (FirstCustomerFlag.equals("Yes")) { LicenceExpiry.click(); LicenceExpiry.clear(); LicenceExpiry.sendKeys( JSON.GetTestData(FactFind, "DriversLicense").get("LicenceExpires").toString()); } else if (CustomerInformation.get("IsApplicant").equals("Yes")) { LicenceExpirySpouse.click(); LicenceExpirySpouse.clear(); LicenceExpirySpouse.sendKeys( JSON.GetTestData(FactFind, "DriversLicense").get("LicenceExpires").toString()); } } Thread.sleep(3000); if (JSON.GetTestData(CustomerInformation, "CustomerDependents") .get("NumberOfDependents") != null) { JSONArray DependantDOBArray = (JSONArray) JSON .GetTestData(CustomerInformation, "CustomerDependents").get("DependentsDOB"); Iterator<String> DOBArray = DependantDOBArray.iterator(); while (DOBArray.hasNext()) { Helper.ScroolToView(driver, AddDependant); AddDependant.click(); Thread.sleep(2000); AgeofDependant.sendKeys(CalculateAge(DOBArray.next().toString())); Helper.ScroolToView(driver, SaveDependent); SaveDependent.click(); } } FirstCustomerFlag = "No"; } } Applicant1.click(); Thread.sleep(5000); Helper.ScroolToView(driver, SaveMyDetails); SaveMyDetails.click(); Thread.sleep(5000); Helper.ScroolToView(driver, NextButtonBottomofthePage); NextButtonBottomofthePage.click(); Helper.ScreenDump(TestExecution.TestExecutionFolder, "FactFindPersonalDetails"); logger.info("FactFind Customer personal details entered successfully"); return true; } catch (InterruptedException e) { e.printStackTrace(); logger.error(e.toString()); Helper.ScreenDump(TestExecution.TestExecutionFolder, "Error"); return false; } }
From source file:net.minecraftforge.fml.common.FMLCommonHandler.java
public static void callFuture(FutureTask task) { try {//w w w . j ava 2s.co m task.run(); task.get(); // Forces the exception to be thrown if any } catch (InterruptedException e) { FMLLog.log(Level.FATAL, e, "Exception caught executing FutureTask: " + e.toString()); } catch (ExecutionException e) { FMLLog.log(Level.FATAL, e, "Exception caught executing FutureTask: " + e.toString()); } }
From source file:cn.kk.exia.MangaDownloader.java
private static String analyzeAndDownload(final String line, final int num, final Logger log, final boolean first, final String targetDir) throws IOException { String pageTitle = Helper.substringBetweenNarrow(line, "<h1>", "</h1>"); if (Helper.isNotEmptyOrNull(pageTitle)) { if (Helper.isNotEmptyOrNull(MangaDownloader.mangaTitle)) { // System.out.println("??-title: " + MangaDownloader.mangaTitle); pageTitle = Helper.escapeFileName(StringEscapeUtils.unescapeHtml4(MangaDownloader.mangaTitle)); } else {/*w ww . ja v a2 s . c om*/ // System.out.println("??-h1: " + pageTitle); pageTitle = Helper.escapeFileName(StringEscapeUtils.unescapeHtml4(pageTitle)); } final File dir = new File(targetDir + File.separator + pageTitle); if (first) { log.log("??" + pageTitle); } dir.mkdirs(); MangaDownloader.nextUrl = Helper.substringBetweenNarrow(line, "<a href=\"", "-" + num + "\"><img"); if (Helper.isNotEmptyOrNull(MangaDownloader.nextUrl)) { MangaDownloader.nextUrl += "-" + num; final String img = Helper.substringBetweenNarrow(line.substring(line.indexOf("<iframe")), "<img src=\"", "\" style=\""); if (Helper.isNotEmptyOrNull(img)) { try { String imgName = img.substring(img.lastIndexOf('/')); if (imgName.indexOf('=') != -1) { imgName = imgName.substring(imgName.lastIndexOf('=') + 1); } imgName = Helper.escapeFileName(imgName); String ext = ".jpg"; final int idx = imgName.lastIndexOf('.'); if (idx != -1) { ext = imgName.substring(idx); } if (null != MangaDownloader.download(img, new File(dir, pageTitle + "_" + num + ext).getAbsolutePath(), false, log)) { log.log("?" + img); try { if (MangaDownloader.lineCounter++ >= 5) { MangaDownloader.lineCounter = 0; Thread.sleep((40 * MangaDownloader.sleepBase) + (int) (Math.random() * 12 * MangaDownloader.sleepBase)); // 12000 } else { Thread.sleep((8 * MangaDownloader.sleepBase) + (int) (Math.random() * 5 * MangaDownloader.sleepBase)); } } catch (final InterruptedException e) { e.printStackTrace(); log.err("" + e.toString()); } } else { log.log("" + img); try { Thread.sleep((5 * MangaDownloader.sleepBase) + (int) (Math.random() * 5 * MangaDownloader.sleepBase)); } catch (final InterruptedException e) { e.printStackTrace(); log.err("" + e.toString()); } } } catch (final IOException e) { // e.printStackTrace(); log.err("" + e.toString()); throw e; } return MangaDownloader.nextUrl; } } } return null; }