List of usage examples for java.util.concurrent Future isDone
boolean isDone();
From source file:org.opens.tgol.orchestrator.TanaguruOrchestratorImpl.java
/** * //from www . ja v a 2 s.c om * @param auditTimeoutThread * @param act * @return */ private Audit submitAuditAndLaunch(AuditTimeoutThread auditTimeoutThread, Act act) { synchronized (auditTimeoutThread) { Future submitedThread = threadPoolTaskExecutor.submit(auditTimeoutThread); while (submitedThread != null && !submitedThread.isDone()) { try { Thread.sleep(500); } catch (InterruptedException ex) { LOGGER.error("", ex); } if (auditTimeoutThread.isDurationExceedsDelay()) { LOGGER.debug("Audit Duration ExceedsDelay. The audit result " + "is now managed in an asynchronous way."); break; } } if (auditTimeoutThread.getException() != null) { LOGGER.error("new KrashAuditException()"); throw new KrashAuditException(); } return auditTimeoutThread.getAudit(); } }
From source file:org.opennaas.extensions.vcpe.manager.VCPENetworkManager.java
@Override public boolean hasFinishedBuild(String resourceId) throws VCPENetworkManagerException { Future<Boolean> f = futures.get(resourceId); if (f == null) { throw new VCPENetworkManagerException("No building task for resource " + resourceId); }/*from ww w . j a v a 2s . c om*/ return f.isDone(); }
From source file:com.dilmus.dilshad.scabi.core.async.DComputeAsync.java
public boolean isDone() { if (false == m_isPerformInProgress) return true; log.debug("isDone() m_splitTotal : {}", m_splitTotal); log.debug("isDone() m_crunList.size() : {}", m_crunList.size()); log.debug("isDone() m_crunListReady : {}", m_crunListReady); if (false == m_crunListReady) return false; log.debug("isDone() m_crunList.size() : {}", m_crunList.size()); boolean check = true; check = m_futureCompute.isDone();// w w w .jav a2 s.c o m check = m_futureRetry.isDone(); log.debug("isDone() m_futureList.size() : {}", m_futureList.size()); int gap = 0; while (false == m_futureListReady) { // TODO log.debug from this point onwards doesn't work if we don't use log.debug here!!! if (0 == gap % 1000000000) // reduce this number if needed to make it print atleast once log.debug("isDone() m_futureListReady : {}", m_futureListReady); gap++; } log.debug("isDone() m_futureList.size() : {}", m_futureList.size()); for (Future<?> f : m_futureList) { check = f.isDone(); } log.debug("isDone() Exiting finish()"); return check; }
From source file:com.blacklocus.qs.worker.WorkerQueueItemHandler.java
@SuppressWarnings("unchecked") @Override// w ww.j av a2s. co m public void withFuture(QSTaskModel task, final Future<Pair<QSTaskModel, Object>> future) { // I don't know if this is useful or not. QSWorker worker = workers.get(task.handler); if (worker == null) { throw new RuntimeException("No worker available for worker identifier: " + task.handler); } final TaskKitFactory factory = new TaskKitFactory(task, worker, logService, workerIdService); worker.withFuture(factory, new Future<Pair<TaskKitFactory, Object>>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { return future.cancel(mayInterruptIfRunning); } @Override public boolean isCancelled() { return future.isCancelled(); } @Override public boolean isDone() { return future.isDone(); } @Override public Pair<TaskKitFactory, Object> get() throws InterruptedException, ExecutionException { Pair<QSTaskModel, Object> theFuture = future.get(); return Pair.of(factory, theFuture.getRight()); } @Override public Pair<TaskKitFactory, Object> get(long timeout, @SuppressWarnings("NullableProblems") TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Pair<QSTaskModel, Object> theFuture = future.get(timeout, unit); return Pair.of(factory, theFuture.getRight()); } }); }
From source file:fr.duminy.jbackup.core.JBackupImplTest.java
private void testShutdown(boolean longTask, boolean withListener) throws Throwable { BackupConfiguration config = createConfiguration(); LockableJBackup jBackup = new LockableJBackup(config.getArchiveFactory()); if (longTask) { jBackup.lockCompression();//from w w w . j av a 2 s . c o m } TerminationListener listener = withListener ? mock(TerminationListener.class) : null; Future<Void> future; Timer timer; if (longTask) { future = jBackup.backup(config); timer = jBackup.shutdown(listener); if (withListener) { assertThat(timer).as("shutdown timer").isNotNull(); assertThat(timer.isRunning()).as("timer is running").isTrue(); verify(listener, never()).terminated(); } else { assertThat(timer).as("shutdown timer").isNull(); } assertThat(future.isDone()).as("isDone").isFalse(); jBackup.unlockCompression(); waitResult(future); } else { future = jBackup.backup(config); waitResult(future); timer = jBackup.shutdown(listener); if (withListener) { assertThat(timer).as("shutdown timer").isNotNull(); } else { assertThat(timer).as("shutdown timer").isNull(); } } waitEndOfTimerIfAny(timer); if (withListener) { verify(listener, times(1)).terminated(); verifyNoMoreInteractions(listener); } }
From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java
@Test public void testRequestConnectionCancelled() throws Exception { final HttpHost target = new HttpHost("localhost"); final HttpRoute route = new HttpRoute(target); final Future<NHttpClientConnection> future = connman.requestConnection(route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, null); Assert.assertNotNull(future);/*from w w w .j a v a 2 s . c o m*/ Mockito.verify(pool).lease(Matchers.same(route), Matchers.eq("some state"), Matchers.eq(1000L), Matchers.eq(2000L), Matchers.eq(TimeUnit.MILLISECONDS), poolEntryCallbackCaptor.capture()); final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue(); callaback.cancelled(); Assert.assertTrue(future.isDone()); Assert.assertTrue(future.isCancelled()); Assert.assertNull(future.get()); }
From source file:ubic.gemma.analysis.preprocess.batcheffects.ComBat.java
/** * Multithreaded/*from w w w .j av a 2 s .c o m*/ * * @param sdata * @param gammastar * @param deltastar */ private void runNonParametric(final DoubleMatrix2D sdata, DoubleMatrix2D gammastar, DoubleMatrix2D deltastar) { final ConcurrentHashMap<String, DoubleMatrix1D[]> results = new ConcurrentHashMap<String, DoubleMatrix1D[]>(); int numThreads = Math.min(batches.size(), Runtime.getRuntime().availableProcessors()); log.info("Runing nonparametric estimation on " + numThreads + " threads"); Future<?>[] futures = new Future[numThreads]; ExecutorService service = Executors.newCachedThreadPool(); /* * Divvy up batches over threads. */ int batchesPerThread = batches.size() / numThreads; final String[] batchIds = batches.keySet().toArray(new String[] {}); for (int i = 0; i < numThreads; i++) { final int firstBatch = i * batchesPerThread; final int lastBatch = i == (numThreads - 1) ? batches.size() : firstBatch + batchesPerThread; futures[i] = service.submit(new Runnable() { @Override public void run() { for (int k = firstBatch; k < lastBatch; k++) { String batchId = batchIds[k]; DoubleMatrix2D batchData = getBatchData(sdata, batchId); DoubleMatrix1D[] batchResults = nonParametricFit(batchData, gammaHat.viewRow(k), deltaHat.viewRow(k)); results.put(batchId, batchResults); } } }); } service.shutdown(); boolean allDone = false; do { for (Future<?> f : futures) { allDone = true; if (!f.isDone() && !f.isCancelled()) { allDone = false; break; } } } while (!allDone); for (int i = 0; i < batchIds.length; i++) { String batchId = batchIds[i]; DoubleMatrix1D[] batchResults = results.get(batchId); for (int j = 0; j < batchResults[0].size(); j++) { gammastar.set(i, j, batchResults[0].get(j)); } for (int j = 0; j < batchResults[1].size(); j++) { deltastar.set(i, j, batchResults[1].get(j)); } } }
From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java
@Test(expected = ExecutionException.class) public void testRequestConnectionFailed() throws Exception { final HttpHost target = new HttpHost("localhost"); final HttpRoute route = new HttpRoute(target); final Future<NHttpClientConnection> future = connman.requestConnection(route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, null); Assert.assertNotNull(future);//from w w w. ja v a2 s.c o m Mockito.verify(pool).lease(Matchers.same(route), Matchers.eq("some state"), Matchers.eq(1000L), Matchers.eq(2000L), Matchers.eq(TimeUnit.MILLISECONDS), poolEntryCallbackCaptor.capture()); final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue(); callaback.failed(new Exception()); Assert.assertTrue(future.isDone()); future.get(); }
From source file:com.chinamobile.bcbsp.comm.CommunicatorNew.java
/** Clear the sender message thread pool. */ private void clearSendMssgPool() { try {// w ww.j a va 2 s. c o m // Iterator it = this.sendMssgResult.keySet().iterator(); // while(it.hasNext()){ // LOG.info("clearSendMssgPool Test! "+it.toString()); // } for (Future<Boolean> ele : this.sendMssgResult.values()) { if (!ele.isDone()) { ele.get(); } } this.sendMssgResult.clear(); } catch (Exception e) { LOG.error("<clearSendMessage1>" + e); throw new RuntimeException("<clearSendMessage1>", e); } }
From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java
protected ImportReport importExportedEntityToCloneRepository(URI exportURI, ImportConfiguration configuration) throws InterruptedException, ExecutionException { loginToCloneRepositoryAsSystem();/*from w w w . j a v a2 s .c o m*/ long timeStart = System.currentTimeMillis(); Future<ImportReport> importReportFuture = importDao.importRepositoryContentFromURI(exportURI, configuration); while (!importReportFuture.isDone()) { final long timePassed = System.currentTimeMillis() - timeStart; Assert.assertTrue(timePassed < (5 * 60 * 1000), "Import does not seem to have finished."); } return importReportFuture.get(); }