javax.cache.processor.EntryProcessor Java Examples
The following examples show how to use
javax.cache.processor.EntryProcessor.
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: CacheWriterTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void shouldWriteThroughUsingInvoke_remove_createEntry() { assertEquals(0, cacheWriter.getWriteCount()); assertEquals(0, cacheWriter.getDeleteCount()); cache.put(1, "Gudday World"); EntryProcessor processors[] = new EntryProcessor[] { new RemoveEntryProcessor<Integer, String, Object>(true), new AssertNotPresentEntryProcessor(null), new SetEntryProcessor<Integer, String>("After remove") }; cache.invoke(1, new CombineEntryProcessor<Integer, String>(processors)); assertEquals(2, cacheWriter.getWriteCount()); assertEquals(0, cacheWriter.getDeleteCount()); assertTrue(cacheWriter.hasWritten(1)); }
Example #2
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 #3
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 #4
Source File: IgniteTxConfigCacheSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Success if implicit tx fails. * * @param cache Cache instance. * @throws Exception If failed. */ protected void checkImplicitTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception { cache.invoke("key", new EntryProcessor<Object, Object, Object>() { @Override public Object process(final MutableEntry<Object, Object> entry, final Object... args) throws EntryProcessorException { try { sleepForTxFailure(); } catch (InterruptedException e) { throw new EntryProcessorException(e); } return null; } }); cache.clear(); }
Example #5
Source File: CacheWriterTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void shouldWriteThroughUsingInvoke_setValue_CreateEntryGetValue() { assertEquals(0, cacheWriter.getWriteCount()); assertEquals(0, cacheWriter.getDeleteCount()); EntryProcessor processors[] = new EntryProcessor[] { new AssertNotPresentEntryProcessor(null), new SetEntryProcessor<Integer, String>("Gudday World") }; Object[] result = cache.invoke(1, new CombineEntryProcessor<Integer, String>(processors)); assertEquals(result[1], "Gudday World"); assertEquals(result[1], cache.get(1)); assertEquals(cache.get(1), cacheWriter.get(1)); assertEquals(1, cacheWriter.getWriteCount()); assertEquals(0, cacheWriter.getDeleteCount()); assertTrue(cacheWriter.hasWritten(1)); assertEquals("Gudday World", cacheWriter.get(1)); }
Example #6
Source File: GridCacheOffheapManager.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public MvccUpdateResult mvccUpdate( GridCacheContext cctx, KeyCacheObject key, CacheObject val, GridCacheVersion ver, long expireTime, MvccSnapshot mvccVer, CacheEntryPredicate filter, EntryProcessor entryProc, Object[] invokeArgs, boolean primary, boolean needHistory, boolean noCreate, boolean needOldVal, boolean retVal, boolean keepBinary) throws IgniteCheckedException { CacheDataStore delegate = init0(false); return delegate.mvccUpdate(cctx, key, val, ver, expireTime, mvccVer, filter, entryProc, invokeArgs, primary, needHistory, noCreate, needOldVal, retVal, keepBinary); }
Example #7
Source File: CacheInvokeTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void existingException() { final Integer key = 123; final String oldValue = "abc"; final String newValue = "def"; cache.put(key, oldValue); EntryProcessor processors[] = new EntryProcessor[]{ new ReplaceEntryProcessor<Integer, String, Integer>(oldValue, newValue), new ThrowExceptionEntryProcessor<Integer, String, String>(IllegalAccessError.class) }; try { cache.invoke(key, new CombineEntryProcessor<Integer, String>(processors)); fail(); } catch (CacheException e) { Throwable rootCause = getRootCause(e); assertTrue("expected IllegalAccessError; observed " + rootCause, rootCause instanceof IllegalAccessError); } assertEquals(oldValue, cache.get(key)); }
Example #8
Source File: IgnteCacheClientWriteBehindStoreNonCoalescingTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Update random key in async mode. * * @param cache Cache to use. * @return IgniteFuture. */ private IgniteFuture<?> updateKey(IgniteCache<Integer, Integer> cache) { IgniteCache asyncCache = cache.withAsync(); // Using EntryProcessor.invokeAll to increment every value in place. asyncCache.invoke(rnd.nextInt(100), new EntryProcessor<Integer, Integer, Object>() { @Override public Object process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException { entry.setValue(entry.getValue() + 1); return null; } }); return asyncCache.future(); }
Example #9
Source File: CacheInvokeTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void noValueException() { final Integer key = 123; final String setValue = "abc"; EntryProcessor processors[] = new EntryProcessor[]{ new AssertNotPresentEntryProcessor(null), new SetEntryProcessor<Integer, String>(setValue), new ThrowExceptionEntryProcessor<Integer, String, String>(IllegalAccessError.class) }; try { cache.invoke(key, new CombineEntryProcessor(processors)); fail(); } catch (CacheException e) { Throwable rootCause = getRootCause(e); assertTrue("expected IllegalAccessError; observed " + rootCause, rootCause instanceof IllegalAccessError); } assertFalse(cache.containsKey(key)); }
Example #10
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 #11
Source File: GridDhtAtomicSingleUpdateRequest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param key Key to add. * @param val Value, {@code null} if should be removed. * @param entryProcessor Entry processor. * @param ttl TTL. * @param expireTime Expire time. */ @Override public void addNearWriteValue(KeyCacheObject key, @Nullable CacheObject val, EntryProcessor<Object, Object, Object> entryProcessor, long ttl, long expireTime) { assert entryProcessor == null; assert ttl <= 0 : ttl; assert key.partition() >= 0 : key; if (this.key != null) { setFlag(true, DHT_ATOMIC_OBSOLETE_NEAR_KEY_FLAG_MASK); return; } near(true); this.key = key; this.val = val; }
Example #12
Source File: CacheProxy.java From caffeine 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) { Map<K, EntryProcessorResult<T>> results = new HashMap<>(keys.size()); for (K key : keys) { try { T result = invoke(key, entryProcessor, arguments); if (result != null) { results.put(key, () -> result); } } catch (EntryProcessorException e) { results.put(key, () -> { throw e; }); } } return results; }
Example #13
Source File: IgfsMetaManager.java From ignite with Apache License 2.0 | 6 votes |
/** * Transfer entry from one directory to another. * * @param entry Entry to be transferred. * @param srcId Source ID. * @param srcName Source name. * @param destId Destination ID. * @param destName Destination name. * @throws IgniteCheckedException If failed. */ private void transferEntry(IgfsListingEntry entry, IgniteUuid srcId, String srcName, IgniteUuid destId, String destName) throws IgniteCheckedException { validTxState(true); if (F.eq(srcId, destId)) id2InfoPrj.invoke(srcId, new IgfsMetaDirectoryListingRenameProcessor(srcName, destName)); else { Map<IgniteUuid, EntryProcessor<IgniteUuid, IgfsEntryInfo, Void>> procMap = new HashMap<>(); procMap.put(srcId, new IgfsMetaDirectoryListingRemoveProcessor(srcName, entry.fileId())); procMap.put(destId, new IgfsMetaDirectoryListingAddProcessor(destName, entry)); id2InfoPrj.invokeAll(procMap); } }
Example #14
Source File: CacheWriterTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void shouldWriteThroughUsingInvoke_setValue_CreateEntryThenRemove() { assertEquals(0, cacheWriter.getWriteCount()); assertEquals(0, cacheWriter.getDeleteCount()); EntryProcessor processors[] = new EntryProcessor[] { new AssertNotPresentEntryProcessor(null), new SetEntryProcessor<Integer, String>("Gudday World"), new RemoveEntryProcessor<Integer, String, Object>(true) }; cache.invoke(1, new CombineEntryProcessor<Integer, String>(processors)); assertEquals(0, cacheWriter.getWriteCount()); assertEquals(0, cacheWriter.getDeleteCount()); assertTrue(!cacheWriter.hasWritten(1)); assertTrue(cache.get(1) == null); assertFalse(cache.containsKey(1)); }
Example #15
Source File: IgniteCacheInvokeClusterReadOnlyModeSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ @Test public void testInvokeAllEntryProcessorsDenied() { Map<Integer, EntryProcessor<Integer, Integer, Object>> map = new HashMap<>(); kvMap.keySet().forEach(k -> map.put(k, ENTRY_PROCESSOR)); performActionReadOnlyExceptionExpected(cache -> cache.invokeAll(map)); }
Example #16
Source File: GatewayProtectedCacheProxy.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 TransactionException { CacheOperationGate opGate = onEnter(); try { return delegate.invokeAll(map, args); } finally { onLeave(opGate); } }
Example #17
Source File: GatewayProtectedCacheProxy.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) throws TransactionException { CacheOperationGate opGate = onEnter(); try { return delegate.invokeAllAsync(map, args); } finally { onLeave(opGate); } }
Example #18
Source File: HibernateCacheProxy.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Nullable @Override public EntryProcessorResult invoke( @Nullable AffinityTopologyVersion topVer, Object key, EntryProcessor entryProcessor, Object... args ) throws IgniteCheckedException { return delegate.get().invoke(topVer, key, entryProcessor, args); }
Example #19
Source File: CacheInvokeTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void removeMissing() { final Integer key = 123; final String value = "aba"; final Integer ret = 456; EntryProcessor processors[] = new EntryProcessor[]{ new AssertNotPresentEntryProcessor<Integer, String, Integer>(ret), new SetEntryProcessor<Integer, String>(value), new RemoveEntryProcessor<Integer, String, String>(true) }; Object[] result = cache.invoke(key, new CombineEntryProcessor<Integer, String>(processors)); assertEquals(ret, result[0]); assertFalse(cache.containsKey(key)); }
Example #20
Source File: GatewayProtectedCacheProxy.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 TransactionException { CacheOperationGate opGate = onEnter(); try { return delegate.invokeAll(keys, entryProcessor, args); } finally { onLeave(opGate); } }
Example #21
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, EntryProcessor<K, V, T> entryProcessor, Object... args) throws TransactionException { CacheOperationGate opGate = onEnter(); try { return delegate.invokeAllAsync(keys, entryProcessor, args); } finally { onLeave(opGate); } }
Example #22
Source File: GridCacheTestEntryEx.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public GridCacheUpdateTxResult mvccSet(@Nullable IgniteInternalTx tx, UUID affNodeId, CacheObject val, EntryProcessor entryProc, Object[] invokeArgs, long ttl0, AffinityTopologyVersion topVer, MvccSnapshot mvccVer, GridCacheOperation op, boolean needHistory, boolean noCreate, boolean needOldVal, CacheEntryPredicate filter, boolean retVal, boolean keepBinary) throws IgniteCheckedException, GridCacheEntryRemovedException { rawPut(val, ttl); return new GridCacheUpdateTxResult(true); }
Example #23
Source File: GridLocalAtomicCache.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync( Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) { 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; IgniteInternalFuture fut = updateAllAsync0(null, map, args, true, false, null); if (statsEnabled) fut.listen(new InvokeAllTimeStatClosure(metrics0(), start)); return fut; }
Example #24
Source File: IgniteCacheOffheapManagerImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public MvccUpdateResult mvccUpdate( GridCacheMapEntry entry, CacheObject val, GridCacheVersion ver, long expireTime, MvccSnapshot mvccSnapshot, boolean primary, boolean needHistory, boolean noCreate, boolean needOldVal, @Nullable CacheEntryPredicate filter, boolean retVal, boolean keepBinary, EntryProcessor entryProc, Object[] invokeArgs) throws IgniteCheckedException { if (entry.detached() || entry.isNear()) return null; assert entry.lockedByCurrentThread(); return dataStore(entry.localPartition()).mvccUpdate(entry.context(), entry.key(), val, ver, expireTime, mvccSnapshot, filter, entryProc, invokeArgs, primary, needHistory, noCreate, needOldVal, retVal, keepBinary); }
Example #25
Source File: IgniteCacheProcessProxy.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> processor, Object... args) { return compute.call(new InvokeAllTask<>(cacheName, isAsync, keys, processor, args)); }
Example #26
Source File: GridCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync( Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.invokeAllAsync(map, args); } finally { gate.leave(prev); } }
Example #27
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 #28
Source File: GridCacheProxyImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public <T> IgniteInternalFuture<EntryProcessorResult<T>> invokeAsync(K key, EntryProcessor<K, V, T> entryProcessor, Object... args) { CacheOperationContext prev = gate.enter(opCtx); try { return delegate.invokeAsync(key, entryProcessor, args); } finally { gate.leave(prev); } }
Example #29
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 #30
Source File: ClassLoaderAwareCache.java From commons-jcs 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) { final Thread thread = Thread.currentThread(); final ClassLoader loader = before(thread); try { return delegate.invokeAll(keys, entryProcessor, arguments); } finally { thread.setContextClassLoader(loader); } }