List of usage examples for java.lang InterruptedException getMessage
public String getMessage()
From source file:com.emuneee.camerasyncmanager.util.GeocodeHelper.java
public static List<Camera> geocodeCameras(List<Camera> cameras, long sleep) throws Exception { List<Camera> geocoded = new ArrayList<Camera>(cameras.size()); int count = 1; // loop through and geocode each camera for (Camera camera : cameras) { StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(sGeocodeUrl).append("?"); urlBuilder.append(sLatLng).append("="); urlBuilder.append(camera.getLatitude()).append(",").append(camera.getLongitude()); urlBuilder.append("&").append(sSensor); sLogger.debug("Geocode URL " + urlBuilder.toString()); try {/*w w w. j a v a 2 s . com*/ // retry String data = null; int retryCount = 0; while (data == null && retryCount < sRetryCount) { if (retryCount > 0) { sLogger.info("Retrying geocoding"); } data = HttpHelper.getStringDataFromUrl(urlBuilder.toString()); Thread.sleep(sleep); retryCount++; } if (data == null) { sLogger.warn("Unable to geocode the camera, no data returned " + camera); } else if (data != null && data.contains("OVER_QUERY_LIMIT")) { sLogger.warn("Unable to geocode the camera, query limit exceeded " + camera); throw new Exception("Unable to geocode the camera, query limit exceeded"); } else { JSONObject jsonObj = (JSONObject) new JSONParser().parse(data); JSONArray resultsArr = (JSONArray) jsonObj.get("results"); if (resultsArr.size() > 0) { for (int i = 0; i < resultsArr.size(); i++) { JSONObject result = (JSONObject) resultsArr.get(i); // loop through the address components JSONArray addressComponents = (JSONArray) result.get("address_components"); for (Object compObj : addressComponents) { JSONObject component = (JSONObject) compObj; String shortName = (String) component.get("short_name"); JSONArray types = (JSONArray) component.get("types"); // loop through the types for (Object typeObj : types) { String type = (String) typeObj; if (type.equalsIgnoreCase("administrative_area_level_3")) { camera.setArea(shortName); break; } else if (type.equalsIgnoreCase("locality")) { camera.setCity(shortName); break; } else if (type.equalsIgnoreCase("administrative_area_level_1")) { camera.setState(shortName); break; } else if (type.equalsIgnoreCase("country")) { camera.setCountry(shortName); break; } else if (type.equalsIgnoreCase("postal_code")) { camera.setZipCode(shortName); break; } } } if (camera.containsAllRequiredData()) { break; } else { sLogger.info( "Some required data is missing, moving to the next address component set"); } } } if (camera.containsAllRequiredData()) { geocoded.add(camera); sLogger.info("Camera " + count++ + " of " + cameras.size() + " geocoded"); sLogger.debug("Geocoded camera " + camera); sLogger.debug("Sleeping for " + sleep + " milliseconds"); } else { sLogger.warn( "Some required data is missing and geocoding results have been exhausted for camera: " + camera); } } } catch (InterruptedException e) { sLogger.error("Error geocoding address"); sLogger.error(e.getMessage()); } catch (ParseException e) { sLogger.error("Error geocoding address"); sLogger.error(e.getMessage()); } } return geocoded; }
From source file:com.ssn.app.loader.SplashDemo.java
/** * just a stub to simulate a long initialization task that updates the text * and progress parts of the status in the Splash *///from w ww . j a v a 2 s . co m private static void appInit() { splashText("Initializing Server Behaviours..."); splashText(copyRightText); splashText(versionAreaText); splashText(loadingText); for (int i = 0; i <= 2; i++) { int pctDone = i * 50; splashText(pctDone + "%"); // splashProgress(pctDone); try { Thread.sleep(500); } catch (InterruptedException ex) { logger.error(ex.getMessage()); } } }
From source file:net.morimekta.idltool.IdlUtils.java
public static Git getCacheRepository(File cacheDir, String repository) throws IOException, GitAPIException { File repoCache = getCacheDirectory(cacheDir, repository); Runtime runtime = Runtime.getRuntime(); if (!repoCache.exists()) { Process p = runtime//from ww w . j av a 2s . com .exec(new String[] { "git", "clone", repository, repoCache.getAbsoluteFile().toString() }); try { int response = p.waitFor(); if (response != 0) { throw new IOException(IOUtils.readString(p.getErrorStream())); } } catch (InterruptedException e) { throw new IOException(e.getMessage(), e); } } else { Process p = runtime.exec(new String[] { "git", "fetch", "origin", "-p" }, null, repoCache); try { int response = p.waitFor(); if (response != 0) { throw new IOException(IOUtils.readString(p.getErrorStream())); } } catch (InterruptedException e) { throw new IOException(e.getMessage(), e); } p = runtime.exec(new String[] { "git", "add", "-A" }, null, repoCache); try { int response = p.waitFor(); if (response != 0) { throw new IOException(IOUtils.readString(p.getErrorStream())); } } catch (InterruptedException e) { throw new IOException(e.getMessage(), e); } p = runtime.exec(new String[] { "git", "reset", "origin/master", "--hard" }, null, repoCache); try { int response = p.waitFor(); if (response != 0) { throw new IOException(IOUtils.readString(p.getErrorStream())); } } catch (InterruptedException e) { throw new IOException(e.getMessage(), e); } } return Git.open(repoCache); }
From source file:com.fujitsu.dc.test.jersey.bar.BarInstallTestUtils.java
/** * Box??.//from www . j av a2 s.c om * @param location Location */ public static void waitBoxInstallCompleted(String location) { DcResponse response = null; JSONObject bodyJson = null; long startTime = System.currentTimeMillis(); while (true) { response = ODataCommon.getOdataResource(location); if (HttpStatus.SC_OK == response.getStatusCode()) { bodyJson = (JSONObject) ((JSONObject) response.bodyAsJson()); if (!ProgressInfo.STATUS.PROCESSING.value().equals(bodyJson.get("status"))) { return; } assertNull(bodyJson.get("installed_at")); assertNotNull(bodyJson.get("progress")); assertNotNull(bodyJson.get("started_at")); } if (System.currentTimeMillis() - startTime > BAR_INSTALL_TIMEOUT) { fail("Failed to bar file install: takes too much time. [" + BAR_INSTALL_TIMEOUT + "millis]"); } try { Thread.sleep(BAR_INSTALL_SLEEP_TIME); } catch (InterruptedException e) { log.info("Interrupted: " + e.getMessage()); } } }
From source file:io.personium.test.jersey.bar.BarInstallTestUtils.java
/** * Box??.//from w w w.ja v a 2s. com * @param location Location */ public static void waitBoxInstallCompleted(String location) { PersoniumResponse response = null; JSONObject bodyJson = null; long startTime = System.currentTimeMillis(); while (true) { response = ODataCommon.getOdataResource(location); if (HttpStatus.SC_OK == response.getStatusCode()) { bodyJson = (JSONObject) ((JSONObject) response.bodyAsJson()); if (!ProgressInfo.STATUS.PROCESSING.value().equals(bodyJson.get("status"))) { return; } assertNull(bodyJson.get("installed_at")); assertNotNull(bodyJson.get("progress")); assertNotNull(bodyJson.get("started_at")); } if (System.currentTimeMillis() - startTime > BAR_INSTALL_TIMEOUT) { fail("Failed to bar file install: takes too much time. [" + BAR_INSTALL_TIMEOUT + "millis]"); } try { Thread.sleep(BAR_INSTALL_SLEEP_TIME); } catch (InterruptedException e) { log.info("Interrupted: " + e.getMessage()); } } }
From source file:com.robin.utilities.Utilities.java
/** * A utility that waits for a specific amount of time. * @param timeToWait Time to wait in ms. *//* w ww . j av a2 s .c o m*/ public static void waitTime(final long timeToWait) { try { Thread.sleep(timeToWait); } catch (InterruptedException e) { Reporter.log(e.getMessage()); e.printStackTrace(); } }
From source file:fr.inria.oak.paxquery.xparser.client.XClient.java
private static void printDOTFile(String filePath, String dotString) { String filePathDot = filePath; String filePathPNG = filePath; if (filePathDot.startsWith("file://")) { filePathDot = filePathDot.substring("file://".length()); filePathPNG = filePathPNG.substring("file://".length()); }/* w w w . java 2 s .c o m*/ /* * int extensionIndex = filePathDot.lastIndexOf("."); if(extensionIndex > -1) { filePathDot = * filePathDot.subSequence(0, extensionIndex) + "-pact.dot"; filePathPNG = * filePathPNG.subSequence(0, extensionIndex) + "-pact.png"; } else { filePathDot = filePathDot * + "-pact.dot"; filePathPNG = filePathPNG + "-pact.png"; } */ if (filePath.endsWith("/") == true) { filePathDot = filePathDot + "xoutput-pact.dot"; filePathPNG = filePathPNG + "xoutput-pact.png"; } else { filePathDot = filePathDot + "/xoutput-pact.dot"; filePathPNG = filePathPNG + "/xoutput-pact.png"; } try { // print the dot file FileWriter writer = new FileWriter(filePathDot, false); writer.write(dotString); writer.close(); Runtime r = Runtime.getRuntime(); String com = new String("dot -Tpng " + filePathDot + " -o " + filePathPNG); Process p = r.exec(com); p.waitFor(); // System.out.println("PACT plan drawn."); } catch (IOException ioe) { System.out.println("Error with pact file: " + ioe.getMessage()); } catch (InterruptedException ie) { System.out.println("Error with pact file: " + ie.getMessage()); } }
From source file:com.mapviewer.business.NetCDFRequestManager.java
/** * Obtains the layerDetails from a ncWMS server and stores the result as a * string (from a JSON object) this is then the javascript variable layerDetails * * @param {Layer} layer//from w w w . j a v a2 s.c o m * @return */ public static String getLayerDetails(Layer layer) throws Exception { //For the moment we only obtain the datails for netCDF layers (ncWMS server) if (!layer.isNetCDF()) { return ""; } URL ncReq; String detailsRequest = buildRequest(layer, "GetMetadata", "layerDetails"); JSONObject layerDetails = new JSONObject(); int maxTries = 1; //120 int tryNumber = 0;// Current try boolean accepted = false; while (!accepted && (tryNumber < maxTries)) {// While try { ncReq = new URL(detailsRequest); ncReq.openConnection(); InputStreamReader input = null; // Number of times we will try to get the layer details for each layer // in this case we will wait at most 2 minutes input = new InputStreamReader(ncReq.openStream()); BufferedReader in = new BufferedReader(input); String inputLine; while ((inputLine = in.readLine()) != null) { if (!inputLine.trim().equalsIgnoreCase("")) {// TODO check for errros //System.out.println("AKI" + inputLine); layerDetails = new JSONObject(inputLine); } } // If minColor and maxColor are set in the xml file, we replace // the JSONObject of LayerDetails if (!((layer.getMinColor() == -1) && (layer.getMaxColor() == -1))) { JSONArray scale = layerDetails.getJSONArray("scaleRange"); scale.put(0, layer.getMinColor()); scale.put(1, layer.getMaxColor()); } accepted = true;//If there is no exception then we accept the layer details } catch (JSONException | IOException e) { try { tryNumber++; System.out.println("Layer details try number:" + tryNumber + " Error:" + e.getMessage()); Thread.sleep(1000);//We wait for 1 seconds. } catch (InterruptedException ex) { System.out.println("Interrupted exception while waiting for layer details:" + ex.getMessage()); } } } if (accepted) { System.out.println("layer details: " + layerDetails.toString()); return layerDetails.toString(); } else { throw new Exception("ERROR: Not able to load layer details for layer:" + layer.getDisplayName("EN")); } }
From source file:com.act.biointerpretation.sarinference.LibMcsClustering.java
/** * Reads in a prediction corpus, containing only one RO's predictions, and builds a clustering tree of the * substrates. Returns every SarTreeNode in the tree. * This method is static because it does not rely on any properties of the enclosing class to construct the job. * TODO: It would probably make more sense to make this its own class, i.e. <Clusterer implements JavaRunnable> * * @param predictionCorpusInput The prediction corpus input file. * @param sarTreeNodesOutput The file to which to write the SarTreeNodeList of every node in the clustering tree. * @return A JavaRunnable to run the appropriate clustering. */// w ww. ja v a 2 s . c om public static JavaRunnable getClusterer(File predictionCorpusInput, File sarTreeNodesOutput) { return new JavaRunnable() { @Override public void run() throws IOException { // Verify input and output files FileChecker.verifyInputFile(predictionCorpusInput); FileChecker.verifyAndCreateOutputFile(sarTreeNodesOutput); // Build input corpus and substrate list L2PredictionCorpus inputCorpus = L2PredictionCorpus .readPredictionsFromJsonFile(predictionCorpusInput); // Get list of molecules, tagged by PredictionId so we can track back to the corresponding predictions later on. Collection<Molecule> molecules = importMoleculesWithPredictionIds(inputCorpus); // Run substrate clustering SarTree sarTree = new SarTree(); try { sarTree.buildByClustering(new LibraryMCS(), molecules); } catch (InterruptedException e) { LOGGER.error("Threw interrupted exception during buildByClustering: %s", e.getMessage()); throw new RuntimeException(e); } // Write output to file SarTreeNodeList nodeList = new SarTreeNodeList(new ArrayList<>(sarTree.getNodes())); nodeList.writeToFile(sarTreeNodesOutput); } @Override public String toString() { return "SarClusterer:" + predictionCorpusInput.getName(); } /** * Imports the substrate molecules from the prediction corpus, and tags them with their prediction IDs from * the corpus, using Chemaxon's setPropertyObject. These prediction Ids can then be recovered from the molecules * later, and mapped back to the original inchis, even if the molecule has been changed so that its inchi is no * longer the same. In particular, LibraryMCS strips stereo and other layers from the inchis, which would make * it hard to track LCMS hit sand misses between the output molecules of LibraryMCS and the initial inchis fed * into LibraryMCS. * * @param inputCorpus The prediction corpus. * @return A list of molecules, tagged with a property objects which contains the corresponding list of * prediction ids.. * @throws MolFormatException If a molecule cannot be imported from an inchi. */ private Collection<Molecule> importMoleculesWithPredictionIds(L2PredictionCorpus inputCorpus) throws MolFormatException { Map<String, Molecule> inchiToMoleculeMap = new HashMap<>(); for (L2Prediction prediction : inputCorpus.getCorpus()) { for (String substrateInchi : prediction.getSubstrateInchis()) { // For now this should only be one substrate if (!inchiToMoleculeMap.containsKey(substrateInchi)) { Molecule mol = importMoleculeWithPredictionId(substrateInchi, prediction.getId()); inchiToMoleculeMap.put(substrateInchi, mol); } else { List<Integer> predictionIds = (ArrayList<Integer>) inchiToMoleculeMap .get(substrateInchi).getPropertyObject(SarTreeNode.PREDICTION_ID_KEY); predictionIds.add(prediction.getId()); } } } return inchiToMoleculeMap.values(); } private Molecule importMoleculeWithPredictionId(String inchi, Integer id) throws MolFormatException { Molecule mol = MolImporter.importMol(inchi, "inchi"); List<Integer> predictionIds = new ArrayList<>(); predictionIds.add(id); mol.setPropertyObject(SarTreeNode.PREDICTION_ID_KEY, predictionIds); return mol; } }; }
From source file:com.clustercontrol.agent.filecheck.FileCheck.java
/** * ??????//from ww w .j a va2 s. com * ??????1?? */ private static String jobFileCheckResultRetry(JobFileCheck jobFileCheck) throws HinemosUnknown_Exception, InvalidRole_Exception, InvalidUserPass_Exception, MonitorNotFound_Exception, JobMasterNotFound_Exception, FacilityNotFound_Exception, JobInfoNotFound_Exception { if (resultRetryCount < 0) { String str = AgentProperties.getProperty("job.filecheck.sender.tries", "15"); resultRetryCount = Integer.parseInt(str); m_log.info("filecheck.retry.count=" + resultRetryCount); } if (resultRetrySleep < 0) { String str = AgentProperties.getProperty("job.filecheck.sender.interval", "60000"); resultRetrySleep = Integer.parseInt(str); m_log.info("filecheck.retry.sleep=" + resultRetrySleep); } for (int i = 0; i < resultRetryCount; i++) { try { return AgentEndPointWrapper.jobFileCheckResult(jobFileCheck); } catch (JobSessionDuplicate_Exception e) { m_log.warn("sendNotifyRetry " + e.getMessage()); } catch (Throwable t) { try { Thread.sleep(resultRetrySleep); } catch (InterruptedException e1) { m_log.warn("sendNotifyRetry " + e1.getMessage()); } } } m_log.warn("give up jobFileCheckResultRetry. Maybe, manager is down"); return null; }