javax.cache.processor.EntryProcessorResult Java Examples
The following examples show how to use
javax.cache.processor.EntryProcessorResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... args ) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) { setFuture(delegate.invokeAllAsync(keys, entryProcessor, args)); return null; } else return delegate.invokeAll(keys, entryProcessor, args); } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #2
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testAtomicOrImplicitTxInvokeAll() throws Exception { executeWithAllCaches(new TestClosure() { @Override public void run() throws Exception { final Map<Integer, EntryProcessorResult<Object>> r = cache.invokeAll(F.asMap( key1, new TestEntryProcessor(okValue), key2, new TestEntryProcessor(badValue))); assertNotNull(r); GridTestUtils.assertThrowsAnyCause(log, new Callable<Object>() { @Override public Object call() throws Exception { return r.get(key2).get(); } }, IgniteCheckedException.class, ERR_MSG); assertEquals(1, cache.size()); } }); }
Example #3
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testTxInvokeAll() throws Exception { executeWithAllTxCaches(new TestClosure() { @Override public void run() throws Exception { try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) { final Map<Integer, EntryProcessorResult<Object>> r = cache.invokeAll(F.asMap( key1, new TestEntryProcessor(okValue), key2, new TestEntryProcessor(badValue))); assertNotNull(r); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return r.get(key2).get(); } }, EntryProcessorException.class, ERR_MSG); tx.rollback(); } assertEquals(0, cache.size()); } }); }
Example #4
Source File: CacheVersionedEntryAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testInvokeAll() throws Exception { Cache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME); Set<Integer> keys = new HashSet<>(); for (int i = 0; i < ENTRIES_NUM; i++) keys.add(i); Map<Integer, EntryProcessorResult<Object>> res = cache.invokeAll(keys, new EntryProcessor<Integer, String, Object>() { @Override public Object process(MutableEntry<Integer, String> entry, Object... args) { CacheEntry<Integer, String> verEntry = entry.unwrap(CacheEntry.class); checkVersionedEntry(verEntry); return verEntry.version(); } }); assertEquals(ENTRIES_NUM, res.size()); }
Example #5
Source File: IgniteCacheInvokeAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testInternalInvokeNullable() throws Exception { IgniteInternalCache<Integer, Integer> cache = grid(0).cachex(DEFAULT_CACHE_NAME); EntryProcessor<Integer, Integer, Void> processor = new NullableProcessor(); for (final Integer key : keys()) { log.info("Test invoke with a nullable result [key=" + key + ']'); EntryProcessorResult<Void> result = cache.invoke(key, processor); EntryProcessorResult<Void> resultAsync = cache.invokeAsync(key, processor).get(); assertNotNull(result); assertNotNull(resultAsync); assertNull(result.get()); assertNull(resultAsync.get()); } }
Example #6
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll( Set<? extends K> keys, CacheEntryProcessor<K, V, T> entryProcessor, Object... args ) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) { setFuture(delegate.invokeAllAsync(keys, entryProcessor, args)); return null; } else return delegate.invokeAll(keys, entryProcessor, args); } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #7
Source File: WithKeepBinaryCacheFullApiTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @param resMap Result map. * @param expRes Expected result. * @param cacheVal Expected cache value for key. * @param deserializeRes Deseriallize result flag. */ private void checkInvokeAllResult(IgniteCache cache, Map<Object, EntryProcessorResult<Object>> resMap, Object expRes, Object cacheVal, boolean deserializeRes) { for (Map.Entry<Object, EntryProcessorResult<Object>> e : resMap.entrySet()) { info("Key: " + e.getKey()); assertTrue("Wrong key type, binary object expected: " + e.getKey(), e.getKey() instanceof BinaryObject); Object res = e.getValue().get(); // TODO IGNITE-2953: delete the following if when the issue wiil be fixed. if (deserializeRes) assertEquals(expRes, deserializeRes ? deserializeBinary(res) : res); if (cache.get(e.getKey()) == null) cache.get(e.getKey()); assertEquals(cacheVal, deserializeBinary(cache.get(e.getKey()))); } }
Example #8
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** * @param topVer Locked topology version. * @param key Key. * @param entryProcessor Entry processor. * @param args Arguments. * @return Invoke result. */ public <T> T invoke(@Nullable AffinityTopologyVersion topVer, K key, EntryProcessor<K, V, T> entryProcessor, Object... args ) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) throw new UnsupportedOperationException(); else { EntryProcessorResult<T> res = delegate.invoke(topVer, key, entryProcessor, args); return res != null ? res.get() : null; } } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #9
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** * Invoke async operation internal implementation. * * @param key Key. * @param entryProcessor Processor. * @param args Arguments. * @return Internal future. */ private <T> IgniteInternalFuture<T> invokeAsync0(K key, EntryProcessor<K, V, T> entryProcessor, Object[] args) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); IgniteInternalFuture<EntryProcessorResult<T>> fut = delegate.invokeAsync(key, entryProcessor, args); return fut.chain(new CX1<IgniteInternalFuture<EntryProcessorResult<T>>, T>() { @Override public T applyx(IgniteInternalFuture<EntryProcessorResult<T>> fut1) throws IgniteCheckedException { try { return fut1.get().get(); } catch (RuntimeException e) { throw new GridClosureException(e); } } }); }
Example #10
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... args) throws EntryProcessorException { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) { setFuture(invokeAsync0(key, entryProcessor, args)); return null; } else { EntryProcessorResult<T> res = delegate.invoke(key, entryProcessor, args); return res != null ? res.get() : null; } } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #11
Source File: PlatformDotNetEntityFrameworkCacheExtension.java From ignite with Apache License 2.0 | 6 votes |
/** * 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)); }
Example #12
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Checks that any invoke returns result. * * @throws Exception if something goes bad. */ @Ignore("https://issues.apache.org/jira/browse/IGNITE-4380") @Test public void testInvokeAllMultithreaded() throws Exception { final IgniteCache<String, Integer> cache = jcache(); final int threadCnt = 4; final int cnt = 5000; final Set<String> keys = Collections.singleton("myKey"); GridTestUtils.runMultiThreaded(new Runnable() { @Override public void run() { for (int i = 0; i < cnt; i++) { final Map<String, EntryProcessorResult<String>> res = cache.invokeAll(keys, INCR_PROCESSOR); assertEquals(1, res.size()); } } }, threadCnt, "testInvokeAllMultithreaded"); assertEquals(cnt * threadCnt, (int)cache.get("myKey")); }
Example #13
Source File: BlazingCacheCache.java From blazingcache with Apache License 2.0 | 6 votes |
@Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... arguments) { checkClosed(); if (keys == null || entryProcessor == null) { throw new NullPointerException(); } HashMap<K, EntryProcessorResult<T>> map = new HashMap<>(); for (K key : keys) { EntryProcessorResult<T> result; try { T t = invoke(key, entryProcessor, arguments); result = t == null ? null : new EntryProcessorResultImpl<>(t, null); } catch (Exception e) { result = new EntryProcessorResultImpl<>(null, new EntryProcessorException(e)); } if (result != null) { map.put(key, result); } } return map; }
Example #14
Source File: GridCacheContext.java From ignite with Apache License 2.0 | 6 votes |
/** * @param resMap Invoke results map. * @param keepBinary Keep binary flag. * @return Unwrapped results. */ public Map unwrapInvokeResult(@Nullable Map<Object, EntryProcessorResult> resMap, final boolean keepBinary) { return F.viewReadOnly(resMap, new C1<EntryProcessorResult, EntryProcessorResult>() { @Override public EntryProcessorResult apply(EntryProcessorResult res) { if (res instanceof CacheInvokeResult) { CacheInvokeResult invokeRes = (CacheInvokeResult)res; if (invokeRes.result() != null) res = CacheInvokeResult.fromResult(unwrapBinaryIfNeeded(invokeRes.result(), keepBinary, false)); } return res; } }); }
Example #15
Source File: WithKeepBinaryCacheFullApiTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @param resMap Result map. * @param expRes Expected result. * @param cacheVal Expected cache value for key. * @param deserializeRes Deseriallize result flag. */ private void checkInvokeAllAsyncResult(IgniteCache cache, Map<Object, EntryProcessorResult<Object>> resMap, Object expRes, Object cacheVal, boolean deserializeRes) { for (Map.Entry<Object, EntryProcessorResult<Object>> e : resMap.entrySet()) { info("Key: " + e.getKey()); assertTrue("Wrong key type, binary object expected: " + e.getKey(), e.getKey() instanceof BinaryObject); Object res = e.getValue().get(); // TODO IGNITE-2953: delete the following if when the issue wiil be fixed. if (deserializeRes) assertEquals(expRes, deserializeRes ? deserializeBinary(res) : res); assertEquals(cacheVal, deserializeBinary(cache.getAsync(e.getKey()).get())); } }
Example #16
Source File: GatewayProtectedCacheProxy.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys, CacheEntryProcessor<K, V, T> entryProcessor, Object... args) throws TransactionException { CacheOperationGate opGate = onEnter(); try { return delegate.invokeAllAsync(keys, entryProcessor, args); } finally { onLeave(opGate); } }
Example #17
Source File: GridCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll( Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) throws IgniteCheckedException { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.invokeAll(map, args); } finally { gate.leave(prev); } }
Example #18
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... args) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); return createFuture(delegate.invokeAllAsync(keys, entryProcessor, args)); }
Example #19
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys, CacheEntryProcessor<K, V, T> entryProcessor, Object... args) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); return createFuture(delegate.invokeAllAsync(keys, entryProcessor, args)); }
Example #20
Source File: JCacheAccessExpiryTest.java From caffeine with Apache License 2.0 | 5 votes |
@Test public void invokeAll_present() { Map<Integer, EntryProcessorResult<Integer>> result = jcache.invokeAll(keys, (entry, args) -> entry.getValue()); Map<Integer, Integer> unwrapped = result.entrySet().stream().collect( Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get())); assertThat(unwrapped, is(entries)); for (Integer key : keys) { Expirable<Integer> expirable = getExpirable(jcache, key); assertThat(expirable.getExpireTimeMS(), is(currentTimeMillis() + EXPIRY_DURATION)); } }
Example #21
Source File: GridCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync( Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... args) { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.invokeAllAsync(keys, entryProcessor, args); } finally { gate.leave(prev); } }
Example #22
Source File: TransformingCacheProxy.java From cache2k with Apache License 2.0 | 5 votes |
@Override public <T> Map<K, EntryProcessorResult<T>> invokeAll( Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... arguments) { EntryProcessor<K0, V0, T> processor = wrapEntryProcessor(entryProcessor); Map<K0, EntryProcessorResult<T>> map = cache.invokeAll(compactBoundedKeys(keys), processor, arguments); Map<K, EntryProcessorResult<T>> m2 = new HashMap<K, EntryProcessorResult<T>>(); for (Map.Entry<K0, EntryProcessorResult<T>> e : map.entrySet()) { m2.put(keyTransformer.expand(e.getKey()), e.getValue()); } return m2; }
Example #23
Source File: GridCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... args) throws IgniteCheckedException { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.invokeAll(keys, entryProcessor, args); } finally { gate.leave(prev); } }
Example #24
Source File: GridCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> EntryProcessorResult<T> invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... args) throws IgniteCheckedException { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.invoke(key, entryProcessor, args); } finally { gate.leave(prev); } }
Example #25
Source File: GridDhtAtomicCache.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys, final EntryProcessor<K, V, T> entryProcessor, Object... args) { if (map != null && keyCheck) validateCacheKeys(keys); warnIfUnordered(keys, BulkOperation.INVOKE); return invokeAll0(true, keys, entryProcessor, args); }
Example #26
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Tests invokeAll method for map of pairs (key, entryProcessor). * * @param cache Cache. * @param required Expected injected resources. * @param async Use async API. * @param oldAsync Use old async API. */ private void checkResourceInjectionOnInvokeAllMap(IgniteCache<String, Integer> cache, Collection<ResourceType> required, boolean async, boolean oldAsync) { Map<String, EntryProcessorResult<Integer>> results; Map<String, EntryProcessor<String, Integer, Integer>> map = new HashMap<>(); map.put(UUID.randomUUID().toString(), new ResourceInjectionEntryProcessor()); map.put(UUID.randomUUID().toString(), new ResourceInjectionEntryProcessor()); map.put(UUID.randomUUID().toString(), new ResourceInjectionEntryProcessor()); map.put(UUID.randomUUID().toString(), new ResourceInjectionEntryProcessor()); if (async) { if (oldAsync) { IgniteCache<String, Integer> acache = cache.withAsync(); acache.invokeAll(map); results = acache.<Map<String, EntryProcessorResult<Integer>>>future().get(); } else results = cache.invokeAllAsync(map).get(); } else results = cache.invokeAll(map); assertEquals(map.size(), results.size()); for (EntryProcessorResult<Integer> res : results.values()) { Collection<ResourceType> notInjected = ResourceInfoSet.valueOf(res.get()).notInjected(required); if (!notInjected.isEmpty()) fail("Can't inject resource(s): " + Arrays.toString(notInjected.toArray())); } }
Example #27
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Tests invokeAll method for set of keys. * * @param cache Cache. * @param required Expected injected resources. * @param async Use async API. * @param oldAsync Use old async API. */ private void checkResourceInjectionOnInvokeAll(IgniteCache<String, Integer> cache, Collection<ResourceType> required, boolean async, boolean oldAsync) { Set<String> keys = new HashSet<>(Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString())); Map<String, EntryProcessorResult<Integer>> results; if (async) { if (oldAsync) { IgniteCache<String, Integer> acache = cache.withAsync(); acache.invokeAll(keys, new ResourceInjectionEntryProcessor()); results = acache.<Map<String, EntryProcessorResult<Integer>>>future().get(); } else results = cache.invokeAllAsync(keys, new ResourceInjectionEntryProcessor()).get(); } else results = cache.invokeAll(keys, new ResourceInjectionEntryProcessor()); assertEquals(keys.size(), results.size()); for (EntryProcessorResult<Integer> res : results.values()) { Collection<ResourceType> notInjected1 = ResourceInfoSet.valueOf(res.get()).notInjected(required); if (!notInjected1.isEmpty()) fail("Can't inject resource(s): " + Arrays.toString(notInjected1.toArray())); } }
Example #28
Source File: GridLocalAtomicCache.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll( Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) throws IgniteCheckedException { A.notNull(map, "map"); if (keyCheck) validateCacheKeys(map.keySet()); warnIfUnordered(map, BulkOperation.INVOKE); final boolean statsEnabled = ctx.statisticsEnabled(); final long start = statsEnabled ? System.nanoTime() : 0L; CacheOperationContext opCtx = ctx.operationContextPerCall(); Map<K, EntryProcessorResult<T>> entryProcessorResult = (Map<K, EntryProcessorResult<T>>) updateAllInternal( TRANSFORM, map.keySet(), map.values(), args, expiryPerCall(), false, false, null, ctx.writeThrough(), ctx.readThrough(), opCtx != null && opCtx.isKeepBinary()); if (statsEnabled) metrics0().addInvokeTimeNanos(System.nanoTime() - start); return entryProcessorResult; }
Example #29
Source File: JCache.java From redisson with Apache License 2.0 | 5 votes |
@Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... arguments) { checkNotClosed(); if (entryProcessor == null) { throw new NullPointerException(); } Map<K, EntryProcessorResult<T>> results = new HashMap<K, EntryProcessorResult<T>>(); for (K key : keys) { try { final T result = invoke(key, entryProcessor, arguments); if (result != null) { results.put(key, new EntryProcessorResult<T>() { @Override public T get() throws EntryProcessorException { return result; } }); } } catch (final EntryProcessorException e) { results.put(key, new EntryProcessorResult<T>() { @Override public T get() throws EntryProcessorException { throw e; } }); } } return results; }
Example #30
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync( Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); return createFuture(delegate.invokeAllAsync(map, args)); }