List of usage examples for java.lang InterruptedException getMessage
public String getMessage()
From source file:dk.dma.epd.shore.EPDShore.java
/** * Function used to call sleep on a thread * // ww w . j a v a2 s.c o m * @param ms * - time in ms of how long to sleep */ public static void sleep(long ms) { try { Thread.sleep(ms); } catch (InterruptedException e) { LOG.error(e.getMessage()); } }
From source file:com.att.nsa.cambria.backends.kafka.KafkaConsumerCache.java
/** * Getting the curator oject to start the zookeeper connection estabished * /*ww w. j a v a2 s. co m*/ * @param curator * @return curator object */ public static CuratorFramework getCuratorFramework(CuratorFramework curator) { if (curator.getState() == CuratorFrameworkState.LATENT) { curator.start(); try { curator.blockUntilConnected(); } catch (InterruptedException e) { // Ignore log.error("error while setting curator framework :" + e.getMessage()); } } return curator; }
From source file:com.betfair.application.performance.BaselinePerformanceTester.java
private static void makeRequest(HttpCallable call, String contentType, Random rnd) { HttpClient httpc = client.get();/* www . j a va 2 s. c om*/ if (httpc == null) { httpc = new DefaultHttpClient(); client.set(httpc); } HttpCallLogEntry cle = new HttpCallLogEntry(); int randomiser = rnd.nextInt(50); avgRandomiser.addAndGet(randomiser); HttpUriRequest method = call.getMethod(contentType, new Object[] { randomiser }, randomiser, cle); method.addHeader("Authority", "CoUGARUK"); CallLogCount loggedCount = null; // Execute the method. synchronized (LOG) { loggedCount = LOG.get(cle); if (loggedCount == null) { loggedCount = new CallLogCount(); LOG.put(cle, loggedCount); } } long nanoTime = System.nanoTime(); InputStream is = null; try { if (TRACE_EVERY > 0 && callsMade.incrementAndGet() % TRACE_EVERY == 0) { method.addHeader("X-Trace-Me", "true"); } loggedCount.numCalls.incrementAndGet(); final HttpResponse httpResponse = httpc.execute(method); int statusCode = httpResponse.getStatusLine().getStatusCode(); boolean failed = false; int expectedHTTPCode = call.expectedResult(); if (contentType.equals(SOAP) && expectedHTTPCode != HttpStatus.SC_OK) { // All SOAP errors are 500. expectedHTTPCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; } if (statusCode != expectedHTTPCode) { System.err.println("Method failed: " + httpResponse.getStatusLine().getReasonPhrase()); failed = true; } // Read the response body. is = httpResponse.getEntity().getContent(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); int b; while ((b = is.read()) != -1) { baos.write(b); } is.close(); String result = new String(baos.toByteArray(), CHARSET); if (result.length() == 0) { System.err.println("FAILURE: Empty buffer returned"); failed = true; } if (failed) { loggedCount.failures.incrementAndGet(); } bytesReceived.addAndGet(baos.toByteArray().length); if (CHECK_LOG && NUM_THREADS == 1) { File logFile = new File( "C:\\perforce\\se\\development\\HEAD\\cougar\\cougar-framework\\baseline\\baseline-launch\\logs\\request-Baseline.log"); String lastLine = getLastLine(logFile); int tries = 0; while (!lastLine.contains(METHOD_NAMES.get(call.getName()))) { if (++tries > 5) { System.err.println( "LOG FAIL: Call: " + METHOD_NAMES.get(call.getName()) + ", Line: " + lastLine); } else { try { Thread.sleep(1); } catch (InterruptedException e) { } } lastLine = getLastLine(logFile); } totalLogRetries.addAndGet(tries); } } catch (Exception e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); loggedCount.failures.incrementAndGet(); } finally { // Release the connection. if (is != null) { try { is.close(); } catch (IOException e) { /* ignore */} } callsRemaining.decrementAndGet(); nanoTime = System.nanoTime() - nanoTime; loggedCount.callTime.addAndGet(nanoTime); } }
From source file:edu.stanford.epad.common.dicom.DCM4CHEEUtil.java
public static void dcmsnd(String inputPathFile, boolean throwException) throws Exception { InputStream is = null;//ww w. j ava 2 s. com InputStreamReader isr = null; BufferedReader br = null; try { String dcmServerTitlePort = aeTitle + "@localhost:" + dicomServerPort; dcmServerTitlePort = dcmServerTitlePort.trim(); log.info("Sending file - command: ./dcmsnd " + dcmServerTitlePort + " " + inputPathFile); String[] command = { "./dcmsnd", dcmServerTitlePort, inputPathFile }; ProcessBuilder pb = new ProcessBuilder(command); String dicomBinDirectoryPath = EPADConfig.getEPADWebServerDICOMBinDir(); log.info("DICOM binary directory: " + dicomBinDirectoryPath); pb.directory(new File(dicomBinDirectoryPath)); Process process = pb.start(); process.getOutputStream(); is = process.getInputStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); String line; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); log.info("./dcmsend output: " + line); } try { int exitValue = process.waitFor(); log.info("dcmsnd exit value is: " + exitValue); if (sb.toString().contains("Sent 0 objects")) { log.warning("Zero objects sent to dcm4che, some error has occurred"); throw new Exception("Error sending files to dcm4che"); } } catch (InterruptedException e) { log.warning("Error sending DICOM files in: " + inputPathFile, e); } String cmdLineOutput = sb.toString(); if (cmdLineOutput.toLowerCase().contains("error")) { throw new IllegalStateException("Failed for: " + cmdLineOutput); } } catch (Exception e) { if (e instanceof IllegalStateException && throwException) { throw e; } log.warning("dcmsnd failed: " + e.getMessage()); if (throwException) { throw new IllegalStateException("dcmsnd failed", e); } } catch (OutOfMemoryError oome) { log.warning("dcmsnd ran out of memory", oome); if (throwException) { throw new IllegalStateException("dcmsnd ran out of memory", oome); } } finally { IOUtils.closeQuietly(br); IOUtils.closeQuietly(isr); } }
From source file:com.microfocus.application.automation.tools.octane.executor.UftJobCleaner.java
/** * Delete discovery job that related to specific executor in Octane * * @param executorToDelete//from w w w. ja v a 2 s . c o m */ public static void deleteDiscoveryJobByExecutor(String executorToDelete) { List<FreeStyleProject> jobs = Jenkins.getInstance().getAllItems(FreeStyleProject.class); for (FreeStyleProject proj : jobs) { if (UftJobRecognizer.isDiscoveryJob(proj)) { String executorId = UftJobRecognizer.getExecutorId(proj); String executorLogicalName = UftJobRecognizer.getExecutorLogicalName(proj); if ((StringUtils.isNotEmpty(executorId) && executorId.equals(executorToDelete)) || (StringUtils.isNotEmpty(executorLogicalName) && executorLogicalName.equals(executorToDelete))) { boolean waitBeforeDelete = false; if (proj.isBuilding()) { proj.getLastBuild().getExecutor().interrupt(); waitBeforeDelete = true; } else if (proj.isInQueue()) { Jenkins.getInstance().getQueue().cancel(proj); waitBeforeDelete = true; } if (waitBeforeDelete) { try { //we cancelled building/queue - wait before deleting the job, so Jenkins will be able to complete some IO actions Thread.sleep(10000); } catch (InterruptedException e) { //do nothing } } try { logger.warn(String.format( "Job '%s' is going to be deleted since matching executor in Octane was deleted", proj.getName())); proj.delete(); } catch (IOException | InterruptedException e) { logger.error("Failed to delete job " + proj.getName() + " : " + e.getMessage()); } } } } }
From source file:com.dodo.wbbshoutbox.codebot.MainActivity.java
public static void refresh() { RequestParams params = new RequestParams(); params.put("page", "ShoutboxEntryXMLList"); Request.get(baseUrl + "index.php", params, new AsyncHttpResponseHandler() { @Override/* w w w .j av a 2s .co m*/ public void onSuccess(String response) { try { read(response); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } @Override public void onFailure(Throwable e, String errorResponse) { Toast.makeText(context, "Verbindung fehlgeschlagen. Fehler: " + e.getMessage(), Toast.LENGTH_SHORT) .show(); } }); if (!UserData.readPref("autorefresh", context).equals("")) { autorefresh(); } }
From source file:com.hpe.application.automation.tools.octane.executor.UftJobCleaner.java
/** * Delete discovery job that related to specific executor in Octane * * @param id/*w w w. jav a 2 s . c om*/ */ public static void deleteExecutor(String id) { long executorToDelete = Long.parseLong(id); List<FreeStyleProject> jobs = Jenkins.getInstance().getAllItems(FreeStyleProject.class); for (FreeStyleProject proj : jobs) { if (UftJobRecognizer.isDiscoveryJobJob(proj)) { Long executorId = getExecutorId(proj); if (executorId != null && executorId == executorToDelete) { boolean waitBeforeDelete = false; if (proj.isBuilding()) { proj.getLastBuild().getExecutor().interrupt(); waitBeforeDelete = true; } else if (proj.isInQueue()) { Jenkins.getInstance().getQueue().cancel(proj); waitBeforeDelete = true; } if (waitBeforeDelete) { try { //we cancelled building/queue - wait before deleting the job, so Jenkins will be able to complete some IO actions Thread.sleep(10000); } catch (InterruptedException e) { //do nothing } } try { logger.warn(String.format( "Job '%s' is going to be deleted since matching executor in Octane was deleted", proj.getName())); proj.delete(); } catch (IOException | InterruptedException e) { logger.error("Failed to delete job " + proj.getName() + " : " + e.getMessage()); } } } } }
From source file:net.mybox.mybox.Common.java
/** * Run a system command on the local machine * @param command//from w w w. j av a 2 s . c o m * @return */ public static SysResult syscommand(String[] command) { Runtime r = Runtime.getRuntime(); SysResult result = new SysResult(); System.out.println("syscommand array: " + StringUtils.join(command, " ")); try { Process p = r.exec(command); // should use a thread so it can be killed if it has not finished and another one needs to be started InputStream in = p.getInputStream(); InputStream stderr = p.getErrorStream(); InputStreamReader inreadErr = new InputStreamReader(stderr); BufferedReader brErr = new BufferedReader(inreadErr); BufferedInputStream buf = new BufferedInputStream(in); InputStreamReader inread = new InputStreamReader(buf); BufferedReader bufferedreader = new BufferedReader(inread); // Read the ls output String line; while ((line = bufferedreader.readLine()) != null) { result.output += line + "\n"; System.err.print(" output> " + result.output); // should check for last line "Contacting server..." after 3 seconds, to restart unison command X times } result.worked = true; // Check for failure try { if (p.waitFor() != 0) { System.err.println("exit value = " + p.exitValue()); System.err.println("command> " + command); System.err.println("output> " + result.output); System.err.print("error> "); while ((line = brErr.readLine()) != null) System.err.println(line); result.worked = false; } result.returnCode = p.waitFor(); } catch (InterruptedException e) { System.err.println(e); result.worked = false; } finally { // Close the InputStream bufferedreader.close(); inread.close(); buf.close(); in.close(); } } catch (IOException e) { System.err.println(e.getMessage()); result.worked = false; } result.output = result.output.trim(); return result; }
From source file:com.frostwire.bittorrent.BTEngine.java
public static BTEngine getInstance() { if (ctx == null) { try {/* ww w.j a va 2 s . c o m*/ ctxSetupLatch.await(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } if (ctx == null && Loader.INSTANCE.isRunning()) { throw new IllegalStateException("BTContext can't be null"); } } return Loader.INSTANCE; }
From source file:Browser.java
/** * Open the specified URL in the client web browser. * /* w w w . java2 s .c o m*/ * @param url URL to open. * @throws IOException If there is brwoser problem. */ public static void openUrl(String url) throws IOException { if (!loadedWithoutErrors) { throw new IOException("Exception in finding browser: " + errorMessage); } Object browser = locateBrowser(); if (browser == null) { throw new IOException("Unable to locate browser: " + errorMessage); } switch (jvm) { case MRJ_2_0: Object aeDesc = null; try { aeDesc = aeDescConstructor.newInstance(new Object[] { url }); putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc }); sendNoReply.invoke(browser, new Object[] {}); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage()); } catch (InstantiationException ie) { throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage()); } finally { aeDesc = null; // Encourage it to get disposed if it was created browser = null; // Ditto } break; case MRJ_2_1: Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; case MRJ_3_0: int[] instance = new int[1]; int result = ICStart(instance, 0); if (result == 0) { int[] selectionStart = new int[] { 0 }; byte[] urlBytes = url.getBytes(); int[] selectionEnd = new int[] { urlBytes.length }; result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart, selectionEnd); if (result == 0) { // Ignore the return value; the URL was launched successfully // regardless of what happens here. ICStop(instance); } else { throw new IOException("Unable to launch URL: " + result); } } else { throw new IOException("Unable to create an Internet Config instance: " + result); } break; case MRJ_3_1: try { openURL.invoke(null, new Object[] { url }); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage()); } break; case WINDOWS_NT: case WINDOWS_9x: // Add quotes around the URL to allow ampersands and other special // characters to work. Process process = Runtime.getRuntime().exec(new String[] { (String) browser, FIRST_WINDOWS_PARAMETER, SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, '"' + url + '"' }); // This avoids a memory leak on some versions of Java on Windows. // That's hinted at in <http://developer.java.sun.com/developer/qow/ // archive/68/>. try { process.waitFor(); process.exitValue(); } catch (InterruptedException ie) { throw new IOException("InterruptedException while launching browser: " + ie.getMessage()); } break; case OTHER: // Assume that we're on Unix and that Netscape is installed // First, attempt to open the URL in a currently running session of // Netscape String command = browser.toString() + " -raise " + NETSCAPE_REMOTE_PARAMETER + " " + NETSCAPE_OPEN_PARAMETER_START + url + NETSCAPE_OPEN_PARAMETER_END; process = Runtime.getRuntime().exec(command); try { int exitCode = process.waitFor(); if (exitCode != 0) { // if Netscape was not open Runtime.getRuntime().exec(new String[] { (String) browser, url }); } } catch (InterruptedException exception) { exception.printStackTrace(); throw new IOException("InterruptedException while launching browser: " + exception.getMessage()); } break; default: // This should never occur, but if it does, we'll try the simplest // thing possible Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; } }