use of javax.cache.event.CacheEntryUpdatedListener in project ignite by apache.
the class CacheDataStructuresManager method queue0.
/**
* @param name Queue name.
* @param cap Capacity.
* @param colloc Collocated flag.
* @param create Create flag.
* @return Queue header.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
@Nullable
public <T> GridCacheQueueProxy<T> queue0(final String name, final int cap, boolean colloc, final boolean create) throws IgniteCheckedException {
cctx.gate().enter();
try {
GridCacheQueueHeaderKey key = new GridCacheQueueHeaderKey(name);
GridCacheQueueHeader hdr;
if (create) {
hdr = new GridCacheQueueHeader(IgniteUuid.randomUuid(), cap, colloc, 0, 0, null);
GridCacheQueueHeader old = queueHdrView.withNoRetries().getAndPutIfAbsent(key, hdr);
if (old != null) {
if (old.capacity() != cap || old.collocated() != colloc)
throw new IgniteCheckedException("Failed to create queue, queue with the same name but " + "different configuration already exists [name=" + name + ']');
hdr = old;
}
} else
hdr = queueHdrView.get(key);
if (hdr == null)
return null;
if (queueQryGuard.compareAndSet(false, true)) {
queueQryId = cctx.continuousQueries().executeInternalQuery(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
if (!busyLock.enterBusy())
return;
try {
for (CacheEntryEvent<?, ?> e : evts) {
GridCacheQueueHeaderKey key = (GridCacheQueueHeaderKey) e.getKey();
GridCacheQueueHeader hdr = (GridCacheQueueHeader) e.getValue();
for (final GridCacheQueueProxy queue : queuesMap.values()) {
if (queue.name().equals(key.queueName())) {
if (hdr == null) {
GridCacheQueueHeader oldHdr = (GridCacheQueueHeader) e.getOldValue();
assert oldHdr != null;
if (oldHdr.id().equals(queue.delegate().id())) {
queue.delegate().onRemoved(false);
queuesMap.remove(queue.delegate().id());
}
} else
queue.delegate().onHeaderChanged(hdr);
}
}
}
} finally {
busyLock.leaveBusy();
}
}
}, new QueueHeaderPredicate(), cctx.isLocal() || (cctx.isReplicated() && cctx.affinityNode()), true, false);
}
GridCacheQueueProxy queue = queuesMap.get(hdr.id());
if (queue == null) {
queue = new GridCacheQueueProxy(cctx, cctx.atomic() ? new GridAtomicCacheQueueImpl<>(name, hdr, cctx) : new GridTransactionalCacheQueueImpl<>(name, hdr, cctx));
GridCacheQueueProxy old = queuesMap.putIfAbsent(hdr.id(), queue);
if (old != null)
queue = old;
}
return queue;
} finally {
cctx.gate().leave();
}
}
use of javax.cache.event.CacheEntryUpdatedListener in project ignite by apache.
the class CacheContinuousQueryRandomOperationsTest method testFilterAndFactoryProvided.
/**
* @throws Exception If failed.
*/
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());
}
}
use of javax.cache.event.CacheEntryUpdatedListener in project ignite by apache.
the class GridCacheContinuousQueryMultiNodesFilteringTest method startGrid.
/**
*/
private Ignite startGrid(final int idx, boolean isClientMode) throws Exception {
String igniteInstanceName = getTestIgniteInstanceName(idx);
IgniteConfiguration cfg = optimize(getConfiguration(igniteInstanceName)).setClientMode(isClientMode);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
cfg.setUserAttributes(Collections.singletonMap("idx", idx));
Ignite node = startGrid(igniteInstanceName, cfg);
IgnitePredicate<ClusterNode> nodeFilter = new NodeFilter(idx);
String partCacheName = "part" + idx;
IgniteCache partCache = node.createCache(defaultCacheConfiguration().setName("part" + idx).setCacheMode(PARTITIONED).setBackups(1).setNodeFilter(nodeFilter));
opCounts.put(partCacheName + "_ins", new AtomicInteger());
opCounts.put(partCacheName + "_upd", new AtomicInteger());
opCounts.put(partCacheName + "_rmv", new AtomicInteger());
partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.INSERT));
partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.UPDATE));
partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.REMOVE));
String replCacheName = "repl" + idx;
IgniteCache replCache = node.createCache(defaultCacheConfiguration().setName("repl" + idx).setCacheMode(REPLICATED).setNodeFilter(nodeFilter));
opCounts.put(replCacheName + "_ins", new AtomicInteger());
opCounts.put(replCacheName + "_upd", new AtomicInteger());
opCounts.put(replCacheName + "_rmv", new AtomicInteger());
replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.INSERT));
replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.UPDATE));
replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.REMOVE));
opCounts.put("qry" + idx + "_total", new AtomicInteger());
ContinuousQuery qry = new ContinuousQuery();
qry.setRemoteFilterFactory(new EntryEventFilterFactory(idx));
qry.setLocalListener(new CacheEntryUpdatedListener() {
/**
* {@inheritDoc}
*/
@Override
public void onUpdated(Iterable evts) {
opCounts.get("qry" + idx + "_total").incrementAndGet();
}
});
partCache.query(qry);
replCache.query(qry);
return node;
}
use of javax.cache.event.CacheEntryUpdatedListener in project ignite by apache.
the class IgniteCacheContinuousQueryNoUnsubscribeTest method checkNoUnsubscribe.
/**
* @param client Client node flag.
* @throws Exception If failed.
*/
private void checkNoUnsubscribe(boolean client) throws Exception {
cntr.set(0);
this.client = client;
try (Ignite ignite = startGrid(3)) {
ContinuousQuery qry = new ContinuousQuery();
qry.setLocalListener(new CacheEntryUpdatedListener() {
@Override
public void onUpdated(Iterable evts) {
// No-op.
}
});
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(CacheTestRemoteFilter.class));
qry.setAutoUnsubscribe(false);
ignite.cache(DEFAULT_CACHE_NAME).query(qry);
ignite.cache(DEFAULT_CACHE_NAME).put(1, 1);
assertEquals(1, cntr.get());
}
this.client = false;
try (Ignite newSrv = startGrid(3)) {
awaitPartitionMapExchange();
Integer key = primaryKey(newSrv.cache(DEFAULT_CACHE_NAME));
newSrv.cache(DEFAULT_CACHE_NAME).put(key, 1);
assertEquals(2, cntr.get());
for (int i = 0; i < 10; i++) ignite(0).cache(DEFAULT_CACHE_NAME).put(i, 1);
assertEquals(12, cntr.get());
}
for (int i = 10; i < 20; i++) ignite(0).cache(DEFAULT_CACHE_NAME).put(i, 1);
assertEquals(22, cntr.get());
}
use of javax.cache.event.CacheEntryUpdatedListener in project ignite by apache.
the class TcpDiscoveryMultiThreadedTest method _testCustomEventNodeRestart.
/**
* @throws Exception If failed.
*/
public void _testCustomEventNodeRestart() throws Exception {
clientFlagGlobal = false;
Ignite ignite = startGrid(0);
ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
final long stopTime = System.currentTimeMillis() + 60_000;
GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
@Override
public void apply(Integer idx) {
try {
while (System.currentTimeMillis() < stopTime) {
Ignite ignite = startGrid(idx + 1);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
int qryCnt = ThreadLocalRandom.current().nextInt(10) + 1;
for (int i = 0; i < qryCnt; i++) {
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
// No-op.
}
});
QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(qry);
cur.close();
}
GridTestUtils.invoke(ignite.configuration().getDiscoverySpi(), "simulateNodeFailure");
ignite.close();
}
} catch (Exception e) {
log.error("Unexpected error: " + e, e);
throw new IgniteException(e);
}
}
}, 5, "node-restart");
}
Aggregations