Example usage for java.util.concurrent ExecutionException getCause

List of usage examples for java.util.concurrent ExecutionException getCause

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException 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.apache.flink.client.program.rest.RestClusterClientTest.java

@Test
public void testTriggerSavepoint() throws Exception {
    final String targetSavepointDirectory = "/tmp";
    final String savepointLocationDefaultDir = "/other/savepoint-0d2fb9-8d5e0106041a";
    final String savepointLocationRequestedDir = targetSavepointDirectory + "/savepoint-0d2fb9-8d5e0106041a";

    final TestSavepointHandlers testSavepointHandlers = new TestSavepointHandlers();
    final TestSavepointHandlers.TestSavepointTriggerHandler triggerHandler = testSavepointHandlers.new TestSavepointTriggerHandler(
            null, targetSavepointDirectory, null, null);
    final TestSavepointHandlers.TestSavepointHandler savepointHandler = testSavepointHandlers.new TestSavepointHandler(
            new SavepointInfo(savepointLocationDefaultDir, null),
            new SavepointInfo(savepointLocationRequestedDir, null),
            new SavepointInfo(null, new SerializedThrowable(new RuntimeException("expected"))),
            new RestHandlerException("not found", HttpResponseStatus.NOT_FOUND));

    // fail first HTTP polling attempt, which should not be a problem because of the retries
    final AtomicBoolean firstPollFailed = new AtomicBoolean();
    failHttpRequest = (messageHeaders, messageParameters,
            requestBody) -> messageHeaders instanceof SavepointStatusHeaders
                    && !firstPollFailed.getAndSet(true);

    try (TestRestServerEndpoint ignored = createRestServerEndpoint(triggerHandler, savepointHandler)) {

        JobID id = new JobID();
        {//from w w  w. ja  va  2 s  . c o m
            CompletableFuture<String> savepointPathFuture = restClusterClient.triggerSavepoint(id, null);
            String savepointPath = savepointPathFuture.get();
            assertEquals(savepointLocationDefaultDir, savepointPath);
        }

        {
            CompletableFuture<String> savepointPathFuture = restClusterClient.triggerSavepoint(id,
                    targetSavepointDirectory);
            String savepointPath = savepointPathFuture.get();
            assertEquals(savepointLocationRequestedDir, savepointPath);
        }

        {
            try {
                restClusterClient.triggerSavepoint(id, null).get();
                fail("Expected exception not thrown.");
            } catch (ExecutionException e) {
                final Throwable cause = e.getCause();
                assertThat(cause, instanceOf(SerializedThrowable.class));
                assertThat(((SerializedThrowable) cause).deserializeError(ClassLoader.getSystemClassLoader())
                        .getMessage(), equalTo("expected"));
            }
        }

        try {
            restClusterClient.triggerSavepoint(new JobID(), null).get();
            fail("Expected exception not thrown.");
        } catch (final ExecutionException e) {
            assertTrue("RestClientException not in causal chain",
                    ExceptionUtils.findThrowable(e, RestClientException.class).isPresent());
        }
    }
}

From source file:org.apache.hadoop.crypto.key.kms.KMSClientProvider.java

@Override
public EncryptedKeyVersion generateEncryptedKey(String encryptionKeyName)
        throws IOException, GeneralSecurityException {
    try {/*from  w  w w  . ja v a  2  s .c o  m*/
        return encKeyVersionQueue.getNext(encryptionKeyName);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof SocketTimeoutException) {
            throw (SocketTimeoutException) e.getCause();
        }
        throw new IOException(e);
    }
}

From source file:i2p.bote.I2PBote.java

public void waitForPasswordChange() throws Throwable {
    if (passwordChangeResult == null)
        return;//  ww  w  .  ja  va2  s  .com

    try {
        passwordChangeResult.get();
    } catch (ExecutionException e) {
        throw e.getCause();
    } finally {
        passwordChangeResult = null;
    }
}

From source file:org.jenkins.plugins.lockableresources.LockableResourcesManager.java

/**
 * @deprecated USe {@link #tryQueue(org.jenkins.plugins.lockableresources.queue.LockableResourcesStruct, long, java.lang.String, int, java.util.Map, java.util.logging.Logger)}
 *///  w w w. j av  a  2s .  co  m
@Deprecated
@CheckForNull
public synchronized List<LockableResource> queue(LockableResourcesStruct requiredResources, long queueItemId,
        String queueItemProject, int number, // 0 means all
        Map<String, Object> params, Logger log) {
    try {
        return tryQueue(requiredResources, queueItemId, queueItemProject, number, params, log);
    } catch (ExecutionException ex) {
        if (LOGGER.isLoggable(Level.WARNING)) {
            String itemName = queueItemProject + " (id=" + queueItemId + ")";
            LOGGER.log(Level.WARNING, "Failed to queue item " + itemName,
                    ex.getCause() != null ? ex.getCause() : ex);
        }
        return null;
    }
}

From source file:edu.dfci.cccb.mev.domain.Heatmap.java

public File limmaRows(String experiment, String control, LimmaOutput type) throws IOException {
    try {/*from  ww w. j  ava  2 s.c o m*/
        return (File) limmaRows.get(new Pair<String, String>(experiment, control)).getValue(type.ordinal());
    } catch (ExecutionException e) {
        throw new RuntimeException(e.getCause());
    }
}

From source file:edu.dfci.cccb.mev.domain.Heatmap.java

public File limmaColumns(String experiment, String control, LimmaOutput type) {
    try {//from ww w .  j  av a  2s . c  o m
        return (File) limmaColumns.get(new Pair<String, String>(experiment, control)).getValue(type.ordinal());
    } catch (ExecutionException e) {
        throw new RuntimeException(e.getCause());
    }
}

From source file:org.apache.flink.runtime.rest.RestServerEndpointITCase.java

@Test
public void testVersionSelection() throws Exception {
    CompletableFuture<EmptyResponseBody> version1Response = restClient.sendRequest(serverAddress.getHostName(),
            serverAddress.getPort(), TestVersionSelectionHeaders1.INSTANCE,
            EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList(),
            RestAPIVersion.V0);// w  w w . j ava  2s  . c  o  m

    try {
        version1Response.get(5, TimeUnit.SECONDS);
        fail();
    } catch (ExecutionException ee) {
        RestClientException rce = (RestClientException) ee.getCause();
        assertEquals(HttpResponseStatus.OK, rce.getHttpResponseStatus());
    }

    CompletableFuture<EmptyResponseBody> version2Response = restClient.sendRequest(serverAddress.getHostName(),
            serverAddress.getPort(), TestVersionSelectionHeaders2.INSTANCE,
            EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList(),
            RestAPIVersion.V1);

    try {
        version2Response.get(5, TimeUnit.SECONDS);
        fail();
    } catch (ExecutionException ee) {
        RestClientException rce = (RestClientException) ee.getCause();
        assertEquals(HttpResponseStatus.ACCEPTED, rce.getHttpResponseStatus());
    }
}

From source file:org.apache.hadoop.hdfs.server.balancer.Dispatcher.java

/**
 * Dispatch block moves for each source. The thread selects blocks to move &
 * sends request to proxy source to initiate block move. The process is flow
 * controlled. Block selection is blocked if there are too many un-confirmed
 * block moves./*from  ww w  .  j a v a2s. c  o m*/
 *
 * @return the total number of bytes successfully moved in this iteration.
 */
private long dispatchBlockMoves() throws InterruptedException {
    final long bytesLastMoved = getBytesMoved();
    final Future<?>[] futures = new Future<?>[sources.size()];

    final Iterator<Source> i = sources.iterator();
    for (int j = 0; j < futures.length; j++) {
        final Source s = i.next();
        futures[j] = dispatchExecutor.submit(new Runnable() {
            @Override
            public void run() {
                s.dispatchBlocks();
            }
        });
    }

    // wait for all dispatcher threads to finish
    for (Future<?> future : futures) {
        try {
            future.get();
        } catch (ExecutionException e) {
            LOG.warn("Dispatcher thread failed", e.getCause());
        }
    }

    // wait for all block moving to be done
    waitForMoveCompletion(targets);

    return getBytesMoved() - bytesLastMoved;
}

From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java

/**
 * Loads a new {@link Map} into the mainPanel / contentPane of the
 * {@link AtlasViewerGUI}. The previous {@link Map}'s {@link DpEntry}s will
 * be removed from cache if they are not used by the new {@link Map}.
 * //from  www . jav a  2s.c  om
 * @param newMap
 *            new {@link Map} to show in the {@link AtlasViewerGUI}
 * 
 * @param force
 *            If force == <code>false</code>, the map is only changed if the
 *            old map != new map. If the map has to be repainted due to a
 *            change of the language, paramter force should be
 *            <code>true</code>.
 */
public void setMap(final Map newMap, boolean force) {
    // LOGGER.debug("setMap called!");

    /**
     * Unless we force it, we don't reload the same map again.
     */
    if ((!force) && map == newMap)
        return;

    if (newMap == null) {
        return;
    }

    AtlasStatusDialog statusDialog = new AtlasStatusDialog(getJFrame(), null,
            GpCoreUtil.R("AmlViewer.process.opening_map", newMap.getTitle()));

    // Remember the status of the toolbar
    Integer lastMapsTool = -99;
    if (getJFrame().getContentPane() instanceof AtlasMapView) {
        AtlasMapView amv = (AtlasMapView) getJFrame().getContentPane();
        lastMapsTool = amv.getSelectedTool();
    }

    // in case the map loading is canceled, we jump back to the last map
    // String lastMapId = map != null ? map.getId() : null;
    AtlasSwingWorker<Boolean> startupTask = new AtlasSwingWorker<Boolean>(statusDialog) {

        @Override
        protected Boolean doInBackground() throws Exception {

            // **************************************************************
            // The previous {@link Map}'s {@link DpEntry}s will be
            // un-cached if they are not used by the new {@link Map}
            // **************************************************************
            // LOGGER.info("map  = " + map);
            if (map != null) {

                Container cp = getJFrame().getContentPane();

                if (cp instanceof AtlasMapView) {
                    AtlasMapView amv = (AtlasMapView) cp;
                    amv.dispose();
                }

                // Un-cache all parts of the old map that are not needed in
                // the new map
                map.uncache(newMap);
            }

            if (JNLPUtil.isAtlasDataFromJWS(atlasConfig)) {
                LOGGER.debug("atlas data comes from JWS, so we download all parts of map " + newMap.getId()
                        + " (if not already cached)...");
                publish(GpCoreUtil.R("AmlViewer.process.downloading_map", newMap.getTitle()));
                newMap.downloadMap(statusDialog);
            }
            return true;
        }
    };

    try {
        startupTask.executeModal();

        final AtlasMapView mapView_ = new AtlasMapView(getJFrame(), getAtlasConfig());
        mapView_.setMap(newMap, statusDialog);

        mapView_.initialize();
        if (lastMapsTool >= 0)
            getMapView().setSelectedTool(lastMapsTool);

        map = newMap;
        setMapView(mapView_);

    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancelException)
            // tries to load the default map, which should not
            setFirstMap();
        else
            ExceptionDialog.show(getJFrame(), e);
    } catch (InterruptedException e) {
    } catch (CancellationException e) {
    }
}