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:org.apache.ranger.plugin.contextenricher.RangerTagFileStoreRetriever.java

@Override
public ServiceTags retrieveTags(long lastKnownVersion, long lastActivationTimeInMillis)
        throws InterruptedException {

    ServiceTags serviceTags = null;/*from  www  .  ja v a  2  s. c  om*/

    if (tagStore != null) {
        try {
            // Ignore lastActivationTimeInMillis for TagFileStore
            serviceTags = tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion);
        } catch (InterruptedException interruptedException) {
            LOG.error("Tag-retriever thread was interrupted");
            throw interruptedException;
        } catch (ClosedByInterruptException closedByInterruptException) {
            LOG.error("Tag-retriever thread was interrupted while blocked on I/O");
            throw new InterruptedException();
        } catch (Exception exception) {
            LOG.error("RangerTagFileStoreRetriever.retrieveTags() - Error retrieving resources, exception=",
                    exception);
        }
    }
    return serviceTags;
}

From source file:org.apache.ranger.plugin.contextenricher.RangerAdminTagRetriever.java

@Override
public ServiceTags retrieveTags(long lastKnownVersion, long lastActivationTimeInMillis)
        throws InterruptedException {

    ServiceTags serviceTags = null;//from   w w  w .  j ava  2s .  c  om

    if (adminClient != null) {
        try {
            serviceTags = adminClient.getServiceTagsIfUpdated(lastKnownVersion, lastActivationTimeInMillis);
        } catch (InterruptedException interruptedException) {
            LOG.error("Tag-retriever thread was interrupted");
            throw interruptedException;
        } catch (ClosedByInterruptException closedByInterruptException) {
            LOG.error("Tag-retriever thread was interrupted while blocked on I/O");
            throw new InterruptedException();
        } catch (Exception exception) {
            LOG.error("RangerAdminTagRetriever.retrieveTags() - Error retrieving resources, exception=",
                    exception);
        }
    }
    return serviceTags;
}

From source file:com.github.stephanarts.cas.ticket.registry.support.WatchDogTest.java

@Test
@Ignore/*  w  w  w.  j a va  2s  .co  m*/
public void testSleepInterrupt() throws Exception {
    WatchDog w = new WatchDog();

    //PowerMockito.mockStatic(Thread.class);
    //PowerMockito.doThrow(new InterruptedException()).when(Thread.class);
    PowerMockito.spy(Thread.class);
    PowerMockito.doThrow(new InterruptedException()).when(Thread.class);
    Thread.sleep(anyLong());

    w.start();
    w.cleanup();

    Assert.assertFalse(w.isAlive());
}

From source file:org.esipfed.eskg.aquisition.ESKGCrawler.java

private static void crawl(SiteCrawler crawler) throws InterruptedException {
    final Set<String> distinctPages = new HashSet<>();
    crawler.addListener(new CrawlerListener() {
        @Override/*from  w  w w. j  av a 2  s .  c  o  m*/
        public void visitedPage(Page page) {
            distinctPages.add(page.getWebURL().getURL());
            Iterator<String> it = distinctPages.iterator();
            while (it.hasNext()) {
                LOG.info("Fetching page - " + it.next());
            }
        }
    });
    try {
        crawler.start(seedUrl, pageFilter, false);
    } catch (Exception e) {
        LOG.error("Error whilst starting crawl. {}", e);
    }
    synchronized (ESKGCrawler.class) {
        try {
            ESKGCrawler.class.wait(15 * 1000);
        } catch (InterruptedException e) {
            LOG.error("Crawler has been interrupted: {}", e);
            throw new InterruptedException();
        }
    }
    crawler.stop();

    LOG.info("Distinct pages: " + distinctPages.size());

}

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

protected static void addDescriptiveMetadataToZipAndMETS(Map<String, ZipEntryInfo> zipEntries,
        MetsWrapper metsWrapper, List<IPDescriptiveMetadata> descriptiveMetadata, String representationId)
        throws IPException, InterruptedException {
    if (descriptiveMetadata != null && !descriptiveMetadata.isEmpty()) {
        for (IPDescriptiveMetadata dm : descriptiveMetadata) {
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }//  w w w .java 2s  .  com
            IPFile file = dm.getMetadata();

            String descriptiveFilePath = IPConstants.DESCRIPTIVE_FOLDER
                    + ModelUtils.getFoldersFromList(file.getRelativeFolders()) + file.getFileName();
            MdRef mdRef = EARKMETSUtils.addDescriptiveMetadataToMETS(metsWrapper, dm, descriptiveFilePath);

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

From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolatorSimple.java

protected void interpolateSurface(LinkedList<Point3d> points) throws InterruptedException {

    double pixSize = Magellan.getCore().getPixelSizeUm();
    //provide interpolator with current list of data points
    Point_dt triangulationPoints[] = new Point_dt[points.size()];
    for (int i = 0; i < points.size(); i++) {
        triangulationPoints[i] = new Point_dt(points.get(i).x, points.get(i).y, points.get(i).z);
    }/*from   w ww  . j ava  2s  .co m*/
    Delaunay_Triangulation dTri = new Delaunay_Triangulation(triangulationPoints);

    int maxPixelDimension = (int) (Math.max(boundXMax_ - boundXMin_, boundYMax_ - boundYMin_) / pixSize);
    //Start with at least 20 interp points and go smaller and smaller until every pixel interped?
    int pixelsPerInterpPoint = 1;
    while (maxPixelDimension / (pixelsPerInterpPoint + 1) > 20) {
        pixelsPerInterpPoint *= 2;
    }
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }

    while (pixelsPerInterpPoint >= MIN_PIXELS_PER_INTERP_POINT) {
        int numInterpPointsX = (int) (((boundXMax_ - boundXMin_) / pixSize) / pixelsPerInterpPoint);
        int numInterpPointsY = (int) (((boundYMax_ - boundYMin_) / pixSize) / pixelsPerInterpPoint);
        double dx = (boundXMax_ - boundXMin_) / (numInterpPointsX - 1);
        double dy = (boundYMax_ - boundYMin_) / (numInterpPointsY - 1);

        float[][] interpVals = new float[numInterpPointsY][numInterpPointsX];
        float[][] interpNormals = new float[numInterpPointsY][numInterpPointsX];
        boolean[][] interpDefined = new boolean[numInterpPointsY][numInterpPointsX];
        for (int yInd = 0; yInd < interpVals.length; yInd++) {
            for (int xInd = 0; xInd < interpVals[0].length; xInd++) {
                if (Thread.interrupted()) {
                    throw new InterruptedException();
                }
                double xVal = boundXMin_ + dx * xInd;
                double yVal = boundYMin_ + dy * yInd;
                boolean inHull = convexHullRegion_
                        .checkPoint(new Vector2D(xVal, yVal)) == Region.Location.INSIDE;
                if (inHull) {
                    Triangle_dt tri = dTri.find(new Point_dt(xVal, yVal));
                    //convert to apache commons coordinates to make a plane
                    Vector3D v1 = new Vector3D(tri.p1().x(), tri.p1().y(), tri.p1().z());
                    Vector3D v2 = new Vector3D(tri.p2().x(), tri.p2().y(), tri.p2().z());
                    Vector3D v3 = new Vector3D(tri.p3().x(), tri.p3().y(), tri.p3().z());
                    Plane plane = new Plane(v1, v2, v3, TOLERANCE);
                    //intersetion of vertical line at these x+y values with plane gives point in plane
                    Vector3D pointInPlane = plane.intersection(
                            new Line(new Vector3D(xVal, yVal, 0), new Vector3D(xVal, yVal, 1), TOLERANCE));
                    float zVal = (float) pointInPlane.getZ();
                    interpVals[yInd][xInd] = zVal;
                    float angle = (float) (Vector3D.angle(plane.getNormal(), new Vector3D(0, 0, 1)) / Math.PI
                            * 180.0);
                    interpNormals[yInd][xInd] = angle;
                    interpDefined[yInd][xInd] = true;
                } else {
                    interpDefined[yInd][xInd] = false;
                }
            }
        }
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        synchronized (interpolationLock_) {
            currentInterpolation_ = new SingleResolutionInterpolation(pixelsPerInterpPoint, interpDefined,
                    interpVals, interpNormals, boundXMin_, boundXMax_, boundYMin_, boundYMax_,
                    convexHullRegion_, convexHullVertices_, getPoints());
            interpolationLock_.notifyAll();
        }
        //         System.gc();
        pixelsPerInterpPoint /= 2;
    }
}

From source file:cz.cuni.mff.ksi.jinfer.autoeditor.automatonvisualizer.layouts.graphviz.GraphvizLayoutFactory.java

@Override
public <T> Layout<State<T>, Step<T>> createLayout(final Automaton<T> automaton,
        final Graph<State<T>, Step<T>> graph, final Transformer<Step<T>, String> edgeLabelTransformer)
        throws InterruptedException {
    if (!GraphvizUtils.isBinaryValid()) {
        DialogDisplayer.getDefault()//from  w  ww .  j a v  a 2 s.  c  o m
                .notify(new NotifyDescriptor.Message(org.openide.util.NbBundle
                        .getMessage(GraphvizLayoutFactory.class, "binary.invalid.message"),
                        NotifyDescriptor.ERROR_MESSAGE));
        throw new InterruptedException();
    }

    try {
        final byte[] graphInDotFormat = AutomatonToDot.<T>convertToDot(automaton, edgeLabelTransformer)
                .getBytes();
        final Map<State<T>, Point2D> positions = getGraphvizPositions(graphInDotFormat,
                automaton.getDelta().keySet());
        final Transformer<State<T>, Point2D> trans = TransformerUtils.mapTransformer(positions);
        return new StaticLayout<State<T>, Step<T>>(graph, trans, new Dimension(windowWidth, windowHeight));
    } catch (Exception ex) {
        LOG.error("Error occured in Graphviz", ex);
        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                org.openide.util.NbBundle.getMessage(GraphvizLayoutFactory.class, "error.dialog.message"),
                NotifyDescriptor.ERROR_MESSAGE));
        throw new InterruptedException(); //NOPMD
    }
}

From source file:fr.gael.dhus.datastore.scanner.FtpScanner.java

/**
 * Recursively scans specified directory.
 * //from  ww w  .  ja v a  2  s .  c o  m
 * @param directory directory to scan
 * @throws IOException if IO exception occurs
 * @throws InterruptedException in user request stop
 */
private int scanDirectory(FtpNode path) throws IOException, BadLoginException, InterruptedException {
    if (isStopped())
        throw new InterruptedException();
    logger.info("LIST " + path);

    boolean accepted = checkIt(path);
    int total = 0;
    if (accepted)
        total++;
    if ((!accepted || isForceNavigate()) && !isFile(path)) {
        for (int index = 0; index < path.getChildrenCount(); index++) {
            DrbItem item = path.getChildAt(index);
            total += scanDirectory((FtpNode) item);
        }
    }
    return total;
}

From source file:de.sjka.logstash.osgi.internal.LogstashSender.java

@Override
public void run() {
    System.out.println("Logstash sender started");
    try {//from w w  w.  j  av a  2s.c om
        while (true) {
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
            LogEntry entry = queue.takeFirst();
            try {
                process(entry);
            } catch (Exception e) {
                queue.putFirst(entry);
                Thread.sleep(60 * SECONDS);
            }
        }
    } catch (InterruptedException e) {
        // all good
    }
    System.out.println("Logstash sender shutting down");
}

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

@Override
public byte[] executeHttpRequest(String uri, LinkedHashMap<String, byte[]> entity, boolean verifyResponse)
        throws Exception { //NOSONAR
    byte[] responseDataRaw = null;
    method = new HttpPost(url + uri);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    for (String key : entity.keySet()) {
        builder.addBinaryBody(key, entity.get(key));
    }//w  w  w. jav a  2 s  .c  o m
    HttpEntity requestEntity = builder.build();
    method.setEntity(requestEntity);
    if (!Thread.currentThread().isInterrupted()) {
        LOG.debug("Executing request {}", method.getRequestLine());
        CloseableHttpResponse 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 {
            response.close();
            method = null;
        }
    } else {
        method = null;
        throw new InterruptedException();
    }

    return responseDataRaw;
}