List of usage examples for java.lang InterruptedException getMessage
public String getMessage()
From source file:com.microsoftopentechnologies.azure.remote.AzureSSHLauncher.java
private void copyFileToRemote(Session jschSession, InputStream stream, String remotePath) throws Exception { LOGGER.info("AzureSSHLauncher: copyFileToRemote: Initiating file transfer to " + remotePath); ChannelSftp sftpChannel = null;//w ww. j av a 2s.c o m try { sftpChannel = (ChannelSftp) jschSession.openChannel("sftp"); sftpChannel.connect(); sftpChannel.put(stream, remotePath); if (!sftpChannel.isClosed()) { try { LOGGER.warning( "AzureSSHLauncher: copyFileToRemote: Channel is not yet closed , waiting for 10 seconds"); Thread.sleep(10 * 1000); } catch (InterruptedException e) { //ignore error } } LOGGER.info("AzureSSHLauncher: copyFileToRemote: copied file Successfully to " + remotePath); } catch (Exception e) { e.printStackTrace(); LOGGER.severe("AzureSSHLauncher: copyFileToRemote: Error occurred while copying file to remote host " + e.getMessage()); throw e; } finally { try { if (sftpChannel != null) sftpChannel.disconnect(); } catch (Exception e) { // ignore silently } } }
From source file:com.yi4all.rupics.ImageDetailActivity.java
public void startSlideShow() { Runnable slide = new Runnable() { @Override/*from w ww . j av a 2 s .c o m*/ public void run() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, LOGTAG); wl.acquire(); while (isSlideshow) { if (imageSequence < imgList.size() - 1) { // back to the next image imageSequence++; setCurrentPage(); } else { // give a tip to user Utils.toastMsg(ImageDetailActivity.this, R.string.alreadyLast); isSlideshow = false; } try { Thread.sleep(2000); } catch (InterruptedException e) { Log.e(LOGTAG, "startSlideShow:" + ((e != null) ? e.getMessage() : "exception is null")); } // if(ImageDetailActivity.this.) } if (wl.isHeld()) wl.release(); } }; new Thread(slide).start(); }
From source file:com.mnxfst.testing.client.TSClient.java
/** * Collects results of previously started tests * @param hostResultIdentifierMapping/*from w ww . j a v a 2 s. com*/ * @param port * @return */ protected Set<TSClientPlanExecutionResult> collectTestplanResults( Map<String, String> hostResultIdentifierMapping, int port) { TSClientPlanResultCollectCallable[] callables = new TSClientPlanResultCollectCallable[hostResultIdentifierMapping .size()]; int count = 0; String uri = null; for (String host : hostResultIdentifierMapping.keySet()) { uri = "/?" + REQUEST_PARAMETER_COLLECT + "=1&" + REQUEST_PARAMETER_RESULT_IDENTIFIER + "=" + hostResultIdentifierMapping.get(host); callables[count] = new TSClientPlanResultCollectCallable(host, port, uri); count = count + 1; } ExecutorService executorService = Executors.newFixedThreadPool(hostResultIdentifierMapping.size()); List<Future<TSClientPlanExecutionResult>> collectedResults = new ArrayList<Future<TSClientPlanExecutionResult>>(); try { collectedResults = executorService.invokeAll(Arrays.asList(callables)); } catch (InterruptedException e) { System.out.println("Test execution result collection interrupted: " + e.getMessage()); } Set<TSClientPlanExecutionResult> result = new HashSet<TSClientPlanExecutionResult>(); for (Future<TSClientPlanExecutionResult> r : collectedResults) { try { result.add(r.get()); } catch (InterruptedException e) { System.out.println("Interrupted while collection results: " + e.getMessage()); } catch (ExecutionException e) { System.out.println("Interrupted while collection results: " + e.getMessage()); } } return result; }
From source file:it.unibo.arces.wot.sepa.engine.protocol.HTTPGate.java
@Override public void run() { try {// ww w .jav a 2 s. c om updateServer.wait(); queryServer.wait(); } catch (InterruptedException e) { logger.info(e.getMessage()); } }
From source file:com.tito.easyyarn.appmaster.ApplicationMaster.java
@VisibleForTesting protected boolean finish() { // wait for completion. LOG.info("(!done " + (!done)); LOG.info("!hasCompleted()" + (!hasCompleted())); while (!done && !hasCompleted()) { try {//from w ww . jav a 2 s . c o m if (currentPhase == null) { if (!pendingPhases.isEmpty()) { currentPhase = pendingPhases.poll(); currentPhase.setPassedArguments(passedArguments); Thread phaseThread = new Thread(currentPhase); phaseThreads.add(phaseThread); LOG.info("Starting First Phase:" + currentPhase.getId()); phaseThread.start(); } else { LOG.error("NO Phases Registered , aborting phase execution"); done = true; } continue; } PhaseStatus currentPhaseStatus = currentPhase.getPhaseStatus(); if (currentPhaseStatus != null && currentPhaseStatus != PhaseStatus.RUNNING && currentPhaseStatus != PhaseStatus.PENDING) { LOG.info("currentPhase.getPhaseStatus()" + currentPhaseStatus); if (currentPhaseStatus == PhaseStatus.SUCCESSED) { LOG.info("Phase Completed successfully : " + currentPhase.getId()); completedPhases.add(currentPhase); // check to see if any pending phases start them if (pendingPhases.isEmpty()) { LOG.info("No More Phases remaining"); done = true; } if (!pendingPhases.isEmpty()) { currentPhase = pendingPhases.poll(); currentPhase.setPassedArguments(passedArguments); Thread phaseThread = new Thread(currentPhase); phaseThreads.add(phaseThread); phaseThread.start(); } } // phase failed else { failedPhases.add(currentPhase); done = true; } } Thread.sleep(1000); } catch (InterruptedException ex) { } } // Join all launched threads // needed for when we time out // and we need to release containers for (Thread phaseThread : phaseThreads) { try { phaseThread.join(10000); } catch (InterruptedException e) { LOG.info("Exception thrown in thread join: " + e.getMessage()); e.printStackTrace(); } } // When the application completes, it should stop all running containers LOG.info("Application completed. Stopping running containers"); nmClientAsync.stop(); // When the application completes, it should send a finish application // signal to the RM LOG.info("Application completed. Signalling finish to RM"); FinalApplicationStatus appStatus; String appMessage = null; boolean success = true; LOG.info("hasCompletedSuccessfully():" + hasCompletedSuccessfully()); LOG.info("completedPhases.size():" + completedPhases.size()); LOG.info("phaseList.size():" + phaseList.size()); LOG.info("+failedPhases.size():" + failedPhases.size()); if (hasCompletedSuccessfully()) { appStatus = FinalApplicationStatus.SUCCEEDED; } else { appStatus = FinalApplicationStatus.FAILED; appMessage = "Diagnostics." + ", total Phases=" + phaseList.size() + ", completed=" + completedPhases.size() + ", failed=" + failedPhases.size(); success = false; } try { amRMClient.unregisterApplicationMaster(appStatus, appMessage, null); } catch (YarnException ex) { LOG.error("Failed to unregister application", ex); } catch (IOException e) { LOG.error("Failed to unregister application", e); } amRMClient.stop(); return success; }
From source file:org.apache.manifoldcf.authorities.authorities.generic.GenericAuthority.java
/** * Check connection for sanity.//from www . j av a 2s. c o m */ @Override public String check() throws ManifoldCFException { HttpClient client = getClient(); try { CheckThread checkThread = new CheckThread(client, genericEntryPoint + "?" + ACTION_PARAM_NAME + "=" + ACTION_CHECK); checkThread.start(); checkThread.join(); if (checkThread.getException() != null) { Throwable thr = checkThread.getException(); return "Check exception: " + thr.getMessage(); } return checkThread.getResult(); } catch (InterruptedException ex) { throw new ManifoldCFException(ex.getMessage(), ex, ManifoldCFException.INTERRUPTED); } }
From source file:net.mozq.picto.core.ProcessCore.java
public static void processFiles(ProcessCondition processCondition, Function<Integer, ProcessData> processDataGetter, IntConsumer processDataUpdater, Function<ProcessData, ProcessDataStatus> overwriteConfirm, BooleanSupplier processStopper) throws IOException { int index = 0; while (!processStopper.getAsBoolean()) { ProcessData processData = processDataGetter.apply(index); if (processData == null) { try { Thread.sleep(100); } catch (InterruptedException e) { // NOP }//from w w w . java 2s .c o m continue; } processData.setStatus(ProcessDataStatus.Processing); processDataUpdater.accept(index); ProcessDataStatus status; try { if (processCondition.isDryRun()) { // NOP status = ProcessDataStatus.Success; } else { status = process(processCondition, processData, overwriteConfirm); } processData.setStatus(status); } catch (Exception e) { processData.setStatus(ProcessDataStatus.Error); processData.setMessage(e.getLocalizedMessage()); App.handleWarn(e.getMessage(), e); } processDataUpdater.accept(index); if (processData.getStatus() == ProcessDataStatus.Error || processData.getStatus() == ProcessDataStatus.Terminated) { break; } index++; } }
From source file:org.grails.datastore.mapping.gemfire.engine.GemfireEntityPersister.java
@Override public Object lock(final Serializable id, final int timeout) throws CannotAcquireLockException { final GemfireTemplate template = gemfireDatastore.getTemplate(getPersistentEntity()); return template.execute(new GemfireCallback() { public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { final Lock lock = region.getDistributedLock(id); try { if (lock.tryLock(timeout, TimeUnit.SECONDS)) { final Object o = region.get(id); distributedLocksHeld.put(o, lock); return o; }/*from ww w .j a va2s .com*/ throw new CannotAcquireLockException("Timeout acquiring Gemfire lock on object type [" + getPersistentEntity() + "] with identifier [" + id + "]"); } catch (InterruptedException e) { throw new CannotAcquireLockException("Cannot acquire Gemfire lock on object type [" + getPersistentEntity() + "] with identifier [" + id + "]: " + e.getMessage(), e); } } }); }
From source file:org.apache.axis2.transport.http.HTTPWorker.java
public void service(final AxisHttpRequest request, final AxisHttpResponse response, final MessageContext msgContext) throws HttpException, IOException { ConfigurationContext configurationContext = msgContext.getConfigurationContext(); final String servicePath = configurationContext.getServiceContextPath(); final String contextPath = (servicePath.startsWith("/") ? servicePath : "/" + servicePath) + "/"; String uri = request.getRequestURI(); String method = request.getMethod(); String soapAction = HttpUtils.getSoapAction(request); InvocationResponse pi;// ww w .j a v a2s . c o m if (method.equals(HTTPConstants.HEADER_GET)) { if (uri.equals("/favicon.ico")) { response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY); response.addHeader(new BasicHeader("Location", "http://ws.apache.org/favicon.ico")); return; } if (!uri.startsWith(contextPath)) { response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY); response.addHeader(new BasicHeader("Location", contextPath)); return; } if (uri.endsWith("axis2/services/")) { String s = HTTPTransportReceiver.getServicesHTML(configurationContext); response.setStatus(HttpStatus.SC_OK); response.setContentType("text/html"); OutputStream out = response.getOutputStream(); out.write(EncodingUtils.getBytes(s, HTTP.ISO_8859_1)); return; } if (uri.indexOf("?") < 0) { if (!uri.endsWith(contextPath)) { if (uri.endsWith(".xsd") || uri.endsWith(".wsdl")) { HashMap services = configurationContext.getAxisConfiguration().getServices(); String file = uri.substring(uri.lastIndexOf("/") + 1, uri.length()); if ((services != null) && !services.isEmpty()) { Iterator i = services.values().iterator(); while (i.hasNext()) { AxisService service = (AxisService) i.next(); InputStream stream = service.getClassLoader() .getResourceAsStream("META-INF/" + file); if (stream != null) { OutputStream out = response.getOutputStream(); response.setContentType("text/xml"); ListingAgent.copy(stream, out); out.flush(); out.close(); return; } } } } } } if (uri.endsWith("?wsdl2")) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 6); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); service.printWSDL2(response.getOutputStream(), getHost(request)); } else { response.setStatus(HttpStatus.SC_FORBIDDEN); } return; } } if (uri.endsWith("?wsdl")) { /** * service name can be hierarchical (axis2/services/foo/1.0.0/Version?wsdl) or * normal (axis2/services/Version?wsdl). */ String[] temp = uri.split(configurationContext.getServiceContextPath() + "/"); String serviceName = temp[1].substring(0, temp[1].length() - 5); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); service.printWSDL(response.getOutputStream(), getHost(request)); } else { response.setStatus(HttpStatus.SC_FORBIDDEN); } return; } } if (uri.endsWith("?xsd")) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); service.printSchema(response.getOutputStream()); } else { response.setStatus(HttpStatus.SC_FORBIDDEN); } return; } } //cater for named xsds - check for the xsd name if (uri.indexOf("?xsd=") > 0) { // fix for imported schemas String[] uriParts = uri.split("[?]xsd="); String serviceName = uri.substring(uriParts[0].lastIndexOf("/") + 1, uriParts[0].length()); String schemaName = uri.substring(uri.lastIndexOf("=") + 1); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (!canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_FORBIDDEN); return; } //run the population logic just to be sure service.populateSchemaMappings(); //write out the correct schema Map schemaTable = service.getSchemaMappingTable(); XmlSchema schema = (XmlSchema) schemaTable.get(schemaName); if (schema == null) { int dotIndex = schemaName.indexOf('.'); if (dotIndex > 0) { String schemaKey = schemaName.substring(0, dotIndex); schema = (XmlSchema) schemaTable.get(schemaKey); } } //schema found - write it to the stream if (schema != null) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); schema.write(response.getOutputStream()); return; } else { InputStream instream = service.getClassLoader() .getResourceAsStream(DeploymentConstants.META_INF + "/" + schemaName); if (instream != null) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); OutputStream outstream = response.getOutputStream(); boolean checkLength = true; int length = Integer.MAX_VALUE; int nextValue = instream.read(); if (checkLength) length--; while (-1 != nextValue && length >= 0) { outstream.write(nextValue); nextValue = instream.read(); if (checkLength) length--; } outstream.flush(); return; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int ret = service.printXSD(baos, schemaName); if (ret > 0) { baos.flush(); instream = new ByteArrayInputStream(baos.toByteArray()); response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); OutputStream outstream = response.getOutputStream(); boolean checkLength = true; int length = Integer.MAX_VALUE; int nextValue = instream.read(); if (checkLength) length--; while (-1 != nextValue && length >= 0) { outstream.write(nextValue); nextValue = instream.read(); if (checkLength) length--; } outstream.flush(); return; } // no schema available by that name - send 404 response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!"); return; } } } } if (uri.indexOf("?wsdl2=") > 0) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl2=")); if (processInternalWSDL(uri, configurationContext, serviceName, response, getHost(request))) return; } if (uri.indexOf("?wsdl=") > 0) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl=")); if (processInternalWSDL(uri, configurationContext, serviceName, response, getHost(request))) return; } String contentType = null; Header[] headers = request.getHeaders(HTTPConstants.HEADER_CONTENT_TYPE); if (headers != null && headers.length > 0) { contentType = headers[0].getValue(); int index = contentType.indexOf(';'); if (index > 0) { contentType = contentType.substring(0, index); } } // deal with GET request pi = RESTUtil.processURLRequest(msgContext, response.getOutputStream(), contentType); } else if (method.equals(HTTPConstants.HEADER_POST)) { // deal with POST request String contentType = request.getContentType(); if (HTTPTransportUtils.isRESTRequest(contentType)) { pi = RESTUtil.processXMLRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType); } else { String ip = (String) msgContext.getProperty(MessageContext.TRANSPORT_ADDR); if (ip != null) { uri = ip + uri; } pi = HTTPTransportUtils.processHTTPPostRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType, soapAction, uri); } } else if (method.equals(HTTPConstants.HEADER_PUT)) { String contentType = request.getContentType(); msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType); pi = RESTUtil.processXMLRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType); } else if (method.equals(HTTPConstants.HEADER_DELETE)) { pi = RESTUtil.processURLRequest(msgContext, response.getOutputStream(), null); } else { throw new MethodNotSupportedException(method + " method not supported"); } Boolean holdResponse = (Boolean) msgContext.getProperty(RequestResponseTransport.HOLD_RESPONSE); if (pi.equals(InvocationResponse.SUSPEND) || (holdResponse != null && Boolean.TRUE.equals(holdResponse))) { try { ((RequestResponseTransport) msgContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL)) .awaitResponse(); } catch (InterruptedException e) { throw new IOException("We were interrupted, so this may not function correctly:" + e.getMessage()); } } // Finalize response RequestResponseTransport requestResponseTransportControl = (RequestResponseTransport) msgContext .getProperty(RequestResponseTransport.TRANSPORT_CONTROL); if (TransportUtils.isResponseWritten(msgContext) || ((requestResponseTransportControl != null) && requestResponseTransportControl.getStatus() .equals(RequestResponseTransport.RequestResponseTransportStatus.SIGNALLED))) { // The response is written or signalled. The current status is used (probably SC_OK). } else { // The response may be ack'd, mark the status as accepted. response.setStatus(HttpStatus.SC_ACCEPTED); } }
From source file:com.opengamma.engine.cache.BerkeleyDBValueIdentifierMapTest.java
@Test(timeOut = 30000) public void interruptThread() throws Throwable { final ExecutorService threads = Executors.newSingleThreadExecutor(); try {//from ww w. ja v a 2 s . c o m final Thread main = Thread.currentThread(); final Runnable interrupter = new Runnable() { @Override public void run() { try { Thread.sleep(1000); main.interrupt(); } catch (InterruptedException e) { throw new OpenGammaRuntimeException("Interrupted", e); } } }; threads.submit(interrupter); int count = 0; do { try { getPerformanceTest(); } catch (OpenGammaRuntimeException e) { assertEquals("Interrupted", e.getMessage()); count++; if (count <= 5) { threads.submit(interrupter); } else { break; } } } while (true); } finally { threads.shutdown(); Thread.interrupted(); threads.awaitTermination(5, TimeUnit.SECONDS); } }