/** {@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; } } }); }
/** * @param fut Future to listen. * @return {@code true} If future was not completed and this job should holdCC. */ private boolean callAsync(IgniteFuture fut) { if (fut.isDone()) return false; jobCtx.holdcc(); fut.listen(lsnr); return true; }
/** {@inheritDoc} */ @Override public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException { platformCtx.gateway().onClientDisconnected(); // 1) onReconnected is called on all grid components. // 2) After all of grid components have completed their reconnection, reconnectFut is completed. reconnectFut.listen(new CI1<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> future) { platformCtx.gateway().onClientReconnected(clusterRestarted); } }); }
/** * Starts the background cleanup of old cache entries. * * @param grid Grid. * @param metaCache Meta cache. * @param dataCacheName Data cache name. * @param currentVersions Current versions. */ private void startBackgroundCleanup(Ignite grid, final Cache<CleanupNodeId, UUID> metaCache, final String dataCacheName, final Map<String, EntryProcessorResult<Long>> currentVersions) { if (cleanupFlags.containsKey(dataCacheName)) return; // Current node already performs cleanup. if (!trySetGlobalCleanupFlag(grid, metaCache)) return; cleanupFlags.put(dataCacheName, true); final ClusterGroup dataNodes = grid.cluster().forDataNodes(dataCacheName); IgniteFuture f = grid.compute(dataNodes).broadcastAsync( new RemoveOldEntriesRunnable(dataCacheName, currentVersions)); f.listen(new CleanupCompletionListener(metaCache, dataCacheName)); }
fut.listen(new IgniteInClosure<IgniteFuture<BitSet>>() { @Override public void apply(final IgniteFuture<BitSet> fut) {
fut.listen(new CI1<IgniteFuture<Object>>() { @Override public void apply(IgniteFuture<Object> f) { jobCtx.callcc();
@Override public void applyx(Transaction tx) throws IgniteCheckedException { try { IgniteFuture<Void> rollbackFut = tx.rollbackAsync(); rollbackFut.listen(fut -> tx.close()); } catch (Throwable t) { log.error("Exception on async rollback", t); throw new IgniteCheckedException("Rollback failed", t); } } };
X.println("Submitted jobs: " + cnt); fut.listen(new CIX1<IgniteFuture<Boolean>>() { @Override public void applyx(IgniteFuture<Boolean> f) { try {
ldr.addData(entries).listen(new IgniteInClosure<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> future) { try {
/** * @throws Exception If fails. */ @Test public void testRuntimeException() throws Exception { Ignite ignite = grid(0); ignite.compute().runAsync(new IgniteRunnable() { @Override public void run() { try { Thread.sleep(500); } catch (InterruptedException ignored) { // No-op. } } }).listen(new IgniteInClosure<IgniteFuture<Void>>() { @Override public void apply(IgniteFuture<Void> future) { throw new RuntimeException(); } }); } }
/** * @throws Exception If failed. */ @Test public void testAsyncOps() throws Exception { final AtomicInteger cnt = new AtomicInteger(); final GridAtomicInteger max = new GridAtomicInteger(); for (int i = 0; i < 5000; i++) { final int i0 = i; cnt.incrementAndGet(); jcache().putAsync("key" + i, i).listen(new CI1<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> t) { cnt.decrementAndGet(); max.setIfGreater(cnt.get()); if (i0 > 0 && i0 % 100 == 0) info("cnt: " + cnt.get()); } }); assertTrue("Maximum number of permits exceeded: " + max.get(), max.get() <= 51); } } }
f.listen(new CI1<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> o) { q.poll();
@Override public void applyx() throws IgniteCheckedException { while (true) { int cnt = jobsCnt.incrementAndGet(); if (cnt > 5000) break; IgniteCallable<Boolean> job; job = new ServiceDescriptorsJob(); IgniteFuture<Boolean> fut = ignite1.compute().callAsync(job); if (cnt % LOG_MOD == 0) X.println("Submitted jobs: " + cnt); fut.listen(new CIX1<IgniteFuture<Boolean>>() { @Override public void applyx(IgniteFuture<Boolean> f) { try { assert f.get(); long cnt = resCnt.incrementAndGet(); if (cnt % LOG_MOD == 0) X.println("Results count: " + cnt); } finally { latch.countDown(); } } }); IgniteUtils.sleep(5); } } }, threads, "TEST-THREAD");
fut.listen(new CI1<IgniteFuture>() { @Override public void apply(IgniteFuture fut) { try {
createCacheListener(key, promise, id); promise.listen(new IgniteInClosure<IgniteFuture<String>>() { @Override public void apply(IgniteFuture<String> fut) { GridTestUtils.runAsync(new Callable<Object>() { cache.getAsync(key).listen(new IgniteInClosure<IgniteFuture<String>>() { @Override public void apply(IgniteFuture<String> f) { String val = f.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()); }
chained1.listen(new CI1<IgniteFuture<Integer>>() { @Override public void apply(IgniteFuture<Integer> fut) { try {
clientCache.getAsync("key").listen(new IgniteInClosure<IgniteFuture<Object>>() { @Override public void apply(IgniteFuture<Object> fut) { assertTrue(fut.isDone());