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:com.lukakama.serviio.watchservice.watcher.WatcherRunnable.java

private void checkInterrupted() throws InterruptedException {
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }//from  www.j  a  v a  2s . co m
}

From source file:org.rhq.modules.plugins.jbossas7.PatchHandlerComponent.java

private boolean waitForServerToStart(ASConnection connection) throws InterruptedException {
    boolean up = false;
    while (!up) {
        up = isServerUp(connection);/*from   w ww  .  ja v a2s.com*/

        if (!up) {
            if (context.getComponentInvocationContext().isInterrupted()) {
                // Operation canceled or timed out
                throw new InterruptedException();
            }
            Thread.sleep(SECONDS.toMillis(1));
        }
    }
    return true;
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Download the content for the given NodeRef
 * @param ref//from w w w .j av a  2  s .  co m
 * @param handler
 */
protected void downloadContent(final NodeRef ref, final Handler handler) {
    startProgressDlg(false);
    _progressDlg.setMax(Long.valueOf(ref.getContentLength()).intValue());

    _dlThread = new ChildDownloadThread(handler, new Downloadable() {
        public Object execute() {
            File f = null;

            try {
                CMISApplication app = (CMISApplication) getContext().getApplicationContext();
                URL url = new URL(ref.getContent());
                String name = ref.getName();
                long fileSize = ref.getContentLength();
                f = app.getFile(name, fileSize);

                if (f != null && f.length() != fileSize) {
                    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

                    FileOutputStream fos = new FileOutputStream(f);
                    InputStream is = _cmis.get(url.getPath());

                    byte[] buffer = new byte[BUF_SIZE];
                    int len = is.read(buffer);
                    int total = len;
                    Message msg = null;
                    Bundle b = null;

                    while (len != -1) {
                        msg = handler.obtainMessage();
                        b = new Bundle();
                        b.putInt("progress", total);
                        msg.setData(b);
                        handler.sendMessage(msg);

                        fos.write(buffer, 0, len);
                        len = is.read(buffer);
                        total += len;

                        if (Thread.interrupted()) {
                            fos.close();
                            f = null;
                            throw new InterruptedException();
                        }
                    }

                    fos.flush();
                    fos.close();
                }
            } catch (Exception e) {
                Log.e(CMISAdapter.class.getSimpleName(), "", e);
            }

            return f;
        }
    });
    _dlThread.start();
}

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

protected static void addDefaultSchemas(Logger logger, List<IPFile> schemas, Path buildDir)
        throws InterruptedException {
    try {/*  ww  w .  j a  va  2s .co m*/
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Path metsSchema = Utils.copyResourceFromClasspathToDir(EARKSIP.class, buildDir, "mets.xsd",
                "/schemas/mets1_11.xsd");
        schemas.add(new IPFile(metsSchema, "mets.xsd"));
        Path xlinkSchema = Utils.copyResourceFromClasspathToDir(EARKSIP.class, buildDir, "xlink.xsd",
                "/schemas/xlink.xsd");
        schemas.add(new IPFile(xlinkSchema, "xlink.xsd"));
    } catch (IOException e) {
        logger.error("Error while trying to add default schemas", e);
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java

protected List<?> asyncSearch(SearchExecutor<?> searchExecutor, String searchString, Map<String, Object> params)
        throws Exception {
    if (Thread.currentThread().isInterrupted()) {
        throw new InterruptedException();
    }/*from  w  ww  . j a  v  a  2  s .c  om*/

    log.debug("Search '{}'", searchString);

    List<?> searchResultItems;
    if (searchExecutor instanceof ParametrizedSearchExecutor) {
        //noinspection unchecked
        ParametrizedSearchExecutor<?> pSearchExecutor = (ParametrizedSearchExecutor<?>) searchExecutor;
        searchResultItems = new ArrayList<>(pSearchExecutor.search(searchString, params));
    } else {
        searchResultItems = new ArrayList<>(searchExecutor.search(searchString, Collections.emptyMap()));
    }

    return searchResultItems;
}

From source file:com.sk89q.squirrelid.util.HttpRequest.java

private static void checkInterrupted() throws InterruptedException {
    if (Thread.currentThread().isInterrupted()) {
        throw new InterruptedException();
    }/*from   w ww.j  ava  2  s . c  o m*/
}

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

protected static void addSubmissionsToZipAndMETS(final Map<String, ZipEntryInfo> zipEntries,
        final MetsWrapper metsWrapper, final List<IPFile> submissions)
        throws IPException, InterruptedException {
    if (submissions != null && !submissions.isEmpty()) {
        for (IPFile submission : submissions) {
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }//from w  ww . j a v a2 s  . c  o m
            final String submissionFilePath = IPConstants.SUBMISSION_FOLDER
                    + ModelUtils.getFoldersFromList(submission.getRelativeFolders()) + submission.getFileName();
            final FileType fileType = EARKMETSUtils.addSubmissionFileToMETS(metsWrapper, submissionFilePath,
                    submission.getPath());
            ZIPUtils.addFileTypeFileToZip(zipEntries, submission.getPath(), submissionFilePath, fileType);
        }
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

private void handleCancelEvent(JSONObject data) {
    try {//from w  w  w.  ja va 2 s  . c  o m
        int requestId = data.getInt("id");
        logger.debug("Received cancel for request {}", requestId);
        // Find and abort running request
        if (runningRequests.containsKey(requestId)) {
            Request request = runningRequests.get(requestId);
            request.abort(new InterruptedException());
            runningRequests.remove(requestId);
        }
    } catch (JSONException e) {
        logger.error(e.getMessage());
    }
}

From source file:eu.vital.TrustManager.connectors.dms.DMSManager.java

private String queryWithExceptions(String dms_endpoint, String body, String method)
        throws SocketTimeoutException, ConnectException, IOException, InterruptedException {
    Cookie ck;//from w  w  w  .  ja  v  a  2s .c o m
    //String internalToken;
    CloseableHttpClient httpclient;
    HttpRequestBase httpaction;
    //boolean wasEmpty;
    //int code;

    httpclient = HttpClients.createDefault();

    URI uri = null;
    try {
        // Prepare to forward the request to the proxy
        uri = new URI(dms_URL + "/" + dms_endpoint);
    } catch (URISyntaxException e1) {
        java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, e1);
    }

    if (method.equals("GET")) {
        httpaction = new HttpGet(uri);
    } else {
        httpaction = new HttpPost(uri);
    }

    // Get token or authenticate if null or invalid
    //internalToken = client.getToken();
    ck = new Cookie("vitalAccessToken", cookie.substring(17));

    httpaction.setHeader("Cookie", ck.toString());
    httpaction.setConfig(RequestConfig.custom().setConnectionRequestTimeout(5000).setConnectTimeout(5000)
            .setSocketTimeout(5000).build());
    httpaction.setHeader("Content-Type", javax.ws.rs.core.MediaType.APPLICATION_JSON);

    StringEntity strEntity = new StringEntity(body, StandardCharsets.UTF_8);

    if (method.equals("POST")) {
        ((HttpPost) httpaction).setEntity(strEntity);
    }

    // Execute and get the response.
    CloseableHttpResponse response = null;
    try {
        response = httpclient.execute(httpaction);
    } catch (ClientProtocolException e) {
        throw new ClientProtocolException();
    } catch (IOException e) {
        try {
            // Try again with a higher timeout
            try {
                Thread.sleep(1000); // do not retry immediately
            } catch (InterruptedException e1) {
                throw new InterruptedException();
                // e1.printStackTrace();
            }
            httpaction.setConfig(RequestConfig.custom().setConnectionRequestTimeout(7000)
                    .setConnectTimeout(7000).setSocketTimeout(7000).build());
            response = httpclient.execute(httpaction);
        } catch (ClientProtocolException ea) {
            java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, ea);
            throw new ClientProtocolException();
        } catch (IOException ea) {
            try {
                // Try again with a higher timeout
                try {
                    Thread.sleep(1000); // do not retry immediately
                } catch (InterruptedException e1) {
                    java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, e1);
                    throw new InterruptedException();
                }
                httpaction.setConfig(RequestConfig.custom().setConnectionRequestTimeout(12000)
                        .setConnectTimeout(12000).setSocketTimeout(12000).build());
                response = httpclient.execute(httpaction);
            } catch (ClientProtocolException eaa) {
                java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, eaa);
                throw new ClientProtocolException();
            } catch (SocketTimeoutException eaa) {
                java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, eaa);
                throw new SocketTimeoutException();
            } catch (ConnectException eaa) {
                java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, eaa);
                throw new ConnectException();
            } catch (ConnectTimeoutException eaa) {
                java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, eaa);
                throw new ConnectTimeoutException();
            }
        }
    }

    int statusCode = response.getStatusLine().getStatusCode();

    if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED) {
        if (statusCode == 503) {
            java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null,
                    "httpStatusCode 503");
            throw new ServiceUnavailableException();
        } else if (statusCode == 502) {
            java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null,
                    "httpStatusCode 502");
            throw new ServerErrorException(502);
        } else if (statusCode == 401) {
            java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null,
                    "could't Athorize the DMS");
            throw new NotAuthorizedException("could't Athorize the DMS");
        } else {
            java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null,
                    "httpStatusCode 500");
            throw new ServiceUnavailableException();
        }
    }

    HttpEntity entity;
    entity = response.getEntity();
    String respString = "";

    if (entity != null) {
        try {
            respString = EntityUtils.toString(entity);
            response.close();
        } catch (ParseException | IOException e) {
            java.util.logging.Logger.getLogger(DMSManager.class.getName()).log(Level.SEVERE, null, e);
        }
    }
    return respString;

}

From source file:org.eclipse.jubula.client.ui.rcp.handlers.project.SaveProjectAsHandler.java

/**
 * @param monitor//from w w w  . j a  va 2  s  .  c  om
 *            The progress monitor for this potentially long-running
 *            operation.
 * @return content for new project to create, or <code>null</code> if the
 *         operation was cancelled.
 * @throws PMException
 *             if saving of project as xml file failed
 * @throws ProjectDeletedException
 *             if current project is already deleted
 * @throws InterruptedException
 *             if the operation was canceled.
 */
private InputStream getContentForNewProject(IProgressMonitor monitor)
        throws ProjectDeletedException, InterruptedException, PMException {
    GeneralStorage.getInstance().validateProjectExists(GeneralStorage.getInstance().getProject());
    InputStream projectStream = XmlStorage.save(GeneralStorage.getInstance().getProject(), null, false, monitor,
            false, null);

    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    if (projectStream != null) {
        return projectStream;
    }

    return null;
}