/** * @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 GridFuture<Boolean> removexAsync(K key, @Nullable GridCacheEntryEx<K, V> cached, GridPredicate<GridCacheEntry<K, V>>[] filter) { return removeAllAsync(Collections.singletonList(key), cached, implicit, false, filter) .chain((GridClosure<GridFuture<GridCacheReturn<V>>, Boolean>) RET2FLAG); }
/** {@inheritDoc} */ @Override public GridFuture<V> removeAsync(K key, @Nullable GridCacheEntryEx<K, V> cached, GridPredicate<GridCacheEntry<K, V>>[] filter) { return removeAllAsync(Collections.singletonList(key), cached, implicit, true, filter) .chain((GridClosure<GridFuture<GridCacheReturn<V>>, V>) RET2VAL); }
/** * @param f Target future. * @return Wrapped future that is aware of cloning behaviour. */ public GridFuture<Map<K, V>> wrapCloneMap(GridFuture<Map<K, V>> f) { if (!hasFlag(CLONE)) return f; return f.chain(new CX1<GridFuture<Map<K, V>>, Map<K, V>>() { @Override public Map<K, V> applyx(GridFuture<Map<K, V>> f) throws GridException { Map<K, V> map = new GridLeanMap<>(); for (Map.Entry<K, V> e : f.get().entrySet()) map.put(e.getKey(), cloneValue(e.getValue())); return map; } }); }
/** {@inheritDoc} */ @Override public GridFuture<Boolean> putxAsync(K key, V val, @Nullable GridCacheEntryEx<K, V> cached, long ttl, GridPredicate<GridCacheEntry<K, V>>[] filter) { return putAllAsync(F.t(key, val), false, cached, ttl, filter) .chain((GridClosure<GridFuture<GridCacheReturn<V>>, Boolean>)RET2FLAG); }
/** {@inheritDoc} */ @Override public GridFuture<Boolean> transformAsync(K key, GridClosure<V, V> transformer, @Nullable GridCacheEntryEx<K, V> cached, long ttl) { return putAllAsync0(null, Collections.singletonMap(key, transformer), null, false, cached, ttl, CU.<K, V>empty()).chain((GridClosure<GridFuture<GridCacheReturn<V>>, Boolean>) RET2FLAG); }
/** {@inheritDoc} */ @Override public GridFuture<V> putAsync(K key, V val, @Nullable GridCacheEntryEx<K, V> cached, long ttl, GridPredicate<GridCacheEntry<K, V>>[] filter) { return putAllAsync(F.t(key, val), true, cached, ttl, filter). chain((GridClosure<GridFuture<GridCacheReturn<V>>, V>) RET2VAL); }
/** {@inheritDoc} */ @Override public GridFuture<?> applyx(GridCacheProjection<Object, Object> c, GridKernalContext ctx) { return c.putAllAsync(map).chain(new FixedResult(true)); } }
/** {@inheritDoc} */ @Override public GridFuture<V> putAsync(K key, V val, GridPredicate<GridCacheEntry<K, V>>[] filter) { return putAllAsync0(F.t(key, val), null, null, true, null, -1, filter). chain((GridClosure<GridFuture<GridCacheReturn<V>>, V>) RET2VAL); }
/** {@inheritDoc} */ @Override public GridFuture<Boolean> putxAsync(K key, V val, GridPredicate<GridCacheEntry<K, V>>[] filter) { return putAllAsync0(F.t(key, val), null, null, false, null, -1, filter) .chain((GridClosure<GridFuture<GridCacheReturn<V>>, Boolean>) RET2FLAG); }
/** {@inheritDoc} */ @Override public GridFuture<Map<K, V>> getAllAsync(@Nullable final Collection<? extends K> keys) { GridFuture<Map<K, V>> fut = getAllAsync(keys, true, null); if (ctx.config().getInterceptor() != null) return fut.chain(new CX1<GridFuture<Map<K, V>>, Map<K, V>>() { @Override public Map<K, V> applyx(GridFuture<Map<K, V>> f) throws GridException { return interceptGet(keys, f.get()); } }); return fut; }
/** {@inheritDoc} */ @Override public <R> GridFuture<R> transformComputeAsync(K key, final GridClosure<V, GridBiTuple<V, R>> transformer) { GridFuture<GridCacheReturn<V>> fut = putAllAsync0(null, Collections.singletonMap(key, new GridCacheTransformComputeClosure<>(transformer)), null, true, null, -1, CU.<K, V>empty()); return fut.chain(new CX1<GridFuture<GridCacheReturn<V>>, R>() { @Override public R applyx(GridFuture<GridCacheReturn<V>> fut) throws GridException { GridCacheReturn<V> ret = fut.get(); return transformer.apply(ret.value()).get2(); } }); }
/** {@inheritDoc} */ @Override public GridFuture<V> getAsync(final K key) { GridFuture<V> fut = getAsync(key, true, null); if (ctx.config().getInterceptor() != null) return fut.chain(new CX1<GridFuture<V>, V>() { @Override public V applyx(GridFuture<V> f) throws GridException { return (V)ctx.config().getInterceptor().onGet(key, f.get()); } }); return fut; }
/** {@inheritDoc} */ @Override public GridFuture<V> getForcePrimaryAsync(final K key) { ctx.denyOnFlag(LOCAL); String taskName = ctx.kernalContext().job().currentTaskName(); return getAllAsync(Collections.singletonList(key), /*force primary*/true, /*skip tx*/false, null, null, taskName, true).chain(new CX1<GridFuture<Map<K, V>>, V>() { @Override public V applyx(GridFuture<Map<K, V>> e) throws GridException { return e.get().get(key); } }); }
/** {@inheritDoc} */ @Override public GridFuture<?> applyx(GridCacheProjection<Object, Object> c, GridKernalContext ctx) { return (F.isEmpty(keys) ? c.removeAllAsync() : c.removeAllAsync(keys)) .chain(new FixedResult(true)); } }
/** {@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(); } }
/** {@inheritDoc} */ @Override public GridFuture<Boolean> loadMissing(boolean async, final Collection<? extends K> keys, boolean deserializePortable, final GridBiInClosure<K, V> c) { return cctx.nearTx().txLoadAsync(this, keys, CU.<K, V>empty(), deserializePortable).chain(new C1<GridFuture<Map<K, V>>, Boolean>() { @Override public Boolean apply(GridFuture<Map<K, V>> f) { try { Map<K, V> map = f.get(); // Must loop through keys, not map entries, // as map entries may not have all the keys. for (K key : keys) c.apply(key, map.get(key)); return true; } catch (Exception e) { setRollbackOnly(); throw new GridClosureException(e); } } }); }
/** {@inheritDoc} */ @Override public <T> Future<T> submit(Runnable task, final T res) { A.notNull(task, "task != null"); checkShutdown(); GridFuture<T> fut = prj.compute().run(task).chain(new CX1<GridFuture<?>, T>() { @Override public T applyx(GridFuture<?> fut) throws GridException { fut.get(); return res; } }); return addFuture(fut); }
/** {@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 GridFuture<Boolean> loadMissing(boolean async, final Collection<? extends K> keys, boolean deserializePortable, final GridBiInClosure<K, V> c) { return cctx.colocated().loadAsync(keys, /*reload*/false, /*force primary*/false, topologyVersion(), CU.subjectId(this, cctx), resolveTaskName(), deserializePortable, null) .chain(new C1<GridFuture<Map<K, V>>, Boolean>() { @Override public Boolean apply(GridFuture<Map<K, V>> f) { try { Map<K, V> map = f.get(); // Must loop through keys, not map entries, // as map entries may not have all the keys. for (K key : keys) c.apply(key, map.get(key)); return true; } catch (Exception e) { setRollbackOnly(); throw new GridClosureException(e); } } }); }