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.yahoo.pulsar.client.impl.PulsarClientImpl.java

@Override
public Producer createProducer(String destination) throws PulsarClientException {
    try {//  ww w .  ja  v  a  2  s. c o m
        return createProducerAsync(destination, new ProducerConfiguration()).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:com.yahoo.pulsar.client.impl.PulsarClientImpl.java

@Override
public Producer createProducer(final String destination, final ProducerConfiguration conf)
        throws PulsarClientException {
    try {//from   w  w  w .  jav a  2  s .com
        return createProducerAsync(destination, conf).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:com.yahoo.pulsar.client.impl.PulsarClientImpl.java

@Override
public Consumer subscribe(String topic, String subscription, ConsumerConfiguration conf)
        throws PulsarClientException {
    try {/*www  . j a  v a  2 s.c  o m*/
        return subscribeAsync(topic, subscription, conf).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.apache.hadoop.fs.s3a.S3AFastOutputStream.java

private void putObject() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Executing regular upload for bucket '{}' key '{}'", bucket, key);
    }/* w w  w.  ja v  a 2s  .  c o m*/
    final ObjectMetadata om = createDefaultMetadata();
    om.setContentLength(buffer.size());
    final PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key,
            new ByteArrayInputStream(buffer.toByteArray()), om);
    putObjectRequest.setCannedAcl(cannedACL);
    putObjectRequest.setGeneralProgressListener(progressListener);
    ListenableFuture<PutObjectResult> putObjectResult = executorService.submit(new Callable<PutObjectResult>() {
        @Override
        public PutObjectResult call() throws Exception {
            return client.putObject(putObjectRequest);
        }
    });
    //wait for completion
    try {
        putObjectResult.get();
    } catch (InterruptedException ie) {
        LOG.warn("Interrupted object upload:" + ie, ie);
        Thread.currentThread().interrupt();
    } catch (ExecutionException ee) {
        throw new IOException("Regular upload failed", ee.getCause());
    }
}

From source file:org.openengsb.connector.script.internal.ScriptServiceImpl.java

private String readResultFromFuture(Future<String> future) throws InterruptedException {
    String result;/*from  w  w  w  .j  a v  a 2s. c om*/
    try {
        result = future.get();
    } catch (ExecutionException e) {
        LOGGER.error(e.getMessage(), e.getCause());
        result = ExceptionUtils.getFullStackTrace(e);
    }
    return result;
}

From source file:org.apache.hadoop.hbase.master.TestTableLockManager.java

@Test(timeout = 600000)
public void testAlterAndDisable() throws Exception {
    prepareMiniCluster();//ww w  . j  a v  a2s.  c  o m
    // Send a request to alter a table, then sleep during
    // the alteration phase. In the mean time, from another
    // thread, send a request to disable, and then delete a table.

    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    master.getMasterCoprocessorHost().load(TestAlterAndDisableMasterObserver.class, 0,
            TEST_UTIL.getConfiguration());

    ExecutorService executor = Executors.newFixedThreadPool(2);
    Future<Object> alterTableFuture = executor.submit(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
            admin.addColumn(TABLE_NAME, new HColumnDescriptor(NEW_FAMILY));
            LOG.info("Added new column family");
            HTableDescriptor tableDesc = admin.getTableDescriptor(TABLE_NAME);
            assertTrue(tableDesc.getFamiliesKeys().contains(NEW_FAMILY));
            return null;
        }
    });
    Future<Object> disableTableFuture = executor.submit(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
            admin.disableTable(TABLE_NAME);
            assertTrue(admin.isTableDisabled(TABLE_NAME));
            admin.deleteTable(TABLE_NAME);
            assertFalse(admin.tableExists(TABLE_NAME));
            return null;
        }
    });

    try {
        disableTableFuture.get();
        alterTableFuture.get();
    } catch (ExecutionException e) {
        if (e.getCause() instanceof AssertionError) {
            throw (AssertionError) e.getCause();
        }
        throw e;
    }
}

From source file:org.jactr.core.model.six.DefaultCycleProcessor6.java

/**
 * run a single cycle of the model/*w  w w .j  a  v  a2  s  .c  om*/
 * 
 * @see java.util.concurrent.Callable#call()
 */
public double cycle(IModel model, boolean eventsHaveFired) {
    BasicModel basicModel = (BasicModel) model;
    execute(_executeBefore);

    /*
     * what time is it?
     */
    double now = ACTRRuntime.getRuntime().getClock(basicModel).getTime();

    basicModel.setCycle(basicModel.getCycle() + 1);
    basicModel.dispatch(new ModelEvent(basicModel, ModelEvent.Type.CYCLE_STARTED));
    double nextWaitTime = Double.NEGATIVE_INFINITY;

    _isExecuting = true;

    try {
        double productionFiringTime = evaluateAndFireProduction(basicModel, now);
        nextWaitTime = calculateNextWaitTime(now, productionFiringTime, basicModel, eventsHaveFired);

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("nextWaitTime : " + nextWaitTime);
    } catch (InterruptedException ie) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Interrupted while executing production. Terminating ");

        nextWaitTime = Double.NaN;
    } catch (ExecutionException e) {
        LOGGER.error("Failed to fire production ", e);
        throw new RuntimeException(e.getMessage(), e.getCause());
    } finally {
        _isExecuting = false;

        /*
         * always fire the cycle stopped event
         */
        basicModel.dispatch(new ModelEvent(basicModel, ModelEvent.Type.CYCLE_STOPPED));

        execute(_executeAfter);
    }

    return nextWaitTime;
}

From source file:org.apache.hive.jdbc.TestJdbcWithMiniHS2.java

private static void startConcurrencyTest(Connection conn, String tableName, int numTasks) {
    // Start concurrent testing
    int POOL_SIZE = 100;
    int TASK_COUNT = numTasks;

    SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<Runnable>();
    ExecutorService workers = new ThreadPoolExecutor(1, POOL_SIZE, 20, TimeUnit.SECONDS, executorQueue);
    List<Future<Boolean>> list = new ArrayList<Future<Boolean>>();
    int i = 0;// ww  w  .j av a2s . c om
    while (i < TASK_COUNT) {
        try {
            Future<Boolean> future = workers.submit(new JDBCTask(conn, i, tableName));
            list.add(future);
            i++;
        } catch (RejectedExecutionException ree) {
            try {
                TimeUnit.MILLISECONDS.sleep(100);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }

    for (Future<Boolean> future : list) {
        try {
            Boolean result = future.get(30, TimeUnit.SECONDS);
            assertTrue(result);
        } catch (ExecutionException ee) {
            fail("Concurrent Statement failed: " + ee.getCause());
        } catch (TimeoutException te) {
            System.out.println("Task was timeout after 30 second: " + te);
        } catch (CancellationException ce) {
            System.out.println("Task was interrupted: " + ce);
        } catch (InterruptedException ie) {
            System.out.println("Thread was interrupted: " + ie);
        }
    }
    workers.shutdown();
}

From source file:org.jboss.additional.testsuite.jdkall.past.eap_6_4_x.clustering.cluster.web.ClusteredWebSimpleTestCase.java

private void abstractGracefulServe(URL baseURL1, boolean undeployOnly)
        throws IllegalStateException, IOException, InterruptedException, Exception {

    final DefaultHttpClient client = HttpClientUtils.relaxedCookieHttpClient();
    String url1 = baseURL1.toString() + SimpleServlet.URL;

    // Make sure a normal request will succeed
    HttpResponse response = client.execute(new HttpGet(url1));
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
    response.getEntity().getContent().close();

    // Send a long request - in parallel
    String longRunningUrl = url1 + "?" + SimpleServlet.REQUEST_DURATION_PARAM + "=" + REQUEST_DURATION;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<HttpResponse> future = executor.submit(new RequestTask(client, longRunningUrl));

    // Make sure long request has started
    Thread.sleep(1000);/*from w ww. j  a v  a 2  s  .co m*/

    if (undeployOnly) {
        // Undeploy the app only.
        undeploy(DEPLOYMENT_1);
    } else {
        // Shutdown server.
        stop(CONTAINER_1);
    }

    // Get result of long request
    // This request should succeed since it initiated before server shutdown
    try {
        response = future.get();
        Assert.assertEquals("Request should succeed since it initiated before undeply or shutdown.",
                HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        response.getEntity().getContent().close();
    } catch (ExecutionException e) {
        e.printStackTrace(System.err);
        Assert.fail(e.getCause().getMessage());
    }

    if (undeployOnly) {
        // If we are only undeploying, then subsequent requests should return 404.
        response = client.execute(new HttpGet(url1));
        Assert.assertEquals("If we are only undeploying, then subsequent requests should return 404.",
                HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
        response.getEntity().getContent().close();
    }

    // Cleanup after test.
    if (undeployOnly) {
        // Redeploy the app only.
        deploy(DEPLOYMENT_1);
    } else {
        // Startup server.
        start(CONTAINER_1);
    }
}

From source file:org.limewire.activation.impl.ActivationCommunicatorTest.java

public void testUnreachableServerClientTimesOut() throws Exception {
    String unreachableIpAddress = "172.16.0.253";
    LimeWireHttpClientModule.class.getClass();
    PrivateAccessor accessor = new PrivateAccessor(Class.forName(LimeWireHttpClientModule.class.getName()),
            null, "CONNECTION_TIMEOUT");
    final int timeout = ((Integer) accessor.getOriginalValue()) + 2000;

    settingsStub.setActivationHost("http://" + unreachableIpAddress + ":5813/sfsdfs");
    Callable<ActivationResponse> contactUnreachableServer = new Callable<ActivationResponse>() {
        @Override//w  w  w. j av a  2 s .c  o m
        public ActivationResponse call() throws Exception {
            return comm.activate("DAVV-XXME-BWU3", RequestType.USER_ACTIVATE);
        }
    };
    ExecutorService poolForReachingServer = Executors.newSingleThreadExecutor();
    Future<ActivationResponse> reachServerResult = poolForReachingServer.submit(contactUnreachableServer);

    try {
        reachServerResult.get(timeout, TimeUnit.MILLISECONDS);
        fail("Expected a SocketTimeoutException");
    } catch (ExecutionException e) {
        assertInstanceof(SocketTimeoutException.class, e.getCause());
    }
}