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.hadoop.util.concurrent.ExecutorHelper.java

static void logThrowableFromAfterExecute(Runnable r, Throwable t) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("afterExecute in thread: " + Thread.currentThread().getName() + ", runnable type: "
                + r.getClass().getName());
    }//  w w w .  ja  v  a  2s .c  o m

    //For additional information, see: https://docs.oracle
    // .com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor
    // .html#afterExecute(java.lang.Runnable,%20java.lang.Throwable) .

    if (t == null && r instanceof Future<?>) {
        try {
            ((Future<?>) r).get();
        } catch (ExecutionException ee) {
            LOG.warn("Execution exception when running task in " + Thread.currentThread().getName());
            t = ee.getCause();
        } catch (InterruptedException ie) {
            LOG.warn("Thread (" + Thread.currentThread() + ") interrupted: ", ie);
            Thread.currentThread().interrupt();
        } catch (Throwable throwable) {
            t = throwable;
        }
    }

    if (t != null) {
        LOG.warn("Caught exception in thread " + Thread.currentThread().getName() + ": ", t);
    }
}

From source file:com.thinkbiganalytics.db.PoolingDataSourceService.java

/**
 * Gets the data source using the specified properties.
 *
 * @param props the data source properties
 * @return the data source/* w ww.  j av  a 2  s  .c o m*/
 */
public static DataSource getDataSource(final DataSourceProperties props) {
    try {
        return DATA_SOURCES.get(props);
    } catch (final ExecutionException e) {
        if (e.getCause() != null) {
            throw Throwables.propagate(e.getCause());
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:forge.ImageCache.java

/**
 * Returns the Image corresponding to the key.
 *//*from  w  ww. j  a  v a2 s .  c  o  m*/
private static BufferedImage getImage(final String key) {
    FThreads.assertExecutedByEdt(true);
    try {
        return ImageCache._CACHE.get(key);
    } catch (final ExecutionException ex) {
        if (ex.getCause() instanceof NullPointerException) {
            return null;
        }
        ex.printStackTrace();
        return null;
    } catch (final InvalidCacheLoadException ex) {
        // should be when a card legitimately has no image
        return null;
    }
}

From source file:forge.assets.ImageCache.java

/**
 * This requests the original unscaled image from the cache for the given key.
 * If the image does not exist then it can return a default image if desired.
 * <p>//from  w  w  w.  j  ava  2  s. c  o m
 * If the requested image is not present in the cache then it attempts to load
 * the image from file (slower) and then add it to the cache for fast future access. 
 * </p>
 */
public static Texture getImage(String imageKey, boolean useDefaultIfNotFound) {
    if (StringUtils.isEmpty(imageKey)) {
        return null;
    }

    boolean altState = imageKey.endsWith(ImageKeys.BACKFACE_POSTFIX);
    if (altState) {
        imageKey = imageKey.substring(0, imageKey.length() - ImageKeys.BACKFACE_POSTFIX.length());
    }
    if (imageKey.startsWith(ImageKeys.CARD_PREFIX)) {
        imageKey = ImageUtil.getImageKey(ImageUtil.getPaperCardFromImageKey(imageKey.substring(2)), altState,
                true);
        if (StringUtils.isBlank(imageKey)) {
            return defaultImage;
        }
    }

    Texture image;
    if (useDefaultIfNotFound) {
        // Load from file and add to cache if not found in cache initially.
        image = cache.getIfPresent(imageKey);
        if (image != null) {
            return image;
        }

        if (imageLoaded) { //prevent loading more than one image each render for performance
            if (!delayLoadRequested) {
                //ensure images continue to load even if no input is being received
                delayLoadRequested = true;
                Gdx.graphics.requestRendering();
            }
            return null;
        }
        imageLoaded = true;
    }

    try {
        image = cache.get(imageKey);
    } catch (final ExecutionException ex) {
        if (!(ex.getCause() instanceof NullPointerException)) {
            ex.printStackTrace();
        }
        image = null;
    } catch (final Exception ex) {
        image = null;
    }

    // No image file exists for the given key so optionally associate with
    // a default "not available" image and add to cache for given key.
    if (image == null) {
        if (useDefaultIfNotFound) {
            image = defaultImage;
            cache.put(imageKey, defaultImage);
        }
    }
    return image;
}

From source file:com.microsoft.azure.storage.util.KeyVaultUtility.java

/**
 * Creates a secret in Azure Key Vault and returns its ID.
 * /*from   w  w  w.  j a v a2s .c o  m*/
 * @param secretName
 *            The name of the secret to create
 * @return The ID of the created secret
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws NoSuchAlgorithmException
 * @throws URISyntaxException
 * @throws MalformedURLException
 */
public static String SetUpKeyVaultSecret(String secretName) throws InterruptedException, ExecutionException,
        NoSuchAlgorithmException, URISyntaxException, MalformedURLException {
    KeyVaultClient cloudVault = GetKeyVaultClient();

    if (Utility.vaultURL == null || Utility.vaultURL.isEmpty()) {
        throw new IllegalArgumentException("No Keyvault URL specified.");
    }

    try {
        // Delete the secret if it exists.
        cloudVault.deleteSecretAsync(Utility.vaultURL, secretName).get();
    } catch (ExecutionException ex) {
        boolean keyNotFound = false;
        if (ex.getCause().getClass() == ServiceException.class) {
            ServiceException serviceException = (ServiceException) ex.getCause();
            if (serviceException.getHttpStatusCode() == 404) {
                keyNotFound = true;
            }
        }

        if (!keyNotFound) {
            System.out.println(
                    "Unable to access the specified vault. Please confirm the KVClientId, KVClientKey, and VaultUri are valid in the app.config file.");
            System.out.println(
                    "Also ensure that the client ID has previously been granted full permissions for Key Vault secrets using the Set-AzureKeyVaultAccessPolicy command with the -PermissionsToSecrets parameter.");
            System.out.println("Press any key to exit");
            Scanner input = new Scanner(System.in);
            input.nextLine();
            input.close();
            throw ex;
        }
    }

    // Create a 256bit symmetric key and convert it to Base64.
    KeyGenerator keyGen = KeyGenerator.getInstance("AES");
    keyGen.init(256); // Note that we cannot use SymmetricKey.KeySize256,
                      // because this resolves to '0x20'.
    SecretKey wrapKey = keyGen.generateKey();

    // Store the Base64 of the key in the key vault. Note that the
    // content-type of the secret must
    // be application/octet-stream or the KeyVaultKeyResolver will not load
    // it as a key.
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/octet-stream");
    Secret cloudSecret = cloudVault.setSecretAsync(Utility.vaultURL, secretName,
            Base64.encodeBase64String(wrapKey.getEncoded()), "application/octet-stream", null, null).get();

    // Return the base identifier of the secret. This will be resolved to
    // the current version of the secret.
    return cloudSecret.getSecretIdentifier().getBaseIdentifier();
}

From source file:gobblin.hive.HiveMetastoreClientPool.java

/**
 * Get a {@link HiveMetastoreClientPool} for the requested metastore URI. Useful for using the same pools across
 * different classes in the code base. Note that if a pool already exists for that metastore, the max number of
 * objects available will be unchanged, and it might be lower than requested by this method.
 *
 * @param properties {@link Properties} used to generate the pool.
 * @param metastoreURI URI of the Hive metastore. If absent, use default metastore.
 * @return a {@link HiveMetastoreClientPool}.
 * @throws IOException//from w w  w  .j  ava  2s . c  o m
 */
public static HiveMetastoreClientPool get(final Properties properties, final Optional<String> metastoreURI)
        throws IOException {
    try {
        return poolCache.get(metastoreURI, new Callable<HiveMetastoreClientPool>() {
            @Override
            public HiveMetastoreClientPool call() throws Exception {
                return new HiveMetastoreClientPool(properties, metastoreURI);
            }
        });
    } catch (ExecutionException ee) {
        throw new IOException("Failed to get " + HiveMetastoreClientPool.class.getSimpleName(), ee.getCause());
    }
}

From source file:org.apache.gobblin.hive.HiveMetastoreClientPool.java

/**
 * Get a {@link HiveMetastoreClientPool} for the requested metastore URI. Useful for using the same pools across
 * different classes in the code base. Note that if a pool already exists for that metastore, the max number of
 * objects available will be unchanged, and it might be lower than requested by this method.
 *
 * @param properties {@link Properties} used to generate the pool.
 * @param metastoreURI URI of the Hive metastore. If absent, use default metastore.
 * @return a {@link HiveMetastoreClientPool}.
 * @throws IOException/*  w w w .j  a va  2 s  .  com*/
 */
public static HiveMetastoreClientPool get(final Properties properties, final Optional<String> metastoreURI)
        throws IOException {
    synchronized (HiveMetastoreClientPool.class) {
        if (poolCache == null) {
            poolCache = createPoolCache(properties);
        }
    }
    try {
        return poolCache.get(metastoreURI, new Callable<HiveMetastoreClientPool>() {
            @Override
            public HiveMetastoreClientPool call() throws Exception {
                return new HiveMetastoreClientPool(properties, metastoreURI);
            }
        });
    } catch (ExecutionException ee) {
        throw new IOException("Failed to get " + HiveMetastoreClientPool.class.getSimpleName(), ee.getCause());
    }
}

From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java

private static boolean didServerReturnNull(ExecutionException e) {
    if (e.getCause() instanceof ParseError) {
        ParseError cause = (ParseError) e.getCause();
        if (cause.getCause() instanceof JSONException) {
            JSONException causeCause = (JSONException) cause.getCause();
            if (causeCause.getMessage().contains("Value null of")) {
                return true;
            }/*w w w .  j  av  a2  s .com*/
        }
    }
    return false;
}

From source file:org.apache.bookkeeper.server.Main.java

static int doMain(String[] args) {

    ServerConfiguration conf;/* www. ja  va2s .com*/

    // 0. parse command line
    try {
        conf = parseCommandLine(args);
    } catch (IllegalArgumentException iae) {
        return ExitCode.INVALID_CONF;
    }

    // 1. building the component stack:
    LifecycleComponent server;
    try {
        server = buildBookieServer(new BookieConfiguration(conf));
    } catch (Exception e) {
        log.error("Failed to build bookie server", e);
        return ExitCode.SERVER_EXCEPTION;
    }

    // 2. start the server
    try {
        ComponentStarter.startComponent(server).get();
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        // the server is interrupted
        log.info("Bookie server is interrupted. Exiting ...");
    } catch (ExecutionException ee) {
        log.error("Error in bookie shutdown", ee.getCause());
        return ExitCode.SERVER_EXCEPTION;
    }
    return ExitCode.OK;
}

From source file:org.eclipse.jubula.rc.javafx.driver.EventThreadQueuerJavaFXImpl.java

/**
 * Executes the given Callable on the JavaFX-Thread and waits for the
 * termination/*from ww  w  .ja  va2  s . c o m*/
 *
 * @param name
 *            a name to identifier which Callable is being executed
 * @param <V>
 *            return value type
 * @param call
 *            the Callable
 * @return
 * @return the return value of the given Callable
 * @throws ExecutionException
 * @throws InterruptedException
 */
public static <V> V invokeAndWait(String name, Callable<V> call) {

    if (Platform.isFxApplicationThread()) {
        try {
            return call.call();
        } catch (Exception e) {
            // the run() method from IRunnable has thrown an exception
            // -> log on info
            // -> throw a StepExecutionException
            Throwable thrown = e.getCause();
            if (thrown instanceof StepExecutionException) {
                if (log.isInfoEnabled()) {
                    log.info(e);
                }
                throw (StepExecutionException) thrown;
            }

            // any other (unchecked) Exception from IRunnable.run()
            log.error("exception thrown by '" + name //$NON-NLS-1$
                    + "':", thrown); //$NON-NLS-1$
            throw new StepExecutionException(thrown);
        }
    }
    try {
        FutureTask<V> task = new FutureTask<>(call);
        Platform.runLater(task);
        return task.get();

    } catch (InterruptedException ie) {
        // this (the waiting) thread was interrupted -> error
        log.error(ie);
        throw new StepExecutionException(ie);
    } catch (ExecutionException ee) {
        // the run() method from IRunnable has thrown an exception
        // -> log on info
        // -> throw a StepExecutionException
        Throwable thrown = ee.getCause();
        if (thrown instanceof StepExecutionException) {
            if (log.isInfoEnabled()) {
                log.info(ee);
            }
            throw (StepExecutionException) thrown;
        }

        // any other (unchecked) Exception from IRunnable.run()
        log.error("exception thrown by '" + name //$NON-NLS-1$
                + "':", thrown); //$NON-NLS-1$
        throw new StepExecutionException(thrown);
    }
}