List of usage examples for java.lang InterruptedException InterruptedException
public InterruptedException(String s)
InterruptedException
with the specified detail message. From source file:org.onecmdb.core.internal.job.workflow.sample.DirectoryImportProcess.java
@Override public void run() throws Throwable { this.terminate = false; for (String path : importPaths) { File pathFile = new File(path); if (!pathFile.isDirectory()) { log.warn("Path '" + path + "' is not a directory, will skip."); continue; }// w ww . j a v a 2 s. co m log.info("Process directory '" + path + "'"); File files[] = pathFile.listFiles(); for (File f : files) { if (terminate) { throw new InterruptedException("Iport operation interrupted"); } log.info("Process file '" + f.getName() + "' in directory '" + path + "'"); XmlParser xmlProvider = new XmlParser(); xmlProvider.setURL(f.toURL().toExternalForm()); // Process beans ProcessBeanProvider importBeans = new ProcessBeanProvider(); WorkflowParameter par = new WorkflowParameter(); par.put("provider", xmlProvider); par.put("validation", "false"); importBeans.setInParameter(par); importBeans.setRelevantData(data); importBeans.run(); // Commit BeanScope scope = (BeanScope) importBeans.getOutParameter().get("scope"); List<IRFC> rfcs = scope.getRFCs(); CommitRfcProcess commit = new CommitRfcProcess(); WorkflowParameter par1 = new WorkflowParameter(); System.out.println(rfcs.size() + " Rfc's generated "); par1.put("rfcs", rfcs); commit.setInParameter(par1); commit.setRelevantData(data); commit.run(); String ok = (String) commit.getOutParameter().get("ok"); String cause = (String) commit.getOutParameter().get("cause"); } } }
From source file:coolmap.application.io.internal.cmatrix.DoubleCMatrixImporter.java
@Override public CMatrix loadData(TFile matrixFolder, JSONObject matrixProperty) throws Exception { String id = matrixProperty.getString(IOTerm.ATTR_ID); String cls = matrixProperty.getString(IOTerm.ATTR_CLASS); String name = matrixProperty.optString(IOTerm.ATTR_NAME); int numColumn = matrixProperty.getInt(IOTerm.ATTR_CMATRIX_NUMCOLUMN); int numRow = matrixProperty.getInt(IOTerm.ATTR_CMATRIX_NUMROW); DoubleCMatrix matrix = new DoubleCMatrix(name, numRow, numColumn, id); //Then standard tsv BufferedReader reader = new BufferedReader(new InputStreamReader( new TFileInputStream(new TFile(matrixFolder + File.separator + IOTerm.FILE_DATA)))); String header = reader.readLine(); String[] ele = header.split("\t", -1); String[] colLabels = new String[ele.length - 1]; for (int i = 1; i < ele.length; i++) { colLabels[i - 1] = ele[i].trim(); }//from w ww . j ava2 s . c o m matrix.setColLabels(colLabels); String row; int counter = 0; Double value; while ((row = reader.readLine()) != null) { ele = row.split("\t"); matrix.setRowLabel(counter, ele[0]); for (int i = 1; i < ele.length; i++) { try { value = Double.parseDouble(ele[i]); } catch (Exception e) { value = null; } matrix.setValue(counter, i - 1, value); //Can consider return if (Thread.interrupted()) { throw new InterruptedException("Loading Operation Canceled"); } } counter++; } reader.close();//Close IO return matrix; }
From source file:org.marketcetera.util.except.ExceptUtils.java
/** * Checks whether the calling thread has been interrupted, and, if * so, throws an {@link InterruptedException} with the given * interruption message and the given underlying cause. The given * underlying cause is set on the thrown exception. The * interrupted status of the thread is cleared. * * @param cause The cause.// w w w .jav a 2 s .c o m * @param message The message. * * @throws InterruptedException Thrown if the calling thread * was interrupted. */ public static void checkInterruption(Throwable cause, String message) throws InterruptedException { if (Thread.currentThread().isInterrupted()) { InterruptedException ex = new InterruptedException(message); ex.initCause(cause); throw ex; } }
From source file:org.smartfrog.services.www.bulkio.client.SunJavaBulkIOClient.java
@Override public long doUpload(String method, long ioSize) throws IOException, InterruptedException { validateURL();/*from w w w . ja v a 2s . c o m*/ CRC32 checksum = new CRC32(); URL targetUrl = getUrl(); getLog().info("Uploading " + ioSize + " bytes to " + targetUrl); HttpURLConnection connection = openConnection(); connection.setRequestMethod(method); connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Long.toString(ioSize)); connection.setDoOutput(true); maybeSetChunking(connection); connection.connect(); OutputStream stream = connection.getOutputStream(); long bytes = 0; try { for (bytes = 0; bytes < ioSize; bytes++) { int octet = (AbstractBulkioServlet.getByteFromCounter(bytes)); stream.write(octet); checksum.update(octet); if (interrupted) { throw new InterruptedException( "Interrupted after sending " + bytes + " bytes" + " to " + targetUrl); } } } finally { closeQuietly(stream); } getLog().info("Upload complete, checking results"); checkStatusCode(targetUrl, connection, HttpURLConnection.HTTP_OK); long expectedChecksum = checksum.getValue(); getLog().info("Uploaded " + bytes + " bytes to " + targetUrl + " checksum=" + expectedChecksum); if (bytes != ioSize) { throw new IOException( "Wrong content length uploaded to " + targetUrl + " : put " + ioSize + " but got " + bytes); } if (parseResults) { InputStream inStream = null; Properties props = new Properties(); try { inStream = connection.getInputStream(); props.load(inStream); } finally { closeQuietly(inStream); } long actualChecksum = getLongPropValue(props, IoAttributes.CHECKSUM); if (actualChecksum != expectedChecksum) { throw new IOException("Expected the checksum from upload of " + ioSize + " bytes " + " to " + targetUrl + "to be " + expectedChecksum + " but got " + actualChecksum + "\n Properties: " + props.toString()); } } return ioSize; }
From source file:com.spotify.helios.servicescommon.PersistentAtomicReference.java
private PersistentAtomicReference(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { try {// w w w . j ava 2 s. c o m this.filename = filename.toAbsolutePath(); this.tempfilename = filename.getFileSystem().getPath(this.filename.toString() + ".tmp"); if (Files.exists(filename)) { final byte[] bytes = Files.readAllBytes(filename); if (bytes.length > 0) { value = Json.read(bytes, javaType); } else { value = initialValue.get(); } } else { value = initialValue.get(); } } catch (InterruptedIOException | ClosedByInterruptException e) { throw new InterruptedException(e.getMessage()); } }
From source file:com.baidu.asynchttpclient.AsyncHttpRequest.java
private void makeRequest() throws IOException { if (!Thread.currentThread().isInterrupted()) { updateNetProxy();/*from www . ja va2 s . com*/ HttpResponse response = client.execute(request, context); if (!Thread.currentThread().isInterrupted()) { if (responseHandler != null) { responseHandler.sendResponseMessage(response); } } // else { // responseHandler.sendFailureMessage(new InterruptedException("request interupted!"), null); // TODO: should raise InterruptedException? this block is reached whenever the request is cancelled // before its response is received // } } else { responseHandler.sendFailureMessage(new InterruptedException("request interupted!"), null); } }
From source file:org.openscore.worker.management.services.OutboundBufferImpl.java
@Override public void put(final Message... messages) throws InterruptedException { Validate.notEmpty(messages, "The array of messages is null or empty"); try {//ww w . j ava2 s.co m syncManager.startPutMessages(); //We need to check if the current thread was interrupted while waiting for the lock (ExecutionThread or InBufferThread in ackMessages) if (Thread.currentThread().isInterrupted()) { throw new InterruptedException("Thread was interrupted while waiting on the lock! Exiting..."); } while (currentWeight >= maxBufferWeight) { logger.warn("Outbound buffer is full. Waiting..."); syncManager.waitForDrain(); } // in case of multiple messages create a single compound message // to make sure that it will be processed in a single transaction Message message = messages.length == 1 ? messages[0] : new CompoundMessage(messages); //put message into the buffer buffer.add(message); currentWeight += message.getWeight(); if (logger.isTraceEnabled()) logger.trace(message.getClass().getSimpleName() + " added to the buffer. " + getStatus()); } catch (InterruptedException ex) { logger.warn("Buffer put action was interrupted", ex); throw ex; } finally { syncManager.finishPutMessages(); } }
From source file:org.apache.hadoop.util.zookeeper.ZooKeeperImpl.java
public void waitForConnection() throws InterruptedException { if (isCurrentThreadEventThread()) { throw new RuntimeException( "waitForConnection should not be called from within the ZooKeeper event thread."); }/*from w ww .ja v a 2 s . c om*/ synchronized (connectedMonitor) { while (!connected && !stop) { connectedMonitor.wait(); } } if (stop) { throw new InterruptedException("This ZooKeeper handle is shutting down."); } }
From source file:MainClass.java
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Running long running operation", indeterminate ? IProgressMonitor.UNKNOWN : TOTAL_TIME); for (int total = 0; total < TOTAL_TIME && !monitor.isCanceled(); total += INCREMENT) { Thread.sleep(INCREMENT);// ww w . j a v a 2 s . c om monitor.worked(INCREMENT); if (total == TOTAL_TIME / 2) monitor.subTask("Doing second half"); } monitor.done(); if (monitor.isCanceled()) throw new InterruptedException("The long running operation was cancelled"); }
From source file:BlockingQueue.java
/** * Pops an element from the queue. Unlike the pop() method, this method does not block * for longer than the given amount of milliseconds. When the given amount of milliseconds * have passed, this method will throw an InterruptedException. *//*from w w w . j a v a 2 s . com*/ public Object pop(long timeout) throws InterruptedException { synchronized (popLock) { synchronized (this) { if (queue.isEmpty()) { wait(timeout); if (queue.isEmpty()) throw new InterruptedException("Timed out"); } } Object val = queue.firstElement(); queue.removeElementAt(0); return val; } }