@Override public Map<K, V> applyx(GridFuture<Map<K, V>> f) throws GridException { return interceptGet(keys, f.get()); } });
/** * @param f Target future. * @return Wrapped future that is aware of cloning behaviour. */ public GridFuture<V> wrapClone(GridFuture<V> f) { if (!hasFlag(CLONE)) return f; return f.chain(new CX1<GridFuture<V>, V>() { @Override public V applyx(GridFuture<V> f) throws GridException { return cloneValue(f.get()); } }); }
/** {@inheritDoc} */ @Override public T get() throws ExecutionException { try { T res = fut.get(); if (fut.isCancelled()) throw new CancellationException("Task was cancelled: " + fut); return res; } catch (GridException e) { // Task cancellation may cause throwing exception. if (fut.isCancelled()) { RuntimeException ex = new CancellationException("Task was cancelled: " + fut); ex.initCause(e); throw ex; } throw new ExecutionException("Failed to get task result: " + fut, e); } }
/** * @param <T> Type of command result. * @param fut Future to add. * @return Future for command. */ @SuppressWarnings("unchecked") private <T> Future<T> addFuture(GridFuture<T> fut) { synchronized (mux) { if (!fut.isDone()) { fut.listenAsync(lsnr); futs.add(fut); } return new TaskFutureWrapper<>(fut); } }
if (fut == null || fut.isDone()) { boolean prepared; prepared = fut == null ? true : fut.get(); fut.listenAsync(new CI1<GridFuture<Boolean>>() { @Override public void apply(GridFuture<Boolean> fut) { boolean prepared;
/** * Adds listener to asynchronously log errors. * * @param f Future to listen to. * @param log Logger. */ public static void asyncLogError(GridFuture<?> f, final GridLogger log) { if (f != null) f.listenAsync(new CI1<GridFuture<?>>() { @Override public void apply(GridFuture<?> f) { try { f.get(); } catch (GridException e) { U.error(log, "Failed to execute future: " + f, e); } } }); }
/** {@inheritDoc} */ @Override public GridRestResponse call() throws Exception { final GridCacheProjection<Object, Object> cache = cache(g, cacheName).forSubjectId(clientId); // Need to apply both operation and response transformation remotely // as cache could be inaccessible on local node and // exception processing should be consistent with local execution. return op.apply(cache, ((GridKernal)g).context()).chain(resultWrapper(cache, key)).get(); } }
@Override public boolean apply(GridFuture<?> f) { return f.isDone(); } };
/** * Adds a future to this compound future. * * @param fut Future to add. */ public void add(GridFuture<T> fut) { assert fut != null; pending.add(fut); futs.add(fut); fut.listenAsync(new Listener()); if (isCancelled()) try { fut.cancel(); } catch (GridException e) { onDone(e); } }
/** {@inheritDoc} */ @Override protected void cancelQuery() throws GridException { if (fut != null) fut.cancel(); }
/** {@inheritDoc} */ @Override public boolean isCancelled() { return embedded.isCancelled(); }
/** * Add local cache future. * * @param idx Block index. * @param fut Future. */ private void addLocalCacheFuture(long idx, GridFuture<byte[]> fut) { assert Thread.holdsLock(this); if (!locCache.containsKey(idx)) { if (locCache.size() == maxLocCacheSize) { final GridFuture<byte[]> evictFut = locCache.remove(locCache.keySet().iterator().next()); if (!evictFut.isDone()) { pendingFuts.add(evictFut); evictFut.listenAsync(new GridInClosure<GridFuture<byte[]>>() { @Override public void apply(GridFuture<byte[]> t) { pendingFuts.remove(evictFut); pendingFutsLock.lock(); try { pendingFutsCond.signalAll(); } finally { pendingFutsLock.unlock(); } } }); } } locCache.put(idx, fut); } }
if (prep == null || prep.isDone()) { try { if (prep != null) prep.get(); prep.listenAsync(new CI1<GridFuture<GridCacheTxEx<K, V>>>() { @Override public void apply(GridFuture<GridCacheTxEx<K, V>> f) { try {
/** * @param ctx Context. * @param embedded Embedded future. * @param c Closure to execute upon completion of embedded future. */ public GridEmbeddedFuture(GridKernalContext ctx, GridFuture<B> embedded, final GridBiClosure<B, Exception, A> c) { super(ctx); assert embedded != null; assert c != null; this.embedded = embedded; embedded.listenAsync(new AL1() { @SuppressWarnings({"ErrorNotRethrown", "CatchGenericClass"}) @Override public void applyx(GridFuture<B> embedded) { try { onDone(c.apply(embedded.get(), null)); } catch (GridException| RuntimeException e) { onDone(c.apply(null, e)); } catch (Error e) { onDone(e); throw e; } } }); }
/** {@inheritDoc} */ @Override public GridRestResponse call() throws Exception { GridCacheProjection<?, ?> prj = cache(g, cacheName).forSubjectId(clientId).flagsOn(flags); if (portable) prj = prj.keepPortable(); // Need to apply both operation and response transformation remotely // as cache could be inaccessible on local node and // exception processing should be consistent with local execution. return op.apply((GridCacheProjection<Object, Object>)prj, ((GridKernal)g).context()). chain(resultWrapper((GridCacheProjection<Object, Object>)prj, key)).get(); } }
/** {@inheritDoc} */ @Override public boolean isDone() { return fut.isDone(); }
/** {@inheritDoc} */ @SuppressWarnings({"MethodWithTooExceptionsDeclared"}) @Override public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException { A.ensure(timeout >= 0, "timeout >= 0"); A.notNull(unit, "unit != null"); try { T res = fut.get(unit.toMillis(timeout)); if (fut.isCancelled()) throw new CancellationException("Task was cancelled: " + fut); return res; } catch (GridFutureTimeoutException e) { TimeoutException e2 = new TimeoutException(); e2.initCause(e); throw e2; } catch (GridComputeTaskTimeoutException e) { throw new ExecutionException("Task execution timed out during waiting for task result: " + fut, e); } catch (GridException e) { // Task cancellation may cause throwing exception. if (fut.isCancelled()) { RuntimeException ex = new CancellationException("Task was cancelled: " + fut); ex.initCause(e); throw ex; } throw new ExecutionException("Failed to get task result.", e); } } }
/** {@inheritDoc} */ @Override public boolean cancel() throws GridException { return embedded.cancel(); }
/** {@inheritDoc} */ @Override public boolean isCancelled() { return fut.isCancelled(); }