use of javax.cache.processor.EntryProcessorException in project ignite by apache.
the class CacheContinuousQueryAsyncFilterListenerTest method testNonDeadLockInFilter.
/**
* @param ccfg Cache configuration.
* @param asyncFilter Async filter.
* @param asyncLsnr Async listener.
* @param jcacheApi Use JCache api for start update listener.
* @throws Exception If failed.
*/
private void testNonDeadLockInFilter(CacheConfiguration ccfg, final boolean asyncFilter, final boolean asyncLsnr, boolean jcacheApi) throws Exception {
ignite(0).createCache(ccfg);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
try {
for (int i = 0; i < ITERATION_CNT; i++) {
log.info("Start iteration: " + i);
int nodeIdx = i % NODES;
final String cacheName = ccfg.getName();
final IgniteCache cache = grid(nodeIdx).cache(cacheName);
final QueryTestKey key = NODES - 1 != nodeIdx ? affinityKey(cache) : new QueryTestKey(1);
final QueryTestValue val0 = new QueryTestValue(1);
final QueryTestValue newVal = new QueryTestValue(2);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch evtFromLsnrLatch = new CountDownLatch(1);
IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> fltrClsr = new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
@Override
public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
if (asyncFilter) {
assertFalse("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("sys-"));
assertTrue("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("callback-"));
}
IgniteCache<Object, Object> cache0 = ignite.cache(cacheName);
QueryTestValue val = e.getValue();
if (val == null)
return;
else if (val.equals(newVal)) {
evtFromLsnrLatch.countDown();
return;
} else if (!val.equals(val0))
return;
Transaction tx = null;
try {
if (cache0.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL)
tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
assertEquals(val, val0);
cache0.put(key, newVal);
if (tx != null)
tx.commit();
latch.countDown();
} catch (Exception exp) {
log.error("Failed: ", exp);
throw new IgniteException(exp);
} finally {
if (tx != null)
tx.close();
}
}
};
IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> lsnrClsr = new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
@Override
public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
if (asyncLsnr) {
assertFalse("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("sys-"));
assertTrue("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("callback-"));
}
QueryTestValue val = e.getValue();
if (val == null || !val.equals(new QueryTestValue(1)))
return;
assertEquals(val, val0);
latch.countDown();
}
};
QueryCursor qry = null;
MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg = null;
CacheInvokeListener locLsnr = asyncLsnr ? new CacheInvokeListenerAsync(lsnrClsr) : new CacheInvokeListener(lsnrClsr);
CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> rmtFltr = asyncFilter ? new CacheTestRemoteFilterAsync(fltrClsr) : new CacheTestRemoteFilter(fltrClsr);
if (jcacheApi) {
lsnrCfg = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(locLsnr), FactoryBuilder.factoryOf(rmtFltr), true, false);
cache.registerCacheEntryListener(lsnrCfg);
} else {
ContinuousQuery<QueryTestKey, QueryTestValue> conQry = new ContinuousQuery<>();
conQry.setLocalListener(locLsnr);
conQry.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFltr));
qry = cache.query(conQry);
}
try {
if (rnd.nextBoolean())
cache.put(key, val0);
else
cache.invoke(key, new CacheEntryProcessor() {
@Override
public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException {
entry.setValue(val0);
return null;
}
});
assert U.await(latch, 3, SECONDS) : "Failed to waiting event.";
assertEquals(cache.get(key), new QueryTestValue(2));
assertTrue("Failed to waiting event from filter.", U.await(latch, 3, SECONDS));
} finally {
if (qry != null)
qry.close();
if (lsnrCfg != null)
cache.deregisterCacheEntryListener(lsnrCfg);
}
log.info("Iteration finished: " + i);
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
use of javax.cache.processor.EntryProcessorException in project ignite by apache.
the class IgnteCacheClientWriteBehindStoreNonCoalescingTest method updateKeys.
/**
* Update specified keys in async mode.
*
* @param cache Cache to use.
* @param keys Keys to update.
* @return IgniteFuture.
*/
private IgniteFuture<?> updateKeys(IgniteCache<Integer, Integer> cache, Set<Integer> keys) {
IgniteCache asyncCache = cache.withAsync();
// Using EntryProcessor.invokeAll to increment every value in place.
asyncCache.invokeAll(keys, 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();
}
use of javax.cache.processor.EntryProcessorException in project redisson by redisson.
the class JCache method invoke.
@Override
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException {
checkNotClosed();
if (key == null) {
throw new NullPointerException();
}
if (entryProcessor == null) {
throw new NullPointerException();
}
long startTime = currentNanoTime();
if (containsKey(key)) {
cacheManager.getStatBean(this).addHits(1);
} else {
cacheManager.getStatBean(this).addMisses(1);
}
cacheManager.getStatBean(this).addGetTime(currentNanoTime() - startTime);
JMutableEntry<K, V> entry = new JMutableEntry<K, V>(this, key, null, config.isReadThrough());
try {
T result = entryProcessor.process(entry, arguments);
if (entry.getAction() == Action.CREATED || entry.getAction() == Action.UPDATED) {
put(key, entry.value());
}
if (entry.getAction() == Action.DELETED) {
remove(key);
}
return result;
} catch (EntryProcessorException e) {
throw e;
} catch (Exception e) {
throw new EntryProcessorException(e);
}
}
use of javax.cache.processor.EntryProcessorException in project ignite by apache.
the class DmlStatementsProcessor method splitErrors.
/**
* Process errors of entry processor - split the keys into duplicated/concurrently modified and those whose
* processing yielded an exception.
*
* @param res Result of {@link GridCacheAdapter#invokeAll)}
* @return pair [array of duplicated/concurrently modified keys, SQL exception for erroneous keys] (exception is
* null if all keys are duplicates/concurrently modified ones).
*/
private static PageProcessingErrorResult splitErrors(Map<Object, EntryProcessorResult<Boolean>> res) {
Set<Object> errKeys = new LinkedHashSet<>(res.keySet());
SQLException currSqlEx = null;
SQLException firstSqlEx = null;
int errors = 0;
// Let's form a chain of SQL exceptions
for (Map.Entry<Object, EntryProcessorResult<Boolean>> e : res.entrySet()) {
try {
e.getValue().get();
} catch (EntryProcessorException ex) {
SQLException next = createJdbcSqlException("Failed to process key '" + e.getKey() + '\'', IgniteQueryErrorCode.ENTRY_PROCESSING);
next.initCause(ex);
if (currSqlEx != null)
currSqlEx.setNextException(next);
else
firstSqlEx = next;
currSqlEx = next;
errKeys.remove(e.getKey());
errors++;
}
}
return new PageProcessingErrorResult(errKeys.toArray(), firstSqlEx, errors);
}
use of javax.cache.processor.EntryProcessorException in project ignite by apache.
the class PlatformCacheEntryProcessorImpl method process.
/** {@inheritDoc} */
@Override
public Object process(MutableEntry entry, Object... args) throws EntryProcessorException {
try {
Ignite ignite = (Ignite) entry.unwrap(Ignite.class);
PlatformProcessor interopProc;
try {
interopProc = PlatformUtils.platformProcessor(ignite);
} catch (IllegalStateException ex) {
throw new EntryProcessorException(ex);
}
interopProc.awaitStart();
return execute0(interopProc.context(), entry);
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
}
Aggregations