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.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.java

Class getScriptClass(final String script) throws Exception {
    try {/*w ww.  j a  v  a2 s  .c om*/
        return classMap.get(script).get();
    } catch (ExecutionException e) {
        final Throwable t = e.getCause();

        // more often than not the cause is a compilation problem but there might be other failures that can
        // occur in which case, just throw the ExecutionException as-is and let it bubble up as i'm not sure
        // what the specific handling should be
        if (t instanceof CompilationFailedException)
            throw (CompilationFailedException) t;
        else
            throw e;
    } catch (InterruptedException e) {
        //This should never happen as the future should completed before it is returned to the us.
        throw new AssertionError();
    }
}

From source file:org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles.java

/**
 * This takes the LQI's grouped by likely regions and attempts to bulk load
 * them.  Any failures are re-queued for another pass with the
 * groupOrSplitPhase./*  w w  w.  j av a  2  s .co  m*/
 */
protected void bulkLoadPhase(final HTable table, final HConnection conn, ExecutorService pool,
        Deque<LoadQueueItem> queue, final Multimap<ByteBuffer, LoadQueueItem> regionGroups) throws IOException {
    // atomically bulk load the groups.
    Set<Future<List<LoadQueueItem>>> loadingFutures = new HashSet<Future<List<LoadQueueItem>>>();
    for (Entry<ByteBuffer, ? extends Collection<LoadQueueItem>> e : regionGroups.asMap().entrySet()) {
        final byte[] first = e.getKey().array();
        final Collection<LoadQueueItem> lqis = e.getValue();

        final Callable<List<LoadQueueItem>> call = new Callable<List<LoadQueueItem>>() {
            public List<LoadQueueItem> call() throws Exception {
                List<LoadQueueItem> toRetry = tryAtomicRegionLoad(conn, table.getName(), first, lqis);
                return toRetry;
            }
        };
        loadingFutures.add(pool.submit(call));
    }

    // get all the results.
    for (Future<List<LoadQueueItem>> future : loadingFutures) {
        try {
            List<LoadQueueItem> toRetry = future.get();

            // LQIs that are requeued to be regrouped.
            queue.addAll(toRetry);

        } catch (ExecutionException e1) {
            Throwable t = e1.getCause();
            if (t instanceof IOException) {
                // At this point something unrecoverable has happened.
                // TODO Implement bulk load recovery
                throw new IOException("BulkLoad encountered an unrecoverable problem", t);
            }
            LOG.error("Unexpected execution exception during bulk load", e1);
            throw new IllegalStateException(t);
        } catch (InterruptedException e1) {
            LOG.error("Unexpected interrupted exception during bulk load", e1);
            throw (InterruptedIOException) new InterruptedIOException().initCause(e1);
        }
    }
}

From source file:org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles.java

/**
 * @return A Multimap<startkey, LoadQueueItem> that groups LQI by likely
 * bulk load region targets./*from w  w  w  .  j  av  a2 s .co  m*/
 */
private Multimap<ByteBuffer, LoadQueueItem> groupOrSplitPhase(final HTable table, ExecutorService pool,
        Deque<LoadQueueItem> queue, final Pair<byte[][], byte[][]> startEndKeys) throws IOException {
    // <region start key, LQI> need synchronized only within this scope of this
    // phase because of the puts that happen in futures.
    Multimap<ByteBuffer, LoadQueueItem> rgs = HashMultimap.create();
    final Multimap<ByteBuffer, LoadQueueItem> regionGroups = Multimaps.synchronizedMultimap(rgs);

    // drain LQIs and figure out bulk load groups
    Set<Future<List<LoadQueueItem>>> splittingFutures = new HashSet<Future<List<LoadQueueItem>>>();
    while (!queue.isEmpty()) {
        final LoadQueueItem item = queue.remove();

        final Callable<List<LoadQueueItem>> call = new Callable<List<LoadQueueItem>>() {
            public List<LoadQueueItem> call() throws Exception {
                List<LoadQueueItem> splits = groupOrSplit(regionGroups, item, table, startEndKeys);
                return splits;
            }
        };
        splittingFutures.add(pool.submit(call));
    }
    // get all the results.  All grouping and splitting must finish before
    // we can attempt the atomic loads.
    for (Future<List<LoadQueueItem>> lqis : splittingFutures) {
        try {
            List<LoadQueueItem> splits = lqis.get();
            if (splits != null) {
                queue.addAll(splits);
            }
        } catch (ExecutionException e1) {
            Throwable t = e1.getCause();
            if (t instanceof IOException) {
                LOG.error("IOException during splitting", e1);
                throw (IOException) t; // would have been thrown if not parallelized,
            }
            LOG.error("Unexpected execution exception during splitting", e1);
            throw new IllegalStateException(t);
        } catch (InterruptedException e1) {
            LOG.error("Unexpected interrupted exception during splitting", e1);
            throw (InterruptedIOException) new InterruptedIOException().initCause(e1);
        }
    }
    return regionGroups;
}

From source file:org.apache.hadoop.hbase.master.assignment.TestAssignmentManager.java

private byte[] waitOnFuture(final Future<byte[]> future) throws Exception {
    try {/*  w  w w.  j a va  2  s. c o m*/
        return future.get(5, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        LOG.info("ExecutionException", e);
        throw (Exception) e.getCause();
    }
}

From source file:burlov.ultracipher.swing.SwingGuiApplication.java

/**
 * @param withConfirmation//w ww. j  a va  2s . c  o  m
 * @return 'true' wenn kein Abbruch durch Benutzer
 */
private boolean createNewCryptor(boolean withConfirmation) {
    char[] psw = inputPassphrase(withConfirmation, "Passphrase");
    if (psw == null) {
        return false;
    }
    CreateCryptorTask task = new CreateCryptorTask(psw);
    WaitDialog dlg = new WaitDialog(getMainFrame(), "Generate key", task, 0, 100);
    dlg.start();
    try {
        core.setCryptor(task.get());
    } catch (ExecutionException e) {
        e.getCause().printStackTrace();
        showError(e);
    } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
    }
    Arrays.fill(psw, '*');
    return true;

}

From source file:org.apache.jackrabbit.oak.segment.CompactionAndCleanupIT.java

@Test
public void testCancelCompaction() throws Throwable {
    final FileStore fileStore = fileStoreBuilder(getFileStoreFolder())
            .withGCOptions(defaultGCOptions().setRetainedGenerations(2)).withMaxFileSize(1).build();
    SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();

    NodeBuilder builder = nodeStore.getRoot().builder();
    addNodes(builder, 10);/*from   w w w .j a v  a  2s .  c om*/
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    fileStore.flush();

    FutureTask<Boolean> async = runAsync(new Callable<Boolean>() {
        @Override
        public Boolean call() throws IOException {
            boolean cancelled = false;
            for (int k = 0; !cancelled && k < 1000; k++) {
                cancelled = !fileStore.compact();
            }
            return cancelled;
        }
    });

    // Give the compaction thread a head start
    sleepUninterruptibly(1, SECONDS);

    fileStore.close();
    try {
        assertTrue(async.get());
    } catch (ExecutionException e) {
        if (!(e.getCause() instanceof IllegalStateException)) {
            // Throw cause unless this is an ISE thrown by the
            // store being already closed, which is kinda expected
            throw e.getCause();
        }
    }
}

From source file:org.apache.flume.sink.hdfs.BucketWriter.java

/**
 * Execute the callable on a separate thread and wait for the completion for
 * the specified amount of time in milliseconds. In case of timeout cancel
 * the callable and throw an IOException
 *///from   w w  w  . j  a v  a2 s  .c o m
private <T> T callWithTimeout(final CallRunner<T> callRunner) throws IOException, InterruptedException {
    Future<T> future = callTimeoutPool.submit(new Callable<T>() {
        @Override
        public T call() throws Exception {
            return proxyUser.execute(new PrivilegedExceptionAction<T>() {
                @Override
                public T run() throws Exception {
                    return callRunner.call();
                }
            });
        }
    });
    try {
        if (callTimeout > 0) {
            return future.get(callTimeout, TimeUnit.MILLISECONDS);
        } else {
            return future.get();
        }
    } catch (TimeoutException eT) {
        future.cancel(true);
        sinkCounter.incrementConnectionFailedCount();
        throw new IOException("Callable timed out after " + callTimeout + " ms" + " on file: " + bucketPath,
                eT);
    } catch (ExecutionException e1) {
        sinkCounter.incrementConnectionFailedCount();
        Throwable cause = e1.getCause();
        if (cause instanceof IOException) {
            throw (IOException) cause;
        } else if (cause instanceof InterruptedException) {
            throw (InterruptedException) cause;
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else if (cause instanceof Error) {
            throw (Error) cause;
        } else {
            throw new RuntimeException(e1);
        }
    } catch (CancellationException ce) {
        throw new InterruptedException("Blocked callable interrupted by rotation event");
    } catch (InterruptedException ex) {
        LOG.warn("Unexpected Exception " + ex.getMessage(), ex);
        throw ex;
    }
}

From source file:com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient.java

@Override
public SchemaIdVersion addSchemaVersion(final String schemaName, final SchemaVersion schemaVersion)
        throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException {

    try {/*w  ww .  j  av a2s. c o  m*/
        return schemaTextCache.get(buildSchemaTextEntry(schemaVersion, schemaName),
                () -> doAddSchemaVersion(schemaName, schemaVersion));
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        LOG.error("Encountered error while adding new version [{}] of schema [{}] and error [{}]",
                schemaVersion, schemaName, e);
        if (cause != null) {
            if (cause instanceof InvalidSchemaException)
                throw (InvalidSchemaException) cause;
            else if (cause instanceof IncompatibleSchemaException) {
                throw (IncompatibleSchemaException) cause;
            } else if (cause instanceof SchemaNotFoundException) {
                throw (SchemaNotFoundException) cause;
            } else {
                throw new RuntimeException(cause.getMessage(), cause);
            }
        } else {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public List<String> getGroups(String user) throws IOException {
    assert user != null;

    try {//  w  ww .jav a  2s .  com
        return userToGroupsCache.get(user);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public String getUserName(int userId) throws IOException {
    if (userId == 0) {
        return null;
    }/*ww  w.j a  v a  2  s . c o m*/

    try {
        return idToUserCache.get(userId);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}