Java Code Examples for javax.cache.processor.EntryProcessor#process()
The following examples show how to use
javax.cache.processor.EntryProcessor#process() .
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: JCSCache.java From commons-jcs with Apache License 2.0 | 6 votes |
private <T> T doInvoke(final TempStateCacheView<K, V> view, final K key, final EntryProcessor<K, V, T> entryProcessor, final Object... arguments) { assertNotClosed(); assertNotNull(entryProcessor, "entryProcessor"); assertNotNull(key, "key"); try { if (config.isStatisticsEnabled()) { if (containsKey(key)) { statistics.increaseHits(1); } else { statistics.increaseMisses(1); } } return entryProcessor.process(new JCSMutableEntry<>(view, key), arguments); } catch (final Exception ex) { return throwEntryProcessorException(ex); } }
Example 2
Source File: TransformingCacheProxy.java From cache2k with Apache License 2.0 | 5 votes |
private <T> EntryProcessor<K0, V0, T> wrapEntryProcessor(final EntryProcessor<K, V, T> entryProcessor) { if (entryProcessor == null) { throw new NullPointerException("null processor"); } return new EntryProcessor<K0, V0, T>() { @Override public T process(final MutableEntry<K0, V0> entry, Object... arguments) throws EntryProcessorException { MutableEntry<K, V> e = wrapMutableEntry(entry); return entryProcessor.process(e, arguments); } }; }
Example 3
Source File: TCacheJSR107.java From triava with Apache License 2.0 | 4 votes |
/** * Process the given EntryProcessor and apply the change (delete or setValue) requested by that * EntryProcessor. Mutable changes have no direct impact, but are be applied after after the * EntryProcessor has returned, but before this method returns. * * @param entryProcessor The entry processor to execute * @param me The MutableEntry * @param args The client arguments * @return The result from the EntryProcessor */ private <T> T processEntryProcessor(EntryProcessor<K, V, T> entryProcessor, TCacheJSR107MutableEntry<K, V> me, Object... args) { T result = entryProcessor.process(me, args); K key; V value; switch (me.operation()) { case REMOVE: key = me.getKey(); remove(key); break; case SET: key = me.getKey(); value = me.getValue(); put(key, value); break; case LOAD: key = me.getKey(); value = me.getValue(); // Load must not write through, according to the TCK and RI // From the spec it is not clear why. See // -1- Get value (we are not loading it via CacheLoader, even though it is in the Specs. See https://github.com/jsr107/RI/issues/54 putNoWriteThrough(key, value); break; case REMOVE_WRITE_THROUGH: key = me.getKey(); remove(key, false); break; case GET: key = me.getKey(); AccessTimeObjectHolder<V> holder = tcache.peekHolder(key); if (holder != null) { // JSR107 1.0 (p.63) mandates that we call getExpiryForAccess() if we read it (except if was loaded) holder.updateMaxIdleTime(tcache.expiryPolicy.getExpiryForAccess()); } break; default: break; } return result; }
Example 4
Source File: IgniteCacheOffheapManagerImpl.java From ignite with Apache License 2.0 | 4 votes |
/** * * @param cctx Cache context. * @param key entry key. * @param ver Entry version. * @param entryProc Entry processor. * @param invokeArgs Entry processor invoke arguments. * @param updateRow Row for update. * @param oldRow Old row. * @param keepBinary Keep binary flag. * @return Entry processor operation. */ @SuppressWarnings("unchecked") private CacheInvokeEntry.Operation applyEntryProcessor(GridCacheContext cctx, KeyCacheObject key, GridCacheVersion ver, EntryProcessor entryProc, Object[] invokeArgs, MvccUpdateDataRow updateRow, CacheDataRow oldRow, boolean keepBinary) { Object procRes = null; Exception err = null; CacheObject oldVal = oldRow == null ? null : oldRow.value(); CacheInvokeEntry invokeEntry = new CacheInvokeEntry<>(key, oldVal, ver, keepBinary, new GridDhtDetachedCacheEntry(cctx, key)); try { procRes = entryProc.process(invokeEntry, invokeArgs); if (invokeEntry.modified() && invokeEntry.op() != CacheInvokeEntry.Operation.REMOVE) { Object val = invokeEntry.getValue(true); CacheObject val0 = cctx.toCacheObject(val); val0.prepareForCache(cctx.cacheObjectContext()); updateRow.value(val0); } } catch (Exception e) { log.error("Exception was thrown during entry processing.", e); err = e; } CacheInvokeResult invokeRes = err == null ? CacheInvokeResult.fromResult(procRes) : CacheInvokeResult.fromError(err); updateRow.invokeResult(invokeRes); return invokeEntry.op(); }
Example 5
Source File: IgniteTxLocalAdapter.java From ignite with Apache License 2.0 | 4 votes |
/** * @param txEntry Entry. * @param cacheVal Value. * @param ret Return value to update. * @param ver Entry version. */ protected final void addInvokeResult(IgniteTxEntry txEntry, CacheObject cacheVal, GridCacheReturn ret, GridCacheVersion ver) { GridCacheContext ctx = txEntry.context(); Object key0 = null; Object val0 = null; IgniteThread.onEntryProcessorEntered(true); try { Object res = null; for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) { CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry<>(txEntry.key(), key0, cacheVal, val0, ver, txEntry.keepBinary(), txEntry.cached()); EntryProcessor<Object, Object, ?> entryProcessor = t.get1(); res = entryProcessor.process(invokeEntry, t.get2()); val0 = invokeEntry.getValue(txEntry.keepBinary()); key0 = invokeEntry.key(); } if (val0 != null) // no validation for remove case ctx.validateKeyAndValue(txEntry.key(), ctx.toCacheObject(val0)); if (res != null) ret.addEntryProcessResult(ctx, txEntry.key(), key0, res, null, txEntry.keepBinary()); } catch (Exception e) { ret.addEntryProcessResult(ctx, txEntry.key(), key0, null, e, txEntry.keepBinary()); } finally { IgniteThread.onEntryProcessorLeft(); } }