Example usage for java.util.concurrent FutureTask get

List of usage examples for java.util.concurrent FutureTask get

Introduction

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

Prototype

public V get() throws InterruptedException, ExecutionException 

Source Link

Usage

From source file:org.nuxeo.ecm.core.management.jtajca.CanMonitorTransactionsTest.java

@Test
public void isActiveStatisticsCollected() throws InterruptedException, ExecutionException {
    FutureTask<Boolean> task = new FutureTask<Boolean>(new TestCollectStatistics());
    executor.execute(task);/*w  ww .ja  v  a2s. c o m*/
    assertThat(task.get(), is(true));
}

From source file:org.nuxeo.ecm.core.management.jtajca.CanMonitorTransactionsTest.java

@Test
@LogCaptureFeature.FilterWith(value = CanMonitorTransactionsTest.LogMessageFilter.class)
public void logContainsTxKey() throws InterruptedException, ExecutionException, NoLogCaptureFilterException {
    FutureTask<Boolean> task = new FutureTask<Boolean>(new TestLogRollbackTrace());
    executor.execute(task);//from w w w  .  j ava  2 s. co  m
    assertThat(task.get(), is(true));
    logCaptureResults.assertHasEvent();
}

From source file:org.nuxeo.ecm.core.management.jtajca.CanMonitorTransactionsTest.java

@Test
@LogCaptureFeature.FilterWith(value = CanMonitorTransactionsTest.LogRollbackTraceFilter.class)
public void logContainsRollbackTrace()
        throws InterruptedException, ExecutionException, NoLogCaptureFilterException {
    FutureTask<Boolean> task = new FutureTask<Boolean>(new TestLogRollbackTrace());
    executor.execute(task);//from   w ww  . j a v a2 s .  co  m
    assertThat(task.get(), is(true));
    logCaptureResults.assertHasEvent();
}

From source file:org.nuxeo.runtime.jtajca.management.CanMonitorTransactions.java

@Test
@LogCaptureFeature.FilterWith(value = CanMonitorTransactions.LogMessageFilter.class)
public void logContainsTxKey() throws InterruptedException, ExecutionException, NoLogCaptureFilterException {
    FutureTask<Boolean> task = new FutureTask<Boolean>(new TestLogRollbackTrace());
    executor.execute(task);/*from  w ww  .  j  a  v a  2s.c  o  m*/
    assertThat(task.get(), is(true));
    logCaptureResults.assertHasEvent();
}

From source file:org.nuxeo.runtime.jtajca.management.CanMonitorTransactions.java

@Test
@LogCaptureFeature.FilterWith(value = CanMonitorTransactions.LogRollbackTraceFilter.class)
public void logContainsRollbackTrace()
        throws InterruptedException, ExecutionException, NoLogCaptureFilterException {
    FutureTask<Boolean> task = new FutureTask<Boolean>(new TestLogRollbackTrace());
    executor.execute(task);/* w w  w .j a va2 s. c  o  m*/
    assertThat(task.get(), is(true));
    logCaptureResults.assertHasEvent();
}

From source file:org.nuxeo.ecm.core.management.jtajca.CanMonitorTransactionsTest.java

@Test
public void isTotalRollbacksCorrect() throws InterruptedException, ExecutionException {
    assertThat(monitor.getActiveCount(), is(1L));
    FutureTask<Boolean> rollback = new FutureTask<Boolean>(new TestTotalRollbacks());
    executor.execute(rollback);/*ww  w .ja  v  a  2s. c o  m*/
    assertThat(rollback.get(), is(true));
}

From source file:com.alibaba.napoli.metamorphosis.client.extension.producer.LocalMessageStorageManager.java

private Store getStore(final String topic, final FutureTask<Store> task) {
    try {/*from   w w  w  .  ja v  a 2  s .  co m*/
        return task.get();
    } catch (final Throwable t) {
        log.error("?topic=" + topic + "store", t);
        throw new GetRecoverStorageErrorException("?topic=" + topic + "store", t);
    }

}

From source file:com.ciphertool.sentencebuilder.etl.importers.FrequencyListImporterImpl.java

@Override
public void importFrequencyList() {
    // Reset the counts in case this method is called again
    rowUpdateCount.set(0);//from   w w  w.j a v  a 2s  . c  om
    rowInsertCount.set(0);

    long start = System.currentTimeMillis();

    try {

        List<Word> wordsFromFile = frequencyFileParser.parseFile();

        log.info("Starting frequency list import...");

        List<FutureTask<Void>> futureTasks = new ArrayList<FutureTask<Void>>();
        FutureTask<Void> futureTask = null;
        List<Word> threadedWordBatch = new ArrayList<Word>();
        for (Word word : wordsFromFile) {
            threadedWordBatch.add(word);

            if (threadedWordBatch.size() >= this.concurrencyBatchSize) {
                List<Word> nextThreadedWordBatch = new ArrayList<Word>();
                int originalSize = threadedWordBatch.size();

                for (int i = 0; i < originalSize; i++) {
                    /*
                     * It's faster to remove from the end of the List
                     * because no elements need to shift
                     */
                    nextThreadedWordBatch.add(threadedWordBatch.remove(threadedWordBatch.size() - 1));
                }

                futureTask = new FutureTask<Void>(new BatchWordImportTask(nextThreadedWordBatch));
                futureTasks.add(futureTask);
                this.taskExecutor.execute(futureTask);
            }
        }

        /*
         * Start one last task if there are any leftover Words from file
         * that did not reach the batch size.
         */
        if (threadedWordBatch.size() > 0) {
            /*
             * It's safe to use the threadedWordBatch now, instead of
             * copying into a temporaryList, because this is the last thread
             * to run.
             */
            futureTask = new FutureTask<Void>(new BatchWordImportTask(threadedWordBatch));
            futureTasks.add(futureTask);
            this.taskExecutor.execute(futureTask);
        }

        for (FutureTask<Void> future : futureTasks) {
            try {
                future.get();
            } catch (InterruptedException ie) {
                log.error("Caught InterruptedException while waiting for BatchWordImportTask ", ie);
            } catch (ExecutionException ee) {
                log.error("Caught ExecutionException while waiting for BatchWordImportTask ", ee);
            }
        }
    } finally {
        log.info("Rows updated: " + this.rowUpdateCount);
        log.info("Rows inserted: " + this.rowInsertCount);
        log.info("Time elapsed: " + (System.currentTimeMillis() - start) + "ms");
    }
}

From source file:org.apache.cxf.dosgi.systests.common.rest.AbstractListenerHookServiceListenerTest.java

private void verifyGreeterResponse(FutureTask<GreeterInfo> task, Object mutex) throws Exception {
    GreeterInfo greetings = null;/*  w  w w. j av a2  s  . co m*/
    synchronized (mutex) {
        while (task == null) {
            mutex.wait(500);
        }
        greetings = task.get();
    }

    assertEquals("4 greetings expected", 4, greetings.getGreetings().size());
}

From source file:org.geek.utils.ApplicationUtils.java

public static String getRequest(final String url) throws InterruptedException, ExecutionException {
    FutureTask<String> task = new FutureTask<String>(new Callable<String>() {

        @Override/*from w ww.jav  a  2 s.c om*/
        public String call() throws Exception {
            // HttpGet  
            HttpGet get = new HttpGet(url);
            // ??get  
            HttpResponse httpResponse = httpClient.execute(get);
            // ???  
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                // ???  
                return EntityUtils.toString(httpResponse.getEntity());
            }
            return null;
        }
    });
    new Thread(task).start();
    return task.get();
}