Example usage for java.lang InterruptedException InterruptedException

List of usage examples for java.lang InterruptedException InterruptedException

Introduction

In this page you can find the example usage for java.lang InterruptedException InterruptedException.

Prototype

public InterruptedException(String s) 

Source Link

Document

Constructs an InterruptedException with the specified detail message.

Usage

From source file:com.flipkart.poseidon.serviceclients.FutureTaskResultToDomainObjectPromiseWrapper.java

@Override
public void await() throws InterruptedException {
    try {//from   w w  w  .j  a  v a2 s.c  om
        for (Future<TaskResult> future : futureList) {
            future.get();
        }
    } catch (ExecutionException exception) {
        promiseBrokenException = new PromiseBrokenException(exception);
        throw new InterruptedException(exception.getMessage());
    } catch (CancellationException exception) {
        promiseBrokenException = new PromiseBrokenException(exception);
    }

}

From source file:io.cloudslang.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 {/*from   w  ww  .ja v  a  2  s .  c om*/
        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...");
        } else {
            if (logger.isDebugEnabled())
                logger.debug("Current thread was not interrupted! Proceeding to put messages to OutBuffer...");
        }

        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:com.spotify.helios.servicescommon.PersistentAtomicReference.java

/**
 * Set the reference to {@code newValue}.
 *
 * @param newValue The value to set./*from   w  w w.  j  a  v  a2s  . c  om*/
 * @throws IOException If an error occurs working with the file on disk.
 * @throws InterruptedException If the thread is interrupted.
 */
public void set(T newValue) throws IOException, InterruptedException {
    try {
        set0(newValue);
    } catch (InterruptedIOException | ClosedByInterruptException e) {
        throw new InterruptedException(e.getMessage());
    }
}

From source file:com.chicm.cmraft.util.CappedPriorityBlockingQueue.java

public E poll(long timeout, TimeUnit unit) throws InterruptedException {
    InterruptedException e = new InterruptedException("poll is not supported, please use take");
    LOG.error("poll is not supported, please use take", e);
    throw e;/*from  w w  w  .  j  a  v  a 2 s .  c  o m*/
}

From source file:com.ngdata.sep.util.zookeeper.ZooKeeperImpl.java

@Override
public void waitForConnection() throws InterruptedException {
    if (isCurrentThreadEventThread()) {
        throw new RuntimeException(
                "waitForConnection should not be called from within the ZooKeeper event thread.");
    }/*  ww w  . j  a va 2 s  .c o m*/

    synchronized (connectedMonitor) {
        while (!connected && !stop) {
            connectedMonitor.wait();
        }
    }

    if (stop) {
        throw new InterruptedException("This ZooKeeper handle is shutting down.");
    }
}

From source file:org.alfresco.extension.bulkfilesystemimport.impl.DirectoryAnalyserImpl.java

/**
 * @see org.alfresco.extension.bulkfilesystemimport.DirectoryAnalyser#analyseDirectory(java.io.File)
 *//* w  w w  .ja  va2s. c  om*/
public AnalysedDirectory analyseDirectory(final File directory) throws InterruptedException {
    final AnalysedDirectory result = new AnalysedDirectory();
    final Map<File, ImportableItem> importableItems = new HashMap<File, ImportableItem>();
    long start;
    long end;

    if (log.isDebugEnabled())
        log.debug("Analysing directory " + AbstractBulkFilesystemImporter.getFileName(directory) + "...");

    start = System.nanoTime();
    result.originalListing = Arrays.asList(directory.listFiles());
    end = System.nanoTime();
    if (log.isTraceEnabled())
        log.trace("List directory took: " + (float) (end - start) / (1000 * 1000 * 1000) + "s");

    // Build up the list of ImportableItems from the directory listing
    start = System.nanoTime();
    for (final File file : result.originalListing) {
        if (importStatus.isStopping() || Thread.currentThread().isInterrupted())
            throw new InterruptedException(
                    Thread.currentThread().getName() + " was interrupted.  Terminating early.");

        if (file.canRead()) {
            if (isVersionFile(file)) {
                addVersionFile(importableItems, file);
                importStatus.incrementNumberOfFilesScanned();
            } else if (isMetadataFile(file)) {
                addMetadataFile(importableItems, file);
                importStatus.incrementNumberOfFilesScanned();
            } else {
                boolean isDirectory = addParentFile(importableItems, file);

                if (isDirectory) {
                    importStatus.incrementNumberOfFoldersScanned();
                } else {
                    importStatus.incrementNumberOfFilesScanned();
                }
            }
        } else {
            if (log.isWarnEnabled())
                log.warn("Skipping unreadable file/directory '"
                        + AbstractBulkFilesystemImporter.getFileName(file) + "'.");

            importStatus.incrementNumberOfUnreadableEntries();
        }
    }
    end = System.nanoTime();
    if (log.isTraceEnabled())
        log.trace("Build list of importable items took: " + (float) (end - start) / (1000 * 1000 * 1000) + "s");

    result.importableItems = new ArrayList<ImportableItem>(importableItems.values());

    // Finally, remove any items from the list that aren't valid
    start = System.nanoTime();
    Iterator<ImportableItem> iter = result.importableItems.iterator();

    while (iter.hasNext()) {
        ImportableItem importableItem = iter.next();

        if (!importableItem.isValid()) {
            iter.remove();
        }
    }

    end = System.nanoTime();
    if (log.isTraceEnabled())
        log.trace(
                "Filter invalid importable items took: " + (float) (end - start) / (1000 * 1000 * 1000) + "s");

    if (log.isDebugEnabled())
        log.debug(
                "Finished analysing directory " + AbstractBulkFilesystemImporter.getFileName(directory) + ".");

    return (result);
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.DownloadCallable.java

@Override
public Void invoke(final File workspace, final VirtualChannel channel) throws InterruptedException {
    clearWorkspaceIfSelected(workspace, listener);

    final AWSClients awsClients = awsClientFactory.getAwsClient(model.getAwsAccessKey(),
            model.getAwsSecretKey(), model.getProxyHost(), model.getProxyPort(), model.getRegion(),
            pluginUserAgentPrefix);// www  .  j  a v a 2 s .  c  o  m

    final AWSCodePipelineJobCredentialsProvider credentialsProvider = new AWSCodePipelineJobCredentialsProvider(
            job.getId(), awsClients.getCodePipelineClient());
    final AmazonS3 s3Client = awsClients.getS3Client(credentialsProvider);

    for (final Artifact artifact : job.getData().getInputArtifacts()) {
        final S3Object sessionObject = getS3Object(s3Client, artifact);

        model.setCompressionType(ExtractionTools.getCompressionType(sessionObject, listener));

        final String downloadedFileName = Paths.get(sessionObject.getKey()).getFileName().toString();

        try {
            downloadAndExtract(sessionObject, workspace, downloadedFileName, listener);
        } catch (final Exception ex) {
            final String error = "Failed to acquire artifacts: " + ex.getMessage();
            LoggingHelper.log(listener, error);
            LoggingHelper.log(listener, ex);

            throw new InterruptedException(error);
        }
    }

    return null;
}

From source file:com.flipkart.poseidon.serviceclients.FutureTaskResultToDomainObjectPromiseWrapper.java

@Override
public void await(long timeout, TimeUnit timeUnit) throws InterruptedException {
    try {/*from   w  ww  .  j  ava 2 s .  c om*/
        for (Future<TaskResult> future : futureList) {
            future.get(timeout, timeUnit);
        }
    } catch (ExecutionException exception) {
        promiseBrokenException = new PromiseBrokenException(exception);
        throw new InterruptedException(exception.getMessage());
    } catch (CancellationException exception) {
        promiseBrokenException = new PromiseBrokenException(exception);
    } catch (TimeoutException ignored) {
    }
}

From source file:org.tdl.vireo.search.impl.LuceneAbstractJobImpl.java

/**
 * Start an index job./*from   w w w. j a v a2 s . co m*/
 * 
 * This method handles the exceptions
 */
public void doJob() {
    try {
        if (cancel) {
            throw new InterruptedException("Lucene '" + this.getLabel()
                    + "' job recieved a cancel request before begining processing.");
        }

        long start = System.currentTimeMillis();

        writeIndex();

        Logger.debug("Lucene '" + this.getLabel() + "' job processed " + total
                + " submissions completed succesfully in " + ((System.currentTimeMillis() - start) / 1000F)
                + " seconds.");

        // If we successfully finished, then the index is no longer corrupted.
        indexer.corruptIndex = false;

    } catch (CorruptIndexException cie) {

        // Attempt to automaticall rebuild the index without intervention. To prevent infinate loops we will only rebuild a maximum of 5 times.
        if (!indexer.corruptIndex) {
            Logger.error(cie,
                    "Lucene is unable to update index because it is corrupted, attempting to recover by rebuilding the index.");

            ErrorLog errorLog = Spring.getBeanOfType(ErrorLog.class);
            errorLog.logError(cie, "Updating search index");

            indexer.deleteAndRebuild(false);
            cancel = true;

        } else {
            Logger.fatal(cie,
                    "Lucene's attempt to rebuild a corrupted index has failed. No further attempts will be made, and searching is disabled.");

            ErrorLog errorLog = Spring.getBeanOfType(ErrorLog.class);
            errorLog.logError(cie, "Updating search index");
        }
        throw new RuntimeException(cie);

    } catch (LockObtainFailedException lofe) {
        Logger.error(lofe,
                "Lucene is unable to update search index because it is being locked by another process.");

        ErrorLog errorLog = Spring.getBeanOfType(ErrorLog.class);
        errorLog.logError(lofe, "Updating search index");

        throw new RuntimeException(lofe);

    } catch (IOException ioe) {
        Logger.error(ioe, "Lucene is unable to update search index because of IO exception.");

        ErrorLog errorLog = Spring.getBeanOfType(ErrorLog.class);
        errorLog.logError(ioe, "Updating search index");

        throw new RuntimeException(ioe);
    } catch (InterruptedException ie) {
        // We were asked to stop.
        Logger.info(ie.getMessage());
    } finally {
        // If we were cancled don't start the next job.
        if (!cancel)
            indexer.runNextJob(null);
    }
}

From source file:ShowProgress.java

/**
 * Runs the long running operation/*  w w  w  . j a v a  2 s  .  co m*/
 * 
 * @param monitor the progress monitor
 */
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);
        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");
}