@Override public Void call() throws Exception { fut.get(); return null; } }, ClusterGroupEmptyException.class, null);
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void listen(final IgniteBiInClosure<Object, Throwable> lsnr) { fut.listen(new IgniteInClosure<IgniteFuture>() { private static final long serialVersionUID = 0L; @Override public void apply(IgniteFuture fut0) { try { lsnr.apply(fut0.get(), null); } catch (Throwable err) { lsnr.apply(null, err); if (err instanceof Error) throw err; } } }); }
/** {@inheritDoc} */ @Override public boolean cancel() { return fut.cancel(); }
/** * @param fut Execution future. * @throws InterruptedException Thrown if wait was interrupted. */ @SuppressWarnings({"UnconditionalWait"}) private void waitForExecution(IgniteFuture fut) throws InterruptedException { long sleep = 250; long threshold = System.currentTimeMillis() + WAIT_TIMEOUT; do synchronized (mux) { mux.wait(sleep); } while (fut != null && !fut.isDone() && !fut.isCancelled() && threshold > System.currentTimeMillis()); assert fut == null || fut.isDone(); }
IgniteFuture<Integer> chained1 = fut.chainAsync(chainClos, customExec); assertFalse(chained1.isDone()); chained1.listen(new TestClosure(latch)); chained1.get(100, TimeUnit.MILLISECONDS); assertTrue(chained1.isDone()); assertEquals(10, (int)chained1.get()); assertTrue(fut.isDone()); assertEquals("10", fut.get()); chained2.listen(new TestClosure(latch1)); chained2.get(100, TimeUnit.MILLISECONDS); assertTrue(chained2.isDone()); assertEquals(10, (int)chained2.get());
/** * @throws Exception If failed. */ @Test public void testChain() throws Exception { GridFutureAdapter<String> fut0 = new GridFutureAdapter<>(); IgniteFutureImpl<String> fut = createFuture(fut0); IgniteFuture<Integer> chained = fut.chain(new C1<IgniteFuture<String>, Integer>() { @Override public Integer apply(IgniteFuture<String> fut) { return Integer.valueOf(fut.get()); } }); assertFalse(chained.isDone()); U.sleep(100); final AtomicInteger lsnrCnt = new AtomicInteger(); chained.listen(new CI1<IgniteFuture<Integer>>() { @Override public void apply(IgniteFuture<Integer> fut) { assertEquals(10, (int)fut.get()); lsnrCnt.incrementAndGet(); } }); fut0.onDone("10"); assertTrue(chained.isDone()); assertEquals(10, (int)chained.get()); assertEquals(1, lsnrCnt.get()); assertTrue(fut.isDone()); assertEquals("10", fut.get()); }
/** {@inheritDoc} */ @Override public long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException { long txId = reader.readLong(); IgniteFuture fut0; switch (type) { case OP_COMMIT_ASYNC: fut0 = tx(txId).commitAsync(); break; case OP_ROLLBACK_ASYNC: fut0 = tx(txId).rollbackAsync(); break; default: return super.processInStreamOutLong(type, reader); } // Future result is the tx itself, we do not want to return it to the platform. IgniteFuture fut = fut0.chain(new C1<IgniteFuture, Object>() { private static final long serialVersionUID = 0L; @Override public Object apply(IgniteFuture fut) { return null; } }); readAndListenFuture(reader, fut); return TRUE; }
/** {@inheritDoc} */ @Override public boolean isCancelled() { return fut.isCancelled(); } }
/** * @throws Exception If test failed. */ private void checkActiveFutures() throws Exception { assertEquals(0, compute(prj).activeTaskFutures().size()); cnt.set(0); Collection<IgniteFuture<Object>> futsList = new ArrayList<>(); for (int i = 0; i < 10; i++) { IgniteFuture<Object> fut = compute(prj).callAsync(new TestWaitCallable<>()); assertFalse(fut.isDone()); Map<IgniteUuid, ComputeTaskFuture<Object>> futs = compute(prj).activeTaskFutures(); assertEquals(i + 1, futs.size()); assertTrue(futs.containsKey(((ComputeTaskFuture)fut).getTaskSession().getId())); futsList.add(fut); } synchronized (mux) { cnt.incrementAndGet(); mux.notifyAll(); } for (IgniteFuture<Object> fut : futsList) fut.get(); assertEquals(0, compute(prj).activeTaskFutures().size()); }
@Override public boolean apply(Event evt) { if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) { info("Disconnected: " + evt); IgniteFuture<?> fut = client.cluster().clientReconnectFuture(); assertNotNull(fut); assertFalse(fut.isDone()); } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) { info("Reconnected: " + evt); reconnectLatch.countDown(); } return true; } }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);