Example usage for java.util.concurrent ExecutionException ExecutionException

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

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException ExecutionException.

Prototype

public ExecutionException(Throwable cause) 

Source Link

Document

Constructs an ExecutionException with the specified cause.

Usage

From source file:Main.java

/**
 * like Platform.runLater but waits until the thread has finished
 * based on: http://www.guigarage.com/2013/01/invokeandwait-for-javafx/
 * @param r the runnable to run in a JavaFX thread
 *//*from   ww  w .  j  a  v  a2s .co m*/
public static void platformRunAndWait(final Runnable r) throws Throwable {
    if (Platform.isFxApplicationThread()) {
        try {
            r.run();
        } catch (Exception e) {
            throw new ExecutionException(e);
        }
    } else {
        final Lock lock = new ReentrantLock();
        final Condition condition = lock.newCondition();
        final boolean[] done = { false };
        // to get around the requirement for final
        final Throwable[] ex = { null };
        lock.lock();
        try {

            Platform.runLater(() -> {
                lock.lock();
                try {
                    r.run();
                } catch (Throwable e) {
                    ex[0] = e;
                } finally {
                    try {
                        done[0] = true;
                        condition.signal();
                    } finally {
                        lock.unlock();
                    }
                }
            });

            while (!done[0])
                condition.await();

            if (ex[0] != null) {
                // re-throw exception from the runLater thread
                throw ex[0];
            }
        } finally {
            lock.unlock();
        }
    }
}

From source file:Main.java

public static void invokeAll(final List<Runnable> tasks, final ExecutorService executor)
        throws InterruptedException, ExecutionException {
    ExecutionException saved = null;

    if (executor != null) {
        final List<Future<?>> futures = new ArrayList<>();
        for (final Runnable task : tasks)
            futures.add(executor.submit(task));

        for (final Future<?> future : futures) {
            try {
                future.get();/*ww  w  . j  av  a2 s  . c  o  m*/
            } catch (InterruptedException e) {
                throw e;
            } catch (ExecutionException e) {
                if (saved == null) {
                    saved = e;
                } else {
                    saved.addSuppressed(e);
                }
            }
        }
    } else {
        for (final Runnable task : tasks) {
            try {
                task.run();
            } catch (Exception e) {
                if (saved == null) {
                    saved = new ExecutionException(e);
                } else {
                    saved.addSuppressed(e);
                }
            }
        }
    }

    if (saved != null)
        throw saved;
}

From source file:name.martingeisse.common.util.PassthroughCache.java

@Override
public V get(K key, Callable<? extends V> producer) throws ExecutionException {
    try {/*from  ww w . j a va  2 s  .  com*/
        return producer.call();
    } catch (Exception e) {
        throw new ExecutionException(e);
    }
}

From source file:com.yahoo.gondola.container.Utils.java

public static boolean pollingWithTimeout(CheckedBooleanSupplier supplier, long waitTimeMs, long timeoutMs,
        Lock lock, Condition condition) throws ExecutionException, InterruptedException {
    long start = System.currentTimeMillis();
    // TODO: default timeout MS should be provided by upper layer.
    if (timeoutMs < 0) {
        waitTimeMs = 1000;/*from   w  w  w  .j  av  a 2 s.  c om*/
    }
    try {
        while (timeoutMs <= 0 || System.currentTimeMillis() - start < timeoutMs) {
            lock(lock);
            try {
                if (supplier.getAsBoolean()) {
                    return true;
                }
                long remain = timeoutMs - (System.currentTimeMillis() - start);
                if (timeoutMs == 0) {
                    break;
                }
                long timeout = timeoutMs == -1 || waitTimeMs < remain || remain <= 0 ? waitTimeMs : remain;
                wait(lock, condition, timeout);
            } finally {
                unlock(lock);
            }
        }
        return false;
    } catch (InterruptedException e) {
        throw e;
    } catch (Exception e) {
        throw new ExecutionException(e);
    }
}

From source file:de.taimos.dvalin.interconnect.core.spring.requestresponse.DaemonRequestResponseMock.java

@Override
public <R> R sync(final UUID uuid, final String queue, final InterconnectObject request,
        final Class<R> responseClazz, final long timeout, final TimeUnit unit) throws ExecutionException {
    try {/*from   w w w  .j  a v a 2 s . co m*/
        return this.async(uuid, queue, request, responseClazz, timeout, unit).get(timeout, unit);
    } catch (final TimeoutException e) {
        throw new ExecutionException(
                new de.taimos.dvalin.interconnect.core.exceptions.TimeoutException(timeout));
    } catch (final InterruptedException e) {
        throw new ExecutionException(e);
    }
}

From source file:com.android.volley.toolbox.RequestFuture.java

private synchronized T doGet(Long timeoutMs) throws InterruptedException, ExecutionException, TimeoutException {
    if (mException != null) {
        throw new ExecutionException(mException);
    }//from www . j av  a 2  s.  co  m

    if (mResultReceived) {
        return mResult;
    }

    if (timeoutMs == null) {
        wait(0);
    } else if (timeoutMs > 0) {
        wait(timeoutMs);
    }

    if (mException != null) {
        throw new ExecutionException(mException);
    }

    if (!mResultReceived) {
        throw new TimeoutException();
    }

    return mResult;
}

From source file:de.fiz.ddb.aas.auxiliaryoperations.ThreadOrganisationSetApprove.java

public ThreadOrganisationSetApprove(OIDs pOIDs, AasPrincipal performer)
        throws IllegalArgumentException, ExecutionException, AASUnauthorizedException {
    this(performer);
    //check mandatory fields
    if (pOIDs == null) {
        throw new IllegalArgumentException("Illegal argument: OIDs = " + pOIDs);
    }/*from w  w w  .j  ava  2  s . c  o  m*/
    ThreadOrganisationRead threadOrgOnWorkDirRead = new ThreadOrganisationRead(pOIDs, performer);
    try {
        this._organisation = threadOrgOnWorkDirRead.call();
        this._oldStatus = this._organisation.getStatus();
    } catch (NameNotFoundException ex) {
        throw new ExecutionException(new NameNotFoundException(
                "OriganOrganization with ID '" + pOIDs + "' was not found. Message: " + ex.getMessage()));
    }
}

From source file:com.ocean.common.concurrent.ext.BasicFuture.java

private T getResult() throws ExecutionException {
    if (this.ex != null) {
        throw new ExecutionException(this.ex);
    }//  w  w w .j av  a 2s  .  com
    return this.result;
}

From source file:io.uploader.drive.task.UploadDirectoryDriveTask.java

@Override
public DriveOperations.OperationResult call() throws Exception {

    DriveOperations.OperationResult res = null;
    try {//w  ww .j  a v a  2  s .co  m
        res = DriveOperations.uploadDirectory(service, destDir, srcDir, overwrite, this.getStopRequester(),
                this.getStatusReporter());
    } catch (Throwable e) {
        logger.error("Error occurred while task was being performed", e);
        throw new ExecutionException(e);
    }
    return res;
}

From source file:org.usrz.libs.riak.response.ChunkedContentHandler.java

@Override
protected Boolean read(PartialResponse<Boolean> partial, InputStream input) throws Exception {
    try {/*from  ww  w.j av  a 2  s .  c o m*/
        final JsonParser parser = mapper.getFactory().createParser(input);
        final MappingIterator<? extends Chunk<T, H>> iterator = mapper.readValues(parser, chunkType);
        while (iterator.hasNextValue()) {
            final Chunk<T, H> chunk = iterator.next();
            if (chunk.putAll(partial, thisInstance))
                continue;
            else
                return false;
        }
        return puttable.close();
    } catch (Throwable throwable) {
        puttable.fail(throwable);
        if (throwable instanceof Exception)
            throw (Exception) throwable;
        throw new ExecutionException(throwable);
    }
}