javax.cache.event.CacheEntryEvent Java Examples
The following examples show how to use
javax.cache.event.CacheEntryEvent.
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: CacheContinuousQueryHandler.java From ignite with Apache License 2.0 | 6 votes |
/** * Transform event data with {@link #getTransformer()} if exists. * * @param trans Transformer. * @param evt Event to transform. * @return Entry contains only transformed data if transformer exists. Unchanged event if transformer is not set. * @see #getTransformer() */ private CacheContinuousQueryEntry transformToEntry(IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> trans, CacheContinuousQueryEvent<? extends K, ? extends V> evt) { Object transVal = transform(trans, evt); return new CacheContinuousQueryEntry(evt.entry().cacheId(), evt.entry().eventType(), null, transVal == null ? null : cacheContext(ctx).toCacheObject(transVal), null, evt.entry().isKeepBinary(), evt.entry().partition(), evt.entry().updateCounter(), evt.entry().topologyVersion(), evt.entry().flags()); }
Example #2
Source File: IgniteCacheSourceTaskCQ.java From spring-boot-akka-event-sourcing-starter with Apache License 2.0 | 6 votes |
@Override public List<CacheEntryEvent> poll() { if (log.isDebugEnabled()) { log.debug("Cache source polling has been started !"); } ArrayList<CacheEntryEvent> evts = new ArrayList<>(evtBatchSize); if (stopped.get()) return evts; try { if (evtBuf.drainTo(evts, evtBatchSize) > 0) { if (log.isDebugEnabled()) { log.debug("Polled events {}", evts); } return evts; } } catch (IgniteException e) { log.error("Error when polling event queue!", e); } // for shutdown. return Collections.emptyList(); }
Example #3
Source File: CacheContinuousQueryHandler.java From ignite with Apache License 2.0 | 6 votes |
/** * @param trans Transformer. * @param evt Event. * @return Transformed value. */ private Object transform(IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> trans, CacheEntryEvent<? extends K, ? extends V> evt) { assert trans != null; Object transVal = null; try { transVal = trans.apply(evt); } catch (Exception e) { U.error(log, e); } return transVal; }
Example #4
Source File: IgniteCacheEntryListenerAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) { assert evt != null; assert evt.getSource() != null : evt; assert evt.getEventType() != null : evt; assert evt.getKey() != null : evt; Integer key; if (evt.getKey() instanceof ListenerTestKey) key = ((ListenerTestKey)evt.getKey()).key; else key = (Integer)evt.getKey(); return key % 2 == 0; }
Example #5
Source File: CacheListenerTestBase.java From triava with Apache License 2.0 | 6 votes |
@Override public void onExpired(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException { String msg = name + ":EXPIRED!"; int eventCount = countEvents(events, msg); expiredListenerFiredCount.addAndGet(eventCount); if (printAllEvents) { Iterator<CacheEntryEvent<? extends Integer, ? extends String>> iterator = events.iterator(); while (iterator.hasNext() ) { CacheEntryEvent<? extends Integer,? extends String> event = iterator.next(); System.out.println(msg + " Event: " + event.getValue()); } } }
Example #6
Source File: CacheContinuousQueryHandler.java From ignite with Apache License 2.0 | 6 votes |
/** * Notifies local listener. * * @param evts Events. * @param trans Transformer */ private void notifyLocalListener(Collection<CacheEntryEvent<? extends K, ? extends V>> evts, @Nullable IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> trans) { EventListener locTransLsnr = localTransformedEventListener(); assert locLsnr == null || locTransLsnr == null; if (F.isEmpty(evts)) return; if (locLsnr != null) locLsnr.onUpdated(evts); if (locTransLsnr != null) locTransLsnr.onUpdated(transform(trans, evts)); }
Example #7
Source File: CacheContinuousQueryRandomOperationsTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param evts Events. * @param evtType Event type. */ private void checkEvents(List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts, EventType evtType) { for (int key = 0; key < KEYS; key++) { QueryTestKey keyVal = new QueryTestKey(key); for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : evts) { if (e.getKey().equals(keyVal)) { checkSingleEvent(e, evtType, evtType != UPDATED ? new QueryTestValue(key) : null, evtType == REMOVED ? new QueryTestValue(key) : null); keyVal = null; break; } } assertNull("Event for key not found.", keyVal); } }
Example #8
Source File: JCacheEntryEvent.java From caffeine with Apache License 2.0 | 6 votes |
@Override public Iterator<CacheEntryEvent<? extends K, ? extends V>> iterator() { return new Iterator<CacheEntryEvent<? extends K, ? extends V>>() { boolean hasNext = true; @Override public boolean hasNext() { return hasNext; } @Override public CacheEntryEvent<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } hasNext = false; return JCacheEntryEvent.this; } }; }
Example #9
Source File: GridServiceProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void onUpdated(final Iterable<CacheEntryEvent<?, ?>> deps) { GridSpinBusyLock busyLock = GridServiceProcessor.this.busyLock; if (busyLock == null || !busyLock.enterBusy()) return; try { depExe.execute(new DepRunnable() { @Override public void run0() { onSystemCacheUpdated(deps); } }); } finally { busyLock.leaveBusy(); } }
Example #10
Source File: CacheListenerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException { for (CacheEntryEvent<? extends K, ? extends V> event : events) { assertEquals(UPDATED, event.getEventType()); throw new UnsupportedOperationException(); } }
Example #11
Source File: IgniteCacheEntryListenerAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void onCreated(Iterable<CacheEntryEvent<?, ?>> evts) { for (CacheEntryEvent<?, ?> evt : evts) { assertNotNull(evt); assertNotNull(evt.getSource()); assertNotNull(evt.getEventType()); assertNotNull(evt.getKey()); } }
Example #12
Source File: PlatformUtils.java From ignite with Apache License 2.0 | 5 votes |
/** * Apply continuous query events to listener. * * @param ctx Context. * @param lsnrPtr Listener pointer. * @param evts Events. * @throws javax.cache.event.CacheEntryListenerException In case of failure. */ public static void applyContinuousQueryEvents(PlatformContext ctx, long lsnrPtr, Iterable<CacheEntryEvent> evts) throws CacheEntryListenerException { assert lsnrPtr != 0; assert evts != null; try (PlatformMemory mem = ctx.memory().allocate()) { PlatformOutputStream out = mem.output(); BinaryRawWriterEx writer = ctx.writer(out); writer.writeLong(lsnrPtr); int cntPos = writer.reserveInt(); int cnt = 0; for (CacheEntryEvent evt : evts) { writeCacheEntryEvent(writer, evt); cnt++; } writer.writeInt(cntPos, cnt); out.synchronize(); ctx.gateway().continuousQueryListenerApply(mem.pointer()); } catch (Exception e) { throw toCacheEntryListenerException(e); } }
Example #13
Source File: IgniteCacheEntryListenerAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) { for (CacheEntryEvent<?, ?> evt : evts) { assertNotNull(evt); assertNotNull(evt.getSource()); assertNotNull(evt.getEventType()); assertNotNull(evt.getKey()); } }
Example #14
Source File: CacheListenerTestBase.java From triava with Apache License 2.0 | 5 votes |
@Override public void onRemoved(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException { String msg = "REMOVED"; int eventCount = countEvents(events, msg); removedListenerFiredCount.addAndGet(eventCount); }
Example #15
Source File: PolicyCacheUpdateListener.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * * @param event The event just updated. * @throws CacheEntryListenerException */ @Override public void entryUpdated(CacheEntryEvent<? extends IdentityCacheKey, ? extends PolicyStatus> event) throws CacheEntryListenerException { if(event!=null) { PolicyCache.updateLocalPolicyCacheMap(event.getKey(), event.getValue()); } }
Example #16
Source File: CacheContinuousQueryFailoverAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public synchronized void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) throws CacheEntryListenerException { try { for (CacheEntryEvent<?, ?> evt : evts) { Integer key = (Integer)evt.getKey(); Integer val = (Integer)evt.getValue(); assertNotNull(key); assertNotNull(val); Integer prevVal = vals.get(key); boolean dup = false; if (prevVal != null && prevVal.equals(val)) dup = true; if (!dup) { vals.put(key, val); List<CacheEntryEvent<?, ?>> keyEvts = this.evts.get(key); if (keyEvts == null) { keyEvts = Collections.synchronizedList(new ArrayList<CacheEntryEvent<?, ?>>()); this.evts.put(key, keyEvts); } keyEvts.add(evt); } } } catch (Throwable e) { err = true; log.error("Unexpected error", e); } }
Example #17
Source File: CacheSizeManager.java From component-runtime with Apache License 2.0 | 5 votes |
@Override public void onCreated(final Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvents) throws CacheEntryListenerException { cacheEntryEvents.forEach(it -> keys.add(it.getKey())); if (keys.size() > maxCacheSize) { final Iterator<K> iterator = keys.iterator(); synchronized (this) { while (keys.size() > maxCacheSize && iterator.hasNext()) { cache.remove(iterator.next()); iterator.remove(); } } } }
Example #18
Source File: CacheContinuousQueryOrderingEventTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param queue Event queue. * @throws Exception If failed. */ private void checkEvents(BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue, int expCnt) throws Exception { CacheEntryEvent<QueryTestKey, QueryTestValue> evt; int cnt = 0; Map<QueryTestKey, Integer> vals = new HashMap<>(); while ((evt = queue.poll(100, TimeUnit.MILLISECONDS)) != null) { assertNotNull(evt); assertNotNull(evt.getKey()); Integer preVal = vals.get(evt.getKey()); if (preVal == null) assertEquals(new QueryTestValue(0), evt.getValue()); else { if (!new QueryTestValue(preVal + 1).equals(evt.getValue())) assertEquals("Key event: " + evt.getKey(), new QueryTestValue(preVal + 1), evt.getValue()); } vals.put(evt.getKey(), evt.getValue().val1); ++cnt; } assertEquals(expCnt, cnt); }
Example #19
Source File: CacheListenerTestBase.java From triava with Apache License 2.0 | 5 votes |
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException { String msg = "UPDATED"; int eventCount = countEvents(events, msg); updatedListenerFiredCount.addAndGet(eventCount); }
Example #20
Source File: CacheListenersTest.java From blazingcache with Apache License 2.0 | 5 votes |
@Test public void testCreateListenerSynch() { CachingProvider cachingProvider = Caching.getCachingProvider(); Properties p = new Properties(); try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) { Map<String, String> created = new HashMap<>(); CacheEntryCreatedListener<String, String> listener = new CacheEntryCreatedListener<String, String>() { @Override public void onCreated(Iterable<CacheEntryEvent<? extends String, ? extends String>> events) throws CacheEntryListenerException { for (CacheEntryEvent<? extends String, ? extends String> e : events) { created.put(e.getKey(), e.getValue()); } } }; MutableConfiguration<String, String> config = new MutableConfiguration<String, String>() .setTypes(String.class, String.class) .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<>( new FactoryBuilder.SingletonFactory(listener), null, true, true) ); Cache<String, String> cache = cacheManager.createCache("simpleCache", config); String key = "key"; cache.put(key, "value"); assertEquals("value", created.get(key)); } }
Example #21
Source File: PlatformUtils.java From ignite with Apache License 2.0 | 5 votes |
/** * Write event to the writer. * * @param writer Writer. * @param evt Event. */ private static void writeCacheEntryEvent(BinaryRawWriterEx writer, CacheEntryEvent evt) { writer.writeObjectDetached(evt.getKey()); writer.writeObjectDetached(evt.getOldValue()); writer.writeObjectDetached(evt.getValue()); writeEventType(writer, evt.getEventType()); }
Example #22
Source File: GridCacheContinuousQueryAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception if failed. * @param bypassFilter Whether remote filter should be bypassed. * @param setLocLsnr Whether local listner should be setted. */ private void doQueryWithRemoteFilterFactory(boolean setLocLsnr, boolean bypassFilter) throws Exception { FILTERED.clear(); ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>(); Map<Integer, Integer> listened = new ConcurrentHashMap<>(); if (setLocLsnr) { qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() { @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) { evts.forEach(event -> listened.put(event.getKey(), event.getValue())); } }); } qry.setRemoteFilterFactory( FactoryBuilder.factoryOf((CacheEntryEventSerializableFilter<Integer, Integer>)evt -> { FILTERED.put(evt.getKey(), evt.getValue()); return bypassFilter; })); try (QueryCursor<Cache.Entry<Integer, Integer>> qryCursor = grid(0).cache(DEFAULT_CACHE_NAME).query(qry)) { checkLsnrAndFilterResults(setLocLsnr, bypassFilter, listened); } }
Example #23
Source File: GridServiceProcessor.java From ignite with Apache License 2.0 | 5 votes |
/** * @param evts Update events. */ private void onSystemCacheUpdated(final Iterable<CacheEntryEvent<?, ?>> evts) { for (CacheEntryEvent<?, ?> e : evts) { if (e.getKey() instanceof GridServiceDeploymentKey) processDeployment((CacheEntryEvent)e); else if (e.getKey() instanceof GridServiceAssignmentsKey) processAssignment((CacheEntryEvent)e); } }
Example #24
Source File: JCSListener.java From commons-jcs with Apache License 2.0 | 5 votes |
public void onExpired(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException { if (expire) { CacheEntryExpiredListener.class.cast(delegate).onExpired(filter(events)); } }
Example #25
Source File: DataStructuresProcessor.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException { if (evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED) return evt.getValue() instanceof GridCacheCountDownLatchValue || evt.getValue() instanceof GridCacheSemaphoreState || evt.getValue() instanceof GridCacheLockState; else { assert evt.getEventType() == EventType.REMOVED : evt; return true; } }
Example #26
Source File: IgniteClientReconnectContinuousProcessorTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) { int cnt = 0; for (CacheEntryEvent<?, ?> evt : evts) { ignite.log().info("Received cache event: " + evt); cnt++; } assertEquals(1, cnt); if (latch != null) latch.countDown(); }
Example #27
Source File: CacheContinuousQueryManager.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public boolean evaluate(CacheEntryEvent evt) { try { return (types & flag(evt.getEventType())) != 0 && (impl == null || impl.evaluate(evt)); } catch (Exception e) { U.error(log, "CacheEntryEventFilter failed: " + e); return true; } }
Example #28
Source File: CacheContinuousQueryAsyncFilterListenerTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) throws CacheEntryListenerException { clsr.apply(ignite, e); return true; }
Example #29
Source File: ICacheEntryListener.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@Override public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) { for (CacheEntryEvent<? extends K, ? extends V> event : events) { switch (event.getEventType()) { case CREATED: created.incrementAndGet(); break; default: unExpected.incrementAndGet(); break; } } }
Example #30
Source File: CacheContinuousQueryHandlerV3.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); boolean b = in.readBoolean(); if (b) { rmtTransFactoryDep = (CacheContinuousQueryDeployableObject)in.readObject(); if (p2pUnmarshalFut.isDone()) p2pUnmarshalFut = new GridFutureAdapter<>(); } else rmtTransFactory = (Factory<? extends IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?>>)in.readObject(); }