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:com.imaginary.home.controller.Command.java

private @Nonnull boolean[] waitFor(@Nonnull ArrayList<Future<Boolean>> threads)
        throws ControllerException, CommunicationException {
    boolean[] results = new boolean[threads.size()];
    long t = System.currentTimeMillis() + timeout;
    boolean done = true;
    int i = 0;//from   w w w .  ja v a 2 s. co  m

    for (Future<Boolean> f : threads) {
        done = false;
        while (t > System.currentTimeMillis()) {
            try {
                if (f.isDone()) {
                    results[i++] = f.get();
                    done = true;
                    break;
                }
                try {
                    Thread.sleep(500L);
                } catch (InterruptedException ignore) {
                }
            } catch (ExecutionException e) {
                if (e.getCause() instanceof ControllerException) {
                    throw (ControllerException) e.getCause();
                } else if (e.getCause() instanceof CommunicationException) {
                    throw (CommunicationException) e.getCause();
                }
                throw new ControllerException(e);
            } catch (InterruptedException e) {
                throw new ControllerException(e);
            }
        }
        if (!done && !f.isDone()) {
            f.cancel(true);
        }
    }
    if (!done) {
        throw new ControllerException("Action timed out");
    }
    return results;
}

From source file:com.cloudera.livy.client.local.rpc.TestRpc.java

@Test
public void testNotDeserializableRpc() throws Exception {
    RpcServer server = autoClose(new RpcServer(emptyConfig));
    Rpc[] rpcs = createRpcConnection(server);
    Rpc client = rpcs[1];// w  ww. j  a  v  a2  s.  com

    try {
        client.call(new NotDeserializable(42)).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException ee) {
        assertTrue(ee.getCause() instanceof RpcException);
        assertTrue(ee.getCause().getMessage().indexOf("KryoException") >= 0);
    }
}

From source file:com.buaa.cfs.security.Groups.java

/**
 * Get the group memberships of a given user. If the user's group is not cached, this method may block.
 *
 * @param user User's name//from w w  w.ja v  a  2s .co m
 *
 * @return the group memberships of the user
 *
 * @throws IOException if user does not exist
 */
public List<String> getGroups(final String user) throws IOException {
    // No need to lookup for groups of static users
    List<String> staticMapping = staticUserToGroupsMap.get(user);
    if (staticMapping != null) {
        return staticMapping;
    }

    // Check the negative cache first
    if (isNegativeCacheEnabled()) {
        if (negativeCache.contains(user)) {
            throw noGroupsForUser(user);
        }
    }

    try {
        return cache.get(user);
    } catch (ExecutionException e) {
        throw (IOException) e.getCause();
    }
}

From source file:org.opennms.core.rpc.camel.EchoRpcIT.java

/**
 * Verifies that the future fails with the original exception if
 * an error occurs when executing locally.
 *//*from  www .j a v a2  s .  c o  m*/
@Test(timeout = 60000)
public void futureFailsWithOriginalExceptionWhenExecutingLocally()
        throws InterruptedException, ExecutionException {
    EchoRequest request = new EchoRequest("Oops!");
    request.shouldThrow(true);
    try {
        echoClient.execute(request).get();
        fail();
    } catch (ExecutionException e) {
        assertEquals("Oops!", e.getCause().getMessage());
        assertEquals(MyEchoException.class, e.getCause().getClass());
    }
}

From source file:org.apache.pulsar.client.impl.ConsumerBuilderImpl.java

@Override
public Consumer<T> subscribe() throws PulsarClientException {
    try {/*from  www.  j  a va2 s  . co m*/
        return subscribeAsync().get();
    } catch (ExecutionException e) {
        Throwable t = e.getCause();
        if (t instanceof PulsarClientException) {
            throw (PulsarClientException) t;
        } else {
            throw new PulsarClientException(t);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new PulsarClientException(e);
    }
}

From source file:org.opennms.core.rpc.camel.EchoRpcIT.java

/**
 * Verifies that the future fails with a {@code RemoteExecutionException} when
 * if an error occurs when executing remotely.
 *///from ww w  . j a va 2  s  .c o m
@Test(timeout = 60000)
public void futureFailsWithRemoteExecutionExceptionWhenExecutingRemotely() throws Exception {
    assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
    EchoRpcModule echoRpcModule = new EchoRpcModule();

    SimpleRegistry registry = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("queuingservice", queuingservice);

    CamelRpcServerRouteManager routeManager = new CamelRpcServerRouteManager(context,
            new MockMinionIdentity(REMOTE_LOCATION_NAME));
    routeManager.bind(echoRpcModule);

    EchoRequest request = new EchoRequest("Oops!");
    request.shouldThrow(true);
    request.setLocation(REMOTE_LOCATION_NAME);
    try {
        echoClient.execute(request).get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause().getMessage(), e.getCause().getMessage().contains("Oops!"));
        assertEquals(RemoteExecutionException.class, e.getCause().getClass());
    }

    routeManager.unbind(echoRpcModule);
    context.stop();
}

From source file:com.basho.riak.client.api.commands.itest.ITestFetchValue.java

private void simpleTest(String bucketType) {
    try {//  ww  w .j a  v a2  s  .  co  m
        RiakClient client = new RiakClient(cluster);
        Namespace ns = new Namespace(bucketType, bucketName.toString());
        Location loc = new Location(ns, "test_fetch_key1");

        Pojo pojo = new Pojo();
        pojo.value = "test value";
        StoreValue sv = new StoreValue.Builder(pojo).withLocation(loc).build();

        StoreValue.Response resp = client.execute(sv);

        FetchValue fv = new FetchValue.Builder(loc).build();
        FetchValue.Response fResp = client.execute(fv);

        assertEquals(pojo.value, fResp.getValue(Pojo.class).value);

        RiakObject ro = fResp.getValue(RiakObject.class);
        assertNotNull(ro.getValue());
        assertEquals("{\"value\":\"test value\"}", ro.getValue().toString());
    } catch (ExecutionException ex) {
        System.out.println(ex.getCause().getCause());
    } catch (InterruptedException ex) {
        Logger.getLogger(ITestFetchValue.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:co.cask.cdap.internal.app.runtime.service.InMemoryProgramRuntimeService.java

private void stopAllPrograms() {

    LOG.info("Stopping all running programs.");

    List<ListenableFuture<ProgramController>> futures = Lists.newLinkedList();
    for (ProgramType type : ProgramType.values()) {
        for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) {
            RuntimeInfo runtimeInfo = entry.getValue();
            if (isRunning(runtimeInfo.getProgramId())) {
                futures.add(runtimeInfo.getController().stop());
            }/*from  w w w  .  j a va  2s  .  com*/
        }
    }
    // unchecked because we cannot do much if it fails. We will still shutdown the standalone CDAP instance.
    try {
        Futures.successfulAsList(futures).get(60, TimeUnit.SECONDS);
        LOG.info("All programs have been stopped.");
    } catch (ExecutionException e) {
        // note this should not happen because we wait on a successfulAsList
        LOG.warn("Got exception while waiting for all programs to stop", e.getCause());
    } catch (InterruptedException e) {
        LOG.warn("Got interrupted exception while waiting for all programs to stop", e);
        Thread.currentThread().interrupt();
    } catch (TimeoutException e) {
        // can't do much more than log it. We still want to exit.
        LOG.warn("Timeout while waiting for all programs to stop.");
    }
}

From source file:com.cloudera.livy.client.local.rpc.TestRpc.java

@Test
public void testClientTimeout() throws Exception {
    RpcServer server = autoClose(new RpcServer(emptyConfig));
    String secret = server.createSecret();

    try {/*from w ww .  ja v a2  s  .c o  m*/
        autoClose(server.registerClient("client", secret, new TestDispatcher(), 1L).get());
        fail("Server should have timed out client.");
    } catch (ExecutionException ee) {
        assertTrue(ee.getCause() instanceof TimeoutException);
    }

    NioEventLoopGroup eloop = new NioEventLoopGroup();
    Future<Rpc> clientRpcFuture = Rpc.createClient(emptyConfig, eloop, "localhost", server.getPort(), "client",
            secret, new TestDispatcher());
    try {
        autoClose(clientRpcFuture.get());
        fail("Client should have failed to connect to server.");
    } catch (ExecutionException ee) {
        // Error should not be a timeout.
        assertFalse(ee.getCause() instanceof TimeoutException);
    }
}

From source file:com.yahoo.omid.transaction.HBaseTransactionManager.java

@Override
public long getLowWatermark() throws TransactionException {
    try {// w  w  w  . j  a v  a2  s  .  c om
        return commitTableClient.readLowWatermark().get();
    } catch (ExecutionException ee) {
        throw new TransactionException("Error reading low watermark", ee.getCause());
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new TransactionException("Interrupted reading low watermark", ie);
    }
}