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() 

Source Link

Document

Constructs an InterruptedException with no detail message.

Usage

From source file:de.bmarwell.j9kwsolver.action.CaptchaSolveThread.java

@Override
public final CaptchaSolutionResponse call() throws Exception {
    CaptchaSolutionResponse solveCaptcha = null;

    if (!isValidSolution()) {
        LOG.debug("Solution cannot be valid at all!");
        return null;
    }//w w w.ja v a 2  s  . c o m

    if (Thread.currentThread().isInterrupted()) {
        throw new InterruptedException();
    }

    solveCaptcha = solveCaptcha();

    return solveCaptcha;
}

From source file:savant.data.sources.BAMDataSource.java

@Override
public List<BAMIntervalRecord> getRecords(String reference, RangeAdapter range, Resolution resolution,
        RecordFilterAdapter filt) throws InterruptedException {

    SAMRecordIterator recordIterator = null;
    List<BAMIntervalRecord> result = new ArrayList<BAMIntervalRecord>();
    try {//  www  .  j av a 2 s  .  c  o m
        // todo: actually use the given reference

        String ref;
        if (getReferenceNames().contains(reference)) {
            ref = reference;
        } else if (getReferenceNames().contains(MiscUtils.homogenizeSequence(reference))) {
            ref = MiscUtils.homogenizeSequence(reference);
        } else {
            ref = guessSequence();
        }

        recordIterator = samFileReader.query(ref, range.getFrom(), range.getTo(), false);

        SAMRecord samRecord;
        BAMIntervalRecord record;
        while (recordIterator.hasNext()) {

            samRecord = recordIterator.next();

            // Don't keep unmapped reads
            if (samRecord.getReadUnmappedFlag()) {
                continue;
            }

            record = BAMIntervalRecord.valueOf(samRecord);
            if (filt == null || filt.accept(record)) {
                result.add(record);
            }
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
        }
    } finally {
        if (recordIterator != null) {
            recordIterator.close();
        }
    }

    return result;
}

From source file:org.ut.biolab.medsavant.client.util.MedSavantWorker.java

public void done() {
    if (this.progressTimer != null) {
        this.progressTimer.stop();
    }/*from   ww  w.  ja  v a 2s  .c o m*/
    showProgress(1.0);
    try {
        if (!swingWorker.isCancelled()) {
            showSuccess(swingWorker.get());
        } else {
            // Send the server one last checkProgress call so that server knows that we've cancelled.
            try {
                checkProgress();
            } catch (Exception ex) {
                LOG.info("Ignoring exception thrown while cancelling.", ex);
            }
            throw new InterruptedException();
        }
    } catch (InterruptedException x) {
        showFailure(x);
    } catch (ExecutionException x) {
        showFailure(x.getCause());
    } finally {
        // Succeed or fail, we want to remove the worker from our page.
        ThreadController.getInstance().removeWorker(this.pageName, this);
    }
}

From source file:org.roda_project.commons_ip.model.impl.eark.EARKUtils.java

protected static void addPreservationMetadataToZipAndMETS(Map<String, ZipEntryInfo> zipEntries,
        MetsWrapper metsWrapper, List<IPMetadata> preservationMetadata, String representationId)
        throws IPException, InterruptedException {
    if (preservationMetadata != null && !preservationMetadata.isEmpty()) {
        for (IPMetadata pm : preservationMetadata) {
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }/*from www  .  j a v  a  2s .  c om*/
            IPFile file = pm.getMetadata();

            String preservationMetadataPath = IPConstants.PRESERVATION_FOLDER
                    + ModelUtils.getFoldersFromList(file.getRelativeFolders()) + file.getFileName();
            MdRef mdRef = EARKMETSUtils.addPreservationMetadataToMETS(metsWrapper, pm,
                    preservationMetadataPath);

            if (representationId != null) {
                preservationMetadataPath = IPConstants.REPRESENTATIONS_FOLDER + representationId
                        + IPConstants.ZIP_PATH_SEPARATOR + preservationMetadataPath;
            }
            ZIPUtils.addMdRefFileToZip(zipEntries, file.getPath(), preservationMetadataPath, mdRef);
        }
    }
}

From source file:com.beetle.framework.util.OtherUtil.java

/**
 * ?sleep?object.wait/*from w w  w  .  ja  v a  2s .c  o  m*/
 * 
 * @param lockObj
 *            ?
 * @param sometime
 *            ??
 * @throws InterruptedException
 */
public static final void blockSomeTime(final Object lockObj, long sometime) throws InterruptedException {
    if (Thread.interrupted())
        throw new InterruptedException();
    synchronized (lockObj) {
        long waitTime = sometime;
        long start = System.currentTimeMillis();
        try {
            for (;;) {
                lockObj.wait(waitTime);
                waitTime = sometime - (System.currentTimeMillis() - start);
                if (waitTime <= 0) {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            lockObj.notify();
            throw ex;
        }
    }
}

From source file:org.ut.biolab.medsavant.server.MedSavantServerUnicastRemoteObject.java

/**
 * Called by server-side code to update the progress for the given session, also checking for cancellation.
 * @param frac the progress from 0.01.0; 0.0 resets the progress, 1.0 indicates that it is finished, -1.0 indicates an indeterminate task
 *//*from   w  w  w. j ava 2  s . com*/
protected void makeProgress(String sessID, String msg, double frac) throws InterruptedException {
    synchronized (sessionProgresses) {

        if (frac == 0.0) {
            // As a side-effect, progress 0.0 always clears the cancelled flag.
            sessionProgresses.put(sessID, new ProgressStatus(msg, frac));
        } else {
            ProgressStatus status = sessionProgresses.get(sessID);
            if (status == ProgressStatus.CANCELLED) {
                LOG.info("Operation cancelled by user.");
                throw new InterruptedException();
            } else if (status == null || !status.message.equals(msg) || status.fractionCompleted != frac) {
                sessionProgresses.put(sessID, new ProgressStatus(msg, frac));
            }
        }
    }
}

From source file:org.roda_project.commons_ip.utils.ZIPUtils.java

public static void zip(Map<String, ZipEntryInfo> files, OutputStream out, SIP sip, boolean createSipIdFolder,
        boolean isCompressed) throws IOException, InterruptedException, IPException {
    ZipOutputStream zos = new ZipOutputStream(out);
    if (isCompressed) {
        zos.setLevel(Deflater.DEFAULT_COMPRESSION);
    } else {/*from w  ww .j a v a 2 s.  c  o m*/
        zos.setLevel(Deflater.NO_COMPRESSION);
    }

    Set<String> nonMetsChecksumAlgorithms = new TreeSet<>();
    nonMetsChecksumAlgorithms.add(IPConstants.CHECKSUM_ALGORITHM);
    Set<String> metsChecksumAlgorithms = new TreeSet<>();
    metsChecksumAlgorithms.addAll(nonMetsChecksumAlgorithms);
    metsChecksumAlgorithms.addAll(sip.getExtraChecksumAlgorithms());

    int i = 0;
    for (ZipEntryInfo file : files.values()) {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }

        file.prepareEntryforZipping();

        LOGGER.debug("Zipping file {}", file.getFilePath());
        ZipEntry entry;
        if (createSipIdFolder) {
            entry = new ZipEntry(sip.getId() + "/" + file.getName());
        } else {
            entry = new ZipEntry(file.getName());
        }

        zos.putNextEntry(entry);
        InputStream inputStream = Files.newInputStream(file.getFilePath());

        try {
            Map<String, String> checksums;
            if (file instanceof METSZipEntryInfo) {
                checksums = calculateChecksums(Optional.of(zos), inputStream, metsChecksumAlgorithms);
                METSZipEntryInfo metsEntry = (METSZipEntryInfo) file;
                metsEntry.setChecksums(checksums);
                metsEntry.setSize(metsEntry.getFilePath().toFile().length());
            } else {
                checksums = calculateChecksums(Optional.of(zos), inputStream, nonMetsChecksumAlgorithms);
            }

            LOGGER.debug("Done zipping file");
            String checksum = checksums.get(IPConstants.CHECKSUM_ALGORITHM);
            String checksumType = IPConstants.CHECKSUM_ALGORITHM;
            file.setChecksum(checksum);
            file.setChecksumAlgorithm(checksumType);
            if (file instanceof METSFileTypeZipEntryInfo) {
                METSFileTypeZipEntryInfo f = (METSFileTypeZipEntryInfo) file;
                f.getMetsFileType().setCHECKSUM(checksum);
                f.getMetsFileType().setCHECKSUMTYPE(checksumType);
            } else if (file instanceof METSMdRefZipEntryInfo) {
                METSMdRefZipEntryInfo f = (METSMdRefZipEntryInfo) file;
                f.getMetsMdRef().setCHECKSUM(checksum);
                f.getMetsMdRef().setCHECKSUMTYPE(checksumType);
            }
        } catch (NoSuchAlgorithmException e) {
            LOGGER.error("Error while zipping files", e);
        }
        zos.closeEntry();
        inputStream.close();
        i++;

        sip.notifySipBuildPackagingCurrentStatus(i);
    }

    zos.close();
    out.close();
}

From source file:org.kaaproject.kaa.client.transport.AndroidHttpClient.java

@Override
public byte[] executeHttpRequest(String uri, LinkedHashMap<String, byte[]> entity, boolean verifyResponse)
        throws Exception { //NOSONAR

    byte[] responseDataRaw = null;
    method = new HttpPost(url + uri);
    MultipartEntity requestEntity = new MultipartEntity();
    for (String key : entity.keySet()) {
        requestEntity.addPart(key, new ByteArrayBody(entity.get(key), null));
    }//from w  w  w.j a  v  a  2  s  .  com
    method.setEntity(requestEntity);
    if (!Thread.currentThread().isInterrupted()) {
        LOG.debug("Executing request {}", method.getRequestLine());
        HttpResponse response = httpClient.execute(method);
        try {
            LOG.debug("Received {}", response.getStatusLine());
            int status = response.getStatusLine().getStatusCode();
            if (status >= 200 && status < 300) {
                responseDataRaw = getResponseBody(response, verifyResponse);
            } else {
                throw new TransportException(status);
            }
        } finally {
            method = null;
        }
    } else {
        method = null;
        throw new InterruptedException();
    }
    return responseDataRaw;
}

From source file:org.apache.hama.pipes.protocol.UplinkReader.java

@Override
public void run() {
    while (true) {
        try {/*  ww  w  .  j a  v a  2s.c  o m*/
            if (Thread.currentThread().isInterrupted()) {
                throw new InterruptedException();
            }

            int cmd = readCommand();
            LOG.debug("Handling uplink command: " + cmd);
            // MessageType.values()[cmd] may cause NullPointerException (bad
            // command)

            if (cmd == MessageType.WRITE_KEYVALUE.code && isPeerAvailable()) { // INCOMING
                writeKeyValue();
            } else if (cmd == MessageType.READ_KEYVALUE.code && isPeerAvailable()) { // OUTGOING
                readKeyValue();
            } else if (cmd == MessageType.INCREMENT_COUNTER.code && isPeerAvailable()) { // INCOMING
                incrementCounter();
            } else if (cmd == MessageType.REGISTER_COUNTER.code && isPeerAvailable()) { // INCOMING
                /*
                 * Is not used in Hama. Hadoop Pipes uses it - maybe for performance
                 * issue, skip transferring group and name each INCREMENT
                 */
            } else if (cmd == MessageType.TASK_DONE.code) { // INCOMING
                synchronized (binProtocol.hasTaskLock) {
                    binProtocol.setHasTask(false);
                    LOG.debug("Got MessageType.TASK_DONE");
                    binProtocol.hasTaskLock.notify();
                }
            } else if (cmd == MessageType.DONE.code) { // INCOMING
                LOG.debug("Pipe child done");
                return;
            } else if (cmd == MessageType.SEND_MSG.code && isPeerAvailable()) { // INCOMING
                sendMessage();
            } else if (cmd == MessageType.GET_MSG_COUNT.code && isPeerAvailable()) { // OUTGOING
                getMessageCount();
            } else if (cmd == MessageType.GET_MSG.code && isPeerAvailable()) { // OUTGOING
                getMessage();
            } else if (cmd == MessageType.SYNC.code && isPeerAvailable()) { // INCOMING
                sync();
            } else if (cmd == MessageType.GET_ALL_PEERNAME.code && isPeerAvailable()) { // OUTGOING
                getAllPeerNames();
            } else if (cmd == MessageType.GET_PEERNAME.code && isPeerAvailable()) { // OUTGOING
                getPeerName();
            } else if (cmd == MessageType.GET_PEER_INDEX.code && isPeerAvailable()) { // OUTGOING
                getPeerIndex();
            } else if (cmd == MessageType.GET_PEER_COUNT.code && isPeerAvailable()) { // OUTGOING
                getPeerCount();
            } else if (cmd == MessageType.GET_SUPERSTEP_COUNT.code && isPeerAvailable()) { // OUTGOING
                getSuperstepCount();
            } else if (cmd == MessageType.REOPEN_INPUT.code && isPeerAvailable()) { // INCOMING
                reopenInput();
            } else if (cmd == MessageType.CLEAR.code && isPeerAvailable()) { // INCOMING
                clear();

                /* SequenceFileConnector Implementation */
            } else if (cmd == MessageType.SEQFILE_OPEN.code) { // OUTGOING
                seqFileOpen();
            } else if (cmd == MessageType.SEQFILE_READNEXT.code) { // OUTGOING
                seqFileReadNext();
            } else if (cmd == MessageType.SEQFILE_APPEND.code) { // INCOMING
                seqFileAppend();
            } else if (cmd == MessageType.SEQFILE_CLOSE.code) { // OUTGOING
                seqFileClose();
                /* SequenceFileConnector Implementation */

            } else if (cmd == MessageType.PARTITION_RESPONSE.code) { // INCOMING
                partitionResponse();
            } else {
                throw new Exception("Bad command code: " + cmd);
            }

        } catch (InterruptedException e) {
            onError(e);
            return;
        } catch (Throwable e) {
            onError(e);
            throw new RuntimeException(e);
        }
    }
}

From source file:com.appenginefan.toolkit.common.WebConnectionClient.java

/**
 * Checks if the interrupted-flag is set (using synchronization on this object)
 *///from   w  w  w.  j  av  a2 s. c o  m
private synchronized void checkForInterruption() throws InterruptedException {
    if (isInterrupted) {
        throw new InterruptedException();
    }
}