Example usage for java.lang InterruptedException getCause

List of usage examples for java.lang InterruptedException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.IslandsView.java

public void islandPopulationUpdate(final int islandIndex,
        final PopulationData<? extends Object> populationData) {
    // Make sure the bars are added to the chart in order of island index, regardless of which island
    // reports its results first.
    if (islandIndex >= islandCount.get()) {
        try {/*  ww w .  j  a  v a  2 s  .co  m*/
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    // Don't need synchronisation here because SwingUtilities queues these updates
                    // and if a second update gets queued, the loop will be a no-op so it's not a problem.
                    for (Integer i = islandCount.get(); i <= islandIndex; i++) {
                        bestDataSet.addValue(0, FITTEST_INDIVIDUAL_LABEL, i);
                        meanDataSet.add(0, 0, MEAN_FITNESS_LABEL, i);
                        islandCount.incrementAndGet();
                    }
                }
            });
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        } catch (InvocationTargetException ex) {
            throw new IllegalStateException(ex.getCause());
        }
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            chart.setNotify(false);
            bestDataSet.setValue(populationData.getBestCandidateFitness(), FITTEST_INDIVIDUAL_LABEL,
                    (Integer) islandIndex);
            meanDataSet.remove(MEAN_FITNESS_LABEL, (Integer) islandIndex);
            meanDataSet.add(populationData.getMeanFitness(), populationData.getFitnessStandardDeviation(),
                    MEAN_FITNESS_LABEL, (Integer) islandIndex);
            ValueAxis rangeAxis = ((CategoryPlot) chart.getPlot()).getRangeAxis();
            // If the range is not sufficient to display all values, enlarge it.
            synchronized (maxLock) {
                max = Math.max(max, populationData.getBestCandidateFitness());
                max = Math.max(max,
                        populationData.getMeanFitness() + populationData.getFitnessStandardDeviation());
                while (max > rangeAxis.getUpperBound()) {
                    rangeAxis.setUpperBound(rangeAxis.getUpperBound() * 2);
                }
                // If the range is much bigger than it needs to be, reduce it.
                while (max < rangeAxis.getUpperBound() / 4) {
                    rangeAxis.setUpperBound(rangeAxis.getUpperBound() / 4);
                }
            }
            chart.setNotify(true);
        }
    });
}

From source file:org.ulyssis.ipp.control.CommandDispatcher.java

public Result send(Command command) {
    final CompletableFuture<Result> future = new CompletableFuture<>();
    sendAsync(command, (c, r) -> {/*w ww  .ja v  a  2s.  c om*/
        assert (c == command);
        future.complete(r);
    });
    try {
        return future.get();
    } catch (InterruptedException e) {
        return Result.TIMEOUT;
    } catch (ExecutionException e) {
        LOG.error("We got an ExecutionException. This should not happen.", e.getCause());
        return Result.ERROR;
    }
}

From source file:org.marketcetera.util.except.ExceptUtilsTest.java

@Test
public void interruptionMessageThrow() {
    Thread.currentThread().interrupt();
    try {/*from w w  w .j  ava2 s .  c  om*/
        ExceptUtils.checkInterruption(TEST_MSG_1);
        fail();
    } catch (InterruptedException ex) {
        assertTrue(Thread.interrupted());
        assertEquals(TEST_MSG_1, ex.getMessage());
        assertNull(ex.getCause());
    }
}

From source file:org.wso2.andes.kernel.disruptor.inbound.InboundSubscriptionEvent.java

public boolean waitForCompletion() throws AndesException {
    try {// www.  jav  a2s.co m
        return future.get();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
        Throwable originalException = e.getCause();
        if (originalException instanceof SubscriptionAlreadyExistsException) {
            throw (SubscriptionAlreadyExistsException) originalException;
        } else if (originalException instanceof AndesException) {
            throw (AndesException) originalException;
        } else {
            // No point in throwing an exception here and disrupting the server. A warning is sufficient.
            log.warn("Error occurred while processing event '" + eventType + "' for channel id "
                    + subscriberConnection.getProtocolChannelID(), originalException);
        }
    }
    return false;
}

From source file:org.marketcetera.util.except.ExceptUtilsTest.java

@Test
public void interruptionMessageNestedThrow() {
    CloneNotSupportedException nested = new CloneNotSupportedException();
    Thread.currentThread().interrupt();
    try {//from ww  w.ja va 2s  . c  om
        ExceptUtils.checkInterruption(nested, TEST_MSG_1);
        fail();
    } catch (InterruptedException ex) {
        assertTrue(Thread.interrupted());
        assertEquals(TEST_MSG_1, ex.getMessage());
        assertEquals(nested, ex.getCause());
    }
}

From source file:org.artifactory.repo.service.ImportJob.java

private void finalizeImport(Future<DbRepoImportHandler> handlerFuture) {
    try {//from   w w w  . jav a2s . c o m
        DbRepoImportHandler importHandler = handlerFuture.get();
        importHandler.finalizeImport();
    } catch (InterruptedException e) {
        log.info("Import was interrupted");
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        log.error("Import had failed due to {}: {}", cause.getClass().getName(), cause.getMessage());
        log.debug("Import had failed due to {}: {}", cause.getClass().getName(), cause.getMessage(), cause);
        if (statusHolder != null) {
            statusHolder.error("Error occurred during import: " + cause.getMessage(), cause, log);
        }
    } catch (RuntimeException e) {
        // Extract cause
        if (statusHolder != null) {
            statusHolder.error("Error occurred during import: " + e.getMessage(), e, log);
        } else {
            log.error("Error occurred during import", e);
        }
    }
}

From source file:com.reactivetechnologies.platform.interceptor.AbstractOutboundChannel.java

@Override
public void feed(final Serializable item) {
    if (parallel) {
        Map<OutboundInterceptor<Serializable>, Future<?>> futures = new LinkedHashMap<>();
        for (final OutboundInterceptor<Serializable> feeder : feeders) {
            Future<?> f = threads.submit(new Callable<Void>() {

                @Override/*w  w w. ja  v  a2  s . c om*/
                public Void call() throws Exception {
                    feeder.feed(item);
                    return null;
                }
            });
            futures.put(feeder, f);
        }
        for (Entry<OutboundInterceptor<Serializable>, Future<?>> f : futures.entrySet()) {
            try {
                f.getValue().get(strategy.getTimeoutSecs(), TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } catch (ExecutionException e) {
                onFeedException(item, f.getKey(), e.getCause());
            } catch (TimeoutException e) {
                onFeedTimeout(item, f.getKey());
            }
        }
    } else {
        for (final OutboundInterceptor<Serializable> feeder : feeders) {
            try {
                feeder.feed(item);
            } catch (Exception e) {
                onFeedException(item, feeder, e);
            }
        }
    }

}

From source file:ch.cyberduck.core.onedrive.OneDriveCommonsHttpRequestExecutor.java

protected Upload doUpload(final URL url, final Set<RequestHeader> headers,
        final HttpEntityEnclosingRequestBase request) {
    for (RequestHeader header : headers) {
        if (header.getKey().equals(HTTP.TRANSFER_ENCODING)) {
            continue;
        }//from   w  ww.  j  av a 2 s .c  o m
        if (header.getKey().equals(HTTP.CONTENT_LEN)) {
            continue;
        }
        request.addHeader(new BasicHeader(header.getKey(), header.getValue()));
    }
    final CountDownLatch entry = new CountDownLatch(1);
    final DelayedHttpEntity entity = new DelayedHttpEntity(entry) {
        @Override
        public long getContentLength() {
            for (RequestHeader header : headers) {
                if (header.getKey().equals(HTTP.CONTENT_LEN)) {
                    return Long.valueOf(header.getValue());
                }
            }
            // Content-Encoding: chunked
            return -1L;
        }
    };
    request.setEntity(entity);
    final DefaultThreadPool executor = new DefaultThreadPool(String.format("http-%s", url), 1);
    final Future<CloseableHttpResponse> future = executor.execute(new Callable<CloseableHttpResponse>() {
        @Override
        public CloseableHttpResponse call() throws Exception {
            return client.execute(request);
        }
    });
    return new Upload() {
        @Override
        public Response getResponse() throws IOException {
            final CloseableHttpResponse response;
            try {
                response = future.get();
            } catch (InterruptedException e) {
                throw new IOException(e);
            } catch (ExecutionException e) {
                throw new IOException(e.getCause());
            } finally {
                executor.shutdown(false);
            }
            return new CommonsHttpResponse(response);
        }

        @Override
        public OutputStream getOutputStream() {
            try {
                // Await execution of HTTP request to make stream available
                entry.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return entity.getStream();
        }
    };
}

From source file:org.marketcetera.util.except.ExceptUtilsTest.java

@Test
public void interruptionEmptyThrow() {
    Thread.currentThread().interrupt();
    try {// w ww. j a v  a 2  s  . c  om
        ExceptUtils.checkInterruption();
        fail();
    } catch (InterruptedException ex) {
        assertTrue(Thread.interrupted());
        assertEquals("Thread execution was interrupted", ex.getMessage());
        assertNull(ex.getCause());
    }
}

From source file:org.apache.hama.bsp.message.HamaAsyncMessageManagerImpl.java

private void startServer(String hostName, int port) throws IOException {
    try {//from ww  w  . j av  a 2s  . c  om
        this.server = AsyncRPC.getServer(this, hostName, port,
                conf.getInt("hama.default.messenger.handler.threads.num", 5), false, conf);

        server.start();
        LOG.info("BSPPeer address:" + server.getAddress().getHostName() + " port:"
                + server.getAddress().getPort());
    } catch (InterruptedException e) {
        e.printStackTrace();
        Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
        e.printStackTrace();
        if (e.getCause() instanceof BindException) {
            final int nextPort = port + 1;
            LOG.warn("Address already in use. Retrying " + hostName + ":" + nextPort);
            if (retry++ >= MAX_RETRY) {
                throw new RuntimeException("RPC Server could not be launched!");
            }
            startServer(hostName, nextPort);
        }
    }
}