Refine search
@SuppressWarnings("unchecked") @Override @Nullable public T process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException { Callable<T> valueLoader = (Callable<T>) arguments[0]; if (entry.exists()) { return (T) fromStoreValue(entry.getValue()); } else { T value; try { value = valueLoader.call(); } catch (Exception ex) { throw new EntryProcessorException("Value loader '" + valueLoader + "' failed " + "to compute value for key '" + entry.getKey() + "'", ex); } entry.setValue(toStoreValue(value)); return value; } } }
/** {@inheritDoc} */ @Override public Void process(MutableEntry<String, PlatformDotNetSessionData> entry, Object... args) throws EntryProcessorException { assert entry.exists(); PlatformDotNetSessionData data = entry.getValue(); assert data != null; // Unlock and update. data = update ? data.updateAndUnlock(lockNodeId, lockId, items, isDiff, staticData, timeout) : data.unlock(lockNodeId, lockId); // Apply. entry.setValue(data); return null; }
@Override public Object process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException { entry.setValue(1); try { Thread.sleep(100); } catch (InterruptedException e) { throw new EntryProcessorException(e); } return null; } });
/** {@inheritDoc} */ @Override public Integer process(MutableEntry<Integer, Integer> e, Object... arguments) throws EntryProcessorException { Ignite ignite = e.unwrap(Ignite.class); assertNotNull(ignite); if (e.exists()) { Integer val = e.getValue(); assertNotNull(val); e.setValue(val + 1); assertTrue(e.exists()); assertEquals(val + 1, (int) e.getValue()); return val; } else { e.setValue(1); return -1; } }
/** {@inheritDoc} */ @Override public Integer process(MutableEntry<Integer, Integer> e, Object... arguments) throws EntryProcessorException { assertTrue(e.exists()); if (expVal != null) assertEquals(expVal, e.getValue()); throw new EntryProcessorException("Test processor exception."); }
entry.setValue(reader.readObjectDetached()); entry.remove(); throw new EntryProcessorException("Failed to execute native cache entry processor.", ctx.createNativeException(nativeErr)); throw new EntryProcessorException("Failed to execute native cache entry processor: " + errMsg);
@Test public void invoke_absent() { assertThat(jcache.invoke(KEY_1, (entry, args) -> { entry.setValue(VALUE_2); return null; }), is(nullValue())); Expirable<Integer> expirable = getExpirable(jcache, KEY_1); assertThat(expirable.getExpireTimeMS(), is(currentTimeMillis() + EXPIRY_DURATION)); }
/** {@inheritDoc} */ @Override public Boolean process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException { if (!entry.exists()) return null; // Someone got ahead of us and removed this entry, let's skip it. Object entryVal = entry.getValue(); if (entryVal == null) return null; // Something happened to the cache while we were performing map-reduce. if (!F.eq(entryVal, val)) return false; entryModifier.apply(entry); return null; // To leave out only erroneous keys - nulls are skipped on results' processing. } }
@Test public void invoke_absent() { assertThat(jcache.get(KEY_1), is(VALUE_1)); advancePastExpiry(); assertThat(jcache.invoke(KEY_1, (entry, args) -> entry.getValue()), is(nullValue())); assertThat(getExpirable(jcache, KEY_1), is(nullValue())); }
@Override public Object process(MutableEntry<TestKey, TestValue> entry, Object... arguments) throws EntryProcessorException { TestValue val = entry.getValue(); // Check that we have correct value. assertEquals(entry.getKey().key(), val.val()); // Try changed entry. val.val(WRONG_VALUE); return -1; } });