/** * @param fut Internal future. * @return Public API future. */ private <R> IgniteFuture<R> createFuture(IgniteInternalFuture<R> fut) { return new IgniteFutureImpl<>(fut); }
@Override public Void call() throws Exception { fut.get(); return null; } }, expectedException(), "test error");
/** * Ctor. * * @param fut Future to wrap. */ public ComputeConvertingFuture(ComputeTaskFuture fut) { this.fut = ((IgniteFutureImpl)fut).internalFuture(); }
/** {@inheritDoc} */ @Override public <T> IgniteFuture<T> chain(final IgniteClosure<? super IgniteFuture<V>, T> doneCb) { return new IgniteFutureImpl<>(chainInternal(doneCb, null)); }
/** {@inheritDoc} */ @Override public GridFutureAdapter<?> onDisconnected() { if (state.get() == GridKernalState.DISCONNECTED) { assert reconnectFut != null; return (GridFutureAdapter<?>)reconnectFut.internalFuture(); } GridFutureAdapter<?> fut = new GridFutureAdapter<>(); reconnectFut = new IgniteFutureImpl<>(fut); if (!state.compareAndSet(GridKernalState.STARTED, GridKernalState.DISCONNECTED)) { ((GridFutureAdapter<?>)reconnectFut.internalFuture()).onDone(new IgniteCheckedException("Node stopped.")); return null; } return fut; }
/** * @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()); }
/** * @throws Exception If failed. */ @Test public void testFutureGet() throws Exception { GridFutureAdapter<String> fut0 = new GridFutureAdapter<>(); IgniteFutureImpl<String> fut = createFuture(fut0); assertFalse(fut.isDone()); U.sleep(100); fut0.onDone("test"); assertEquals("test", fut.get()); assertTrue(fut.isDone()); }
proxyImpl.onRestarted(cache.context(), cache.context().cache()); else new IgniteFutureImpl<>(fut).get();
IgniteFuture<Integer> chained = fut.chain(new C1<IgniteFuture<String>, Integer>() { @Override public Integer apply(IgniteFuture<String> fut) { try { fut.get(); IgniteFuture<Integer> chained = fut.chain(new C1<IgniteFuture<String>, Integer>() { @Override public Integer apply(IgniteFuture<String> fut) { try { fut.get();
/** {@inheritDoc} */ @Override public V get() { try { return fut.get(); } catch (IgniteCheckedException e) { throw convertException(e); } }
/** * @param err Err. */ private void checkChainedOnErrorFinishedFuture(final Exception err) throws Exception { IgniteFutureImpl<String> fut = createFuture(new GridFinishedFuture<String>(err)); // Chain callback will be invoked in specific executor. IgniteFuture<Integer> chained1 = fut.chainAsync(new C1<IgniteFuture<String>, Integer>() { @Override public Integer apply(IgniteFuture<String> fut) { assertEquals(CUSTOM_THREAD_NAME, Thread.currentThread().getName()); try { fut.get(); fail(); } catch (IgniteException e) { assertExpectedException(e, err); throw e; } return -1; } }, customExec); assertExceptionThrown(err, chained1); assertExceptionThrown(err, fut); assertTrue(chained1.isDone()); assertTrue(fut.isDone()); }
/** * @throws Exception If failed. */ @Test public void testAsyncListeners() throws Exception { GridFutureAdapter<String> fut0 = new GridFutureAdapter<>(); IgniteFutureImpl<String> fut = createFuture(fut0); final CountDownLatch latch1 = new CountDownLatch(1); IgniteInClosure<? super IgniteFuture<String>> lsnr1 = createAsyncListener(latch1, CUSTOM_THREAD_NAME, null); assertFalse(fut.isDone()); fut.listenAsync(lsnr1, customExec); U.sleep(100); assertEquals(1, latch1.getCount()); fut0.onDone("test"); assert latch1.await(1, TimeUnit.SECONDS) : latch1.getCount(); checkAsyncListener(fut); checkAsyncListener(createFuture(new GridFinishedFuture<>("test"))); }
/** * @param fut Future. */ private void checkAsyncListener(IgniteFutureImpl<String> fut) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); IgniteInClosure<? super IgniteFuture<String>> lsnr = createAsyncListener(latch, CUSTOM_THREAD_NAME, null); fut.listenAsync(lsnr, customExec); assert latch.await(1, TimeUnit.SECONDS) : latch.getCount(); }
/** * @throws Exception If failed. */ @Test public void testFutureException() throws Exception { GridFutureAdapter<String> fut0 = new GridFutureAdapter<>(); final IgniteFutureImpl<String> fut = createFuture(fut0); assertFalse(fut.isDone()); U.sleep(100); IgniteCheckedException err0 = new IgniteCheckedException("test error"); fut0.onDone(err0); Exception err = (Exception)GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { fut.get(); return null; } }, expectedException(), "test error"); assertExpectedException(err, err0); assertTrue(fut.isDone()); err = (Exception)GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { fut.get(); return null; } }, expectedException(), null); assertExpectedException(err, err0); }
IgniteFuture<Integer> chained2 = createFuture(ffut0).chainAsync(chainClos, customExec);
if (curFut != null && curFut.internalFuture() == reconnectFut) userFut = curFut; else { userFut = new IgniteFutureImpl<>(reconnectFut);
/** {@inheritDoc} */ @Override public <T> IgniteFuture<T> chainAsync(final IgniteClosure<? super IgniteFuture<V>, T> doneCb, Executor exec) { A.notNull(doneCb, "doneCb"); A.notNull(exec, "exec"); return new IgniteFutureImpl<>(chainInternal(doneCb, exec)); }
/** {@inheritDoc} */ @Override public V get(long timeout, TimeUnit unit) { try { return fut.get(timeout, unit); } catch (IgniteCheckedException e) { throw convertException(e); } }