use of javax.cache.event.CacheEntryEventFilter in project ignite by apache.
the class CacheContinuousQueryHandler method onEntryUpdate.
/**
* @param evt Continuous query event.
* @param notify Notify flag.
* @param loc Listener deployed on this node.
* @param recordIgniteEvt Record ignite event.
*/
private void onEntryUpdate(CacheContinuousQueryEvent<K, V> evt, boolean notify, boolean loc, boolean recordIgniteEvt) {
try {
GridCacheContext<K, V> cctx = cacheContext(ctx);
if (cctx == null)
return;
CacheContinuousQueryEntry entry = evt.entry();
IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> trans = getTransformer();
if (loc) {
if (!locOnly) {
Collection<CacheEntryEvent<? extends K, ? extends V>> evts = handleEvent(ctx, entry);
notifyLocalListener(evts, trans);
if (!internal && !skipPrimaryCheck)
sendBackupAcknowledge(ackBuf.onAcknowledged(entry), routineId, ctx);
} else if (!entry.isFiltered())
notifyLocalListener(F.asList(evt), trans);
} else {
if (!entry.isFiltered()) {
if (trans != null)
entry = transformToEntry(trans, evt);
prepareEntry(cctx, nodeId, entry);
}
Object entryOrList = handleEntry(cctx, entry);
if (entryOrList != null) {
if (log.isDebugEnabled())
log.debug("Send the following event to listener: " + entryOrList);
ctx.continuous().addNotification(nodeId, routineId, entryOrList, topic, sync, true);
}
}
} catch (ClusterTopologyCheckedException ex) {
if (log.isDebugEnabled())
log.debug("Failed to send event notification to node, node left cluster " + "[node=" + nodeId + ", err=" + ex + ']');
} catch (IgniteCheckedException ex) {
U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), "Failed to send event notification to node: " + nodeId, ex);
}
if (recordIgniteEvt && notify) {
CacheEntryEventFilter filter;
try {
filter = getEventFilter();
} catch (IgniteCheckedException e) {
if (log.isDebugEnabled()) {
log.debug("Failed to trigger a continuous query event. " + "[routineId=" + routineId + ", cacheName=" + cacheName + ", err=" + e + "]");
}
return;
}
// noinspection unchecked
ctx.event().record(new CacheQueryReadEvent<K, V>(ctx.discovery().localNode(), "Continuous query executed.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.CONTINUOUS.name(), cacheName, null, null, null, filter instanceof CacheEntryEventSerializableFilter ? (CacheEntryEventSerializableFilter) filter : null, null, nodeId, taskName(), evt.getKey(), evt.getValue(), evt.getOldValue(), null));
}
}
use of javax.cache.event.CacheEntryEventFilter in project ignite by apache.
the class CacheContinuousQueryHandler method sendQueryExecutedEvent.
/**
* Fires continuous query execution event.
* @see org.apache.ignite.events.EventType#EVT_CACHE_QUERY_EXECUTED
*/
private void sendQueryExecutedEvent() {
GridCacheContext<K, V> cctx = cacheContext(ctx);
CacheEntryEventFilter filter;
try {
filter = getEventFilter();
} catch (IgniteCheckedException e) {
if (log.isDebugEnabled()) {
log.debug("Failed to trigger the continuoue query executed event. " + "[routineId=" + routineId + ", cacheName=" + cacheName + ", err=" + e + "]");
}
return;
}
if (cctx != null && cctx.events().isRecordable(EVT_CACHE_QUERY_EXECUTED)) {
// noinspection unchecked
ctx.event().record(new CacheQueryExecutedEvent<K, V>(ctx.discovery().localNode(), "Continuous query executed.", EVT_CACHE_QUERY_EXECUTED, CacheQueryType.CONTINUOUS.name(), cacheName, null, null, null, filter instanceof CacheEntryEventSerializableFilter ? (CacheEntryEventSerializableFilter) filter : null, null, nodeId, taskName()));
}
}
use of javax.cache.event.CacheEntryEventFilter in project ignite by apache.
the class CacheContinuousQueryOperationP2PTest method testMultithreadedUpdatesNodeJoin.
/**
* @throws Exception If failed.
*/
@Test
public void testMultithreadedUpdatesNodeJoin() throws Exception {
Ignite client = startGrid("client");
CacheConfiguration<Object, Object> cacheCfg = cacheConfiguration(PARTITIONED, 0, ATOMIC);
IgniteCache<Object, Object> cache = client.createCache(cacheCfg);
int iterations = 50;
int keysNum = 100;
int threadsNum = Runtime.getRuntime().availableProcessors();
CountDownLatch updatesLatch = new CountDownLatch(iterations * keysNum * threadsNum / 2);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
final Class<Factory<CacheEntryEventFilter>> evtFilterFactoryCls = (Class<Factory<CacheEntryEventFilter>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
qry.setRemoteFilterFactory((Factory<? extends CacheEntryEventFilter<Object, Object>>) (Object) evtFilterFactoryCls.newInstance());
qry.setLocalListener((evts) -> {
for (CacheEntryEvent<?, ?> ignored : evts) updatesLatch.countDown();
});
cache.query(qry);
for (int t = 0; t < threadsNum; t++) {
int threadId = t;
GridTestUtils.runAsync(() -> {
for (int i = 0; i < iterations; i++) {
log.info("Iteration #" + (i + 1));
for (int k = 0; k < keysNum; k++) {
int key = keysNum * threadId + k;
cache.put(key, key);
}
}
}, "cache-writer-thread-" + threadId);
}
startGrid(NODES);
assertTrue("Failed to wait for all cache updates invocations. Latch: " + updatesLatch, updatesLatch.await(30, TimeUnit.SECONDS));
}
use of javax.cache.event.CacheEntryEventFilter in project ignite by apache.
the class CacheContinuousQueryRandomOperationsTest method testFilterAndFactoryProvided.
/**
* @throws Exception If failed.
*/
@Test
public void testFilterAndFactoryProvided() throws Exception {
final CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 1, ATOMIC, false);
grid(0).createCache(ccfg);
try {
final ContinuousQuery qry = new ContinuousQuery();
qry.setRemoteFilterFactory(new Factory<CacheEntryEventFilter>() {
@Override
public CacheEntryEventFilter create() {
return null;
}
});
qry.setRemoteFilter(new CacheEntryEventSerializableFilter() {
@Override
public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
return false;
}
});
qry.setLocalListener(new CacheEntryUpdatedListener() {
@Override
public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
// No-op.
}
});
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return grid(0).cache(ccfg.getName()).query(qry);
}
}, IgniteException.class, null);
} finally {
grid(0).destroyCache(ccfg.getName());
}
}
Aggregations