/** * Creates a new index rebuild future that should be completed later after exchange is done. The future * has to be created before exchange is initialized to guarantee that we will capture a correct future * after activation or restore completes. * If there was an old future for the given ID, it will be completed. * * @param cacheId Cache ID. */ private void prepareIndexRebuildFuture(int cacheId) { GridFutureAdapter<Void> old = idxRebuildFuts.put(cacheId, new GridFutureAdapter<>()); if (old != null) old.onDone(); }
/** * Synchronously waits for completion of the task for up to the given timeout. * * @param timeout The maximum time to wait in milliseconds. * @throws IgniteCheckedException In case of an error. */ protected void waitForComplete(long timeout) throws IgniteCheckedException { completeStateFut.get(timeout); }
/** * Chain the future making sure that operation is completed after local schema is updated. * * @param fut Current future. * @return Chained future. */ @SuppressWarnings("unchecked") private GridFutureAdapter<?> publicFuture(GridFutureAdapter fut) { final GridFutureAdapter<?> chainedFut = new GridFutureAdapter<>(); fut.listen(new IgniteInClosure<IgniteInternalFuture>() { @Override public void apply(IgniteInternalFuture fut) { Exception err = null; try { fut.get(); if (cacheRegistered && !nop) qryProc.onLocalOperationFinished(op, type); } catch (Exception e) { err = e; } finally { chainedFut.onDone(null, err); } } }); return chainedFut; }
@Override public Object call() throws Exception { GridFutureAdapter<String> fut = new GridFutureAdapter<>(); fut.onCancelled(); fut.onDone(); return fut.get(); } }, IgniteFutureCancelledCheckedException.class, null);
/** */ private void completeWithException(GridFutureAdapter fut, Throwable e) { fut.onDone(e); if (e instanceof Error) throw (Error)e; }
@Override public Object call() throws Exception { Random rnd = new Random(); while (!done) { for (int j = 0; j < rnd.nextInt(10); j++) { GridFutureAdapter<Object> fut = new GridFutureAdapter<>(); futs.add(fut); for (int k = 1; k < rnd.nextInt(3); k++) { fut.listen(new IgniteInClosure<IgniteInternalFuture<Object>>() { @Override public void apply(IgniteInternalFuture<Object> t) { try { t.get(); } catch (IgniteCheckedException e) { e.printStackTrace(); } cnt.increment(); } }); } } GridFutureAdapter<Object> fut; while ((fut = futs.poll()) != null) fut.onDone(); } return null; } });
/** * @throws Exception If failed. */ private static void testFutureWithGet() throws Exception { n = 0; long start = System.currentTimeMillis(); for (int i = 0; i < MAX; i++) { GridFutureAdapter<Integer> f = new GridFutureAdapter<>(); f.onDone(n); f.get(); n += 2; } long time = System.currentTimeMillis() - start; X.println("Future with get time: " + time); }
/** * Returns if the task completed. * * @return {@code true} if the task completed, otherwise {@code false}. */ protected boolean isCompleted() { return completeStateFut.isDone(); }
/** {@inheritDoc} */ @Override public void suspend() { suspendFut = new GridFutureAdapter<>(); }
@Override public Object call() throws Exception { GridFutureAdapter<String> fut = new GridFutureAdapter<>(); fut.onCancelled(); return fut.get(); } }, IgniteFutureCancelledCheckedException.class, null);
/** * Basically the same as {@link #startWrite(String, byte[])} but for CAS operations. */ private boolean startCas(String key, byte[] expValBytes, byte[] newValBytes) throws IgniteCheckedException { UUID reqId = UUID.randomUUID(); GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>(); updateFuts.put(reqId, fut); DiscoveryCustomMessage msg = new DistributedMetaStorageCasMessage(reqId, key, expValBytes, newValBytes); ctx.discovery().sendCustomEvent(msg); return fut.get(); }
/** {@inheritDoc} */ @Override public void onMessage(UUID nodeId, Object msg, byte plc) { MvccMessage msg0 = (MvccMessage)msg; if (msg0.waitForCoordinatorInit() && !initFut.isDone()) { initFut.listen(new IgniteInClosure<IgniteInternalFuture<Void>>() { @Override public void apply(IgniteInternalFuture<Void> fut) { assert curCrd.local(); processMessage(nodeId, msg); } }); } else processMessage(nodeId, msg); }
/** * Updates external process map so that shuffle can proceed with sending messages to reducers. * * @param req Update request. */ private void updateTasks(final HadoopJobInfoUpdateRequest req) { initFut.listen(new CI1<IgniteInternalFuture<?>>() { @Override public void apply(IgniteInternalFuture<?> gridFut) { assert initGuard.get(); assert req.jobId().equals(job.id()); if (req.reducersAddresses() != null) { if (shuffleJob.initializeReduceAddresses(req.reducersAddresses())) { shuffleJob.startSending("external", new IgniteInClosure2X<HadoopProcessDescriptor, HadoopMessage>() { @Override public void applyx(HadoopProcessDescriptor dest, HadoopMessage msg) throws IgniteCheckedException { comm.sendMessage(dest, msg); } }); } } } }); }
resFut.onDone(fut.get()); resFut.onCancelled(); resFut.onDone(e);
/** * Resets future for subsequent reuse. */ public void reset() { final Object oldState = state; if (oldState == INIT) return; if (!isDone(oldState)) throw new IgniteException("Illegal state"); compareAndSetState(oldState, INIT); }
if (fut != null) { if (asyncWaitForTransition) { return new IgniteFutureImpl<>(fut.chain(new C1<IgniteInternalFuture<Void>, Boolean>() { @Override public Boolean apply(IgniteInternalFuture<Void> fut) { Boolean res = globalState.transitionResult();
GridFutureAdapter<String> fut = new GridFutureAdapter<>(); fut.onDone(); assertNull(fut.get()); fut = new GridFutureAdapter<>(); fut.onDone("test"); assertEquals("test", fut.get()); fut = new GridFutureAdapter<>(); fut.onDone(new IgniteCheckedException("TestMessage")); fut = new GridFutureAdapter<>(); fut.onDone("test", new IgniteCheckedException("TestMessage")); fut = new GridFutureAdapter<>(); fut.onDone("test"); fut.onCancelled(); assertEquals("test", fut.get());
GridFutureAdapter<String> fut = new GridFutureAdapter<>(); fut.listen(new CI1<IgniteInternalFuture<String>>() { @Override public void apply(IgniteInternalFuture<String> t) { if (Thread.currentThread() != runThread) fut.onDone(); fut.listen(new CI1<IgniteInternalFuture<String>>() { @Override public void apply(IgniteInternalFuture<String> t) { if (Thread.currentThread() != runThread)