javax.cache.event.CacheEntryCreatedListener Java Examples
The following examples show how to use
javax.cache.event.CacheEntryCreatedListener.
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: ListenerEntry.java From triava with Apache License 2.0 | 6 votes |
/** * Returns whether this {@link ListenerEntry} is listening to the given eventType * @param eventType The event Type * @return true, if the listener is listening to the given eventType */ boolean isListeningFor(EventType eventType) { switch (eventType) { case CREATED: return listener instanceof CacheEntryCreatedListener; case EXPIRED: return listener instanceof CacheEntryExpiredListener; case REMOVED: return listener instanceof CacheEntryRemovedListener; case UPDATED: return listener instanceof CacheEntryUpdatedListener; } return false; }
Example #2
Source File: EventListenerAdaptors.java From ehcache3 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") static <K, V> List<EventListenerAdaptor<K, V>> ehListenersFor(CacheEntryListener<? super K, ? super V> listener, CacheEntryEventFilter<? super K, ? super V> filter, Cache<K, V> source, boolean requestsOld) { List<EventListenerAdaptor<K, V>> rv = new ArrayList<>(); if (listener instanceof CacheEntryUpdatedListener) { rv.add(new UpdatedAdaptor<>(source, (CacheEntryUpdatedListener<K, V>) listener, (CacheEntryEventFilter<K, V>) filter, requestsOld)); } if (listener instanceof CacheEntryCreatedListener) { rv.add(new CreatedAdaptor<>(source, (CacheEntryCreatedListener<K, V>) listener, (CacheEntryEventFilter<K, V>) filter, requestsOld)); } if (listener instanceof CacheEntryRemovedListener) { rv.add(new RemovedAdaptor<>(source, (CacheEntryRemovedListener<K, V>) listener, (CacheEntryEventFilter<K, V>) filter, requestsOld)); } if (listener instanceof CacheEntryExpiredListener) { rv.add(new ExpiredAdaptor<>(source, (CacheEntryExpiredListener<K, V>) listener, (CacheEntryEventFilter<K, V>) filter, requestsOld)); } return rv; }
Example #3
Source File: JCSListener.java From commons-jcs with Apache License 2.0 | 6 votes |
public JCSListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { oldValue = cacheEntryListenerConfiguration.isOldValueRequired(); synchronous = cacheEntryListenerConfiguration.isSynchronous(); final Factory<CacheEntryEventFilter<? super K, ? super V>> filterFactory = cacheEntryListenerConfiguration .getCacheEntryEventFilterFactory(); if (filterFactory == null) { filter = NoFilter.INSTANCE; } else { filter = filterFactory.create(); } delegate = cacheEntryListenerConfiguration.getCacheEntryListenerFactory().create(); remove = CacheEntryRemovedListener.class.isInstance(delegate); expire = CacheEntryExpiredListener.class.isInstance(delegate); update = CacheEntryUpdatedListener.class.isInstance(delegate); create = CacheEntryCreatedListener.class.isInstance(delegate); }
Example #4
Source File: ListenerEntry.java From triava with Apache License 2.0 | 5 votes |
private void sendEvents(TCacheEntryEventCollection<K, V> eventColl, CacheEntryListener<K, V> listener) { EventType eventType = eventColl.eventType(); // System.out.println("sendEvents to listener " + listener + ", eventType=" + eventColl.eventType()); switch (eventType) { case CREATED: if (listener instanceof CacheEntryCreatedListener) eventManager.created((CacheEntryCreatedListener<K, V>)listener, eventColl); break; case EXPIRED: if (listener instanceof CacheEntryExpiredListener) eventManager.expired((CacheEntryExpiredListener<K, V>)listener, eventColl); break; case UPDATED: if (listener instanceof CacheEntryUpdatedListener) eventManager.updated((CacheEntryUpdatedListener<K,V>)listener, eventColl); break; case REMOVED: if (listener instanceof CacheEntryRemovedListener) eventManager.removed((CacheEntryRemovedListener<K,V>)listener, eventColl); break; default: // By default do nothing. If new event types are added to the Spec, they will be ignored. } }
Example #5
Source File: CacheEntryListenerServer.java From cache2k with Apache License 2.0 | 5 votes |
private void runHandlers(EventType eventType, TestCacheEntryEvent event) { ArrayList events = new ArrayList(1); events.add(event); for (CacheEntryListener listener : listeners) { switch (eventType) { case CREATED : if (listener instanceof CacheEntryCreatedListener) { ((CacheEntryCreatedListener) listener).onCreated(events); } break; case UPDATED: if (listener instanceof CacheEntryUpdatedListener) { ((CacheEntryUpdatedListener) listener).onUpdated(events); } break; case REMOVED: if (listener instanceof CacheEntryRemovedListener) { ((CacheEntryRemovedListener) listener).onRemoved(events); } break; case EXPIRED: if (listener instanceof CacheEntryExpiredListener) { ((CacheEntryExpiredListener) listener).onExpired(events); } break; default: break; } } }
Example #6
Source File: CacheEntryListenerClient.java From cache2k with Apache License 2.0 | 5 votes |
@Override public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvents) throws CacheEntryListenerException { if (isDirectCallable()) { for (CacheEntryListener<K,V> l : listenerServer.getListeners()) { if (l instanceof CacheEntryCreatedListener) { ((CacheEntryCreatedListener<K,V>) l).onCreated(cacheEntryEvents); } } return; } for (CacheEntryEvent<? extends K, ? extends V> event : cacheEntryEvents) { getClient().invoke(new OnCacheEntryEventHandler<K, V>(event)); } }
Example #7
Source File: BlazingCacheCacheEntryListenerWrapper.java From blazingcache with Apache License 2.0 | 5 votes |
BlazingCacheCacheEntryListenerWrapper(boolean synchronous, boolean oldValueRequired, CacheEntryListener<K, V> listener, CacheEntryEventFilter<K, V> filter, CacheEntryListenerConfiguration<K, V> configuration, BlazingCacheCache<K, V> parent) { this.synchronous = synchronous; this.parent = parent; this.oldValueRequired = oldValueRequired; this.listener = listener; this.filter = filter; this.configuration = configuration; this.onCreate = listener instanceof CacheEntryCreatedListener; this.onUpdate = listener instanceof CacheEntryUpdatedListener; this.onRemove = listener instanceof CacheEntryRemovedListener; this.needPreviousValue = oldValueRequired || onRemove || onUpdate; }
Example #8
Source File: BlazingCacheCacheEntryListenerWrapper.java From blazingcache with Apache License 2.0 | 5 votes |
void onEntryCreated(K key, V value) { if (onCreate) { BlazingCacheCacheEntryEvent event = new BlazingCacheCacheEntryEvent(key, null, value, parent, EventType.CREATED, false); if (filter != null && !filter.evaluate(event)) { return; } ((CacheEntryCreatedListener) listener).onCreated(Arrays.asList(event)); } }
Example #9
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 #10
Source File: JCSListener.java From commons-jcs with Apache License 2.0 | 5 votes |
public void onCreated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException { if (create) { CacheEntryCreatedListener.class.cast(delegate).onCreated(filter(events)); } }
Example #11
Source File: EventTypeAwareListener.java From caffeine with Apache License 2.0 | 5 votes |
/** Returns if the backing listener consumes this type of event. */ @SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") public boolean isCompatible(@NonNull EventType eventType) { switch (eventType) { case CREATED: return (listener instanceof CacheEntryCreatedListener<?, ?>); case UPDATED: return (listener instanceof CacheEntryUpdatedListener<?, ?>); case REMOVED: return (listener instanceof CacheEntryRemovedListener<?, ?>); case EXPIRED: return (listener instanceof CacheEntryExpiredListener<?, ?>); } throw new IllegalStateException("Unknown event type: " + eventType); }
Example #12
Source File: EventTypeAwareListener.java From caffeine with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) { if (listener instanceof CacheEntryCreatedListener<?, ?>) { ((CacheEntryCreatedListener<K, V>) listener).onCreated(events); } }
Example #13
Source File: EventTypeFilter.java From caffeine with Apache License 2.0 | 5 votes |
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") private boolean isCompatible(CacheEntryEvent<? extends K, ? extends V> event) { switch (event.getEventType()) { case CREATED: return (listener instanceof CacheEntryCreatedListener<?, ?>); case UPDATED: return (listener instanceof CacheEntryUpdatedListener<?, ?>); case REMOVED: return (listener instanceof CacheEntryRemovedListener<?, ?>); case EXPIRED: return (listener instanceof CacheEntryExpiredListener<?, ?>); } throw new CacheEntryListenerException("Unknown event type: " + event.getEventType()); }
Example #14
Source File: Listener.java From cache2k with Apache License 2.0 | 4 votes |
public Created(final CacheEntryListenerConfiguration<K, V> _config, final CacheEntryEventFilter<K, V> _filter, final CacheEntryCreatedListener<K, V> _listener) { super(_config, _filter, _listener); listener = _listener; }
Example #15
Source File: EntitlementBaseCache.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
public void setCacheEntryCreatedListener(CacheEntryCreatedListener<K, V> cacheEntryCreatedListener) { this.cacheEntryCreatedListener = cacheEntryCreatedListener; }
Example #16
Source File: EventListenerAdaptors.java From ehcache3 with Apache License 2.0 | 4 votes |
CreatedAdaptor(Cache<K, V> source, CacheEntryCreatedListener<K, V> listener, CacheEntryEventFilter<K, V> filter, boolean requestsOld) { super(source, filter, requestsOld); this.listener = listener; }
Example #17
Source File: EntitlementBaseCache.java From carbon-identity with Apache License 2.0 | 4 votes |
public void setCacheEntryCreatedListener(CacheEntryCreatedListener<K, V> cacheEntryCreatedListener) { this.cacheEntryCreatedListener = cacheEntryCreatedListener; }
Example #18
Source File: CacheContinuousQueryManager.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws IgniteCheckedException In case of error. */ @SuppressWarnings("unchecked") void execute() throws IgniteCheckedException { if (!onStart) cctx.config().addCacheEntryListenerConfiguration(cfg); CacheEntryListener locLsnrImpl = (CacheEntryListener)cfg.getCacheEntryListenerFactory().create(); if (locLsnrImpl == null) throw new IgniteCheckedException("Local CacheEntryListener is mandatory and can't be null."); byte types = 0; types |= locLsnrImpl instanceof CacheEntryCreatedListener ? CREATED_FLAG : 0; types |= locLsnrImpl instanceof CacheEntryUpdatedListener ? UPDATED_FLAG : 0; types |= locLsnrImpl instanceof CacheEntryRemovedListener ? REMOVED_FLAG : 0; types |= locLsnrImpl instanceof CacheEntryExpiredListener ? EXPIRED_FLAG : 0; if (types == 0) throw new IgniteCheckedException("Listener must implement one of CacheEntryListener sub-interfaces."); final byte types0 = types; locLsnr = new JCacheQueryLocalListener( locLsnrImpl, log); routineId = executeQuery0( locLsnr, new IgniteOutClosure<CacheContinuousQueryHandler>() { @Override public CacheContinuousQueryHandler apply() { CacheContinuousQueryHandler hnd; Factory<CacheEntryEventFilter<K, V>> rmtFilterFactory = cfg.getCacheEntryEventFilterFactory(); if (rmtFilterFactory != null) hnd = new CacheContinuousQueryHandlerV2( cctx.name(), TOPIC_CACHE.topic(topicPrefix, cctx.localNodeId(), seq.getAndIncrement()), locLsnr, securityAwareFilterFactory(rmtFilterFactory), cfg.isOldValueRequired(), cfg.isSynchronous(), false, false, types0); else { JCacheQueryRemoteFilter jCacheFilter; CacheEntryEventFilter filter = null; if (rmtFilterFactory != null) { filter = rmtFilterFactory.create(); if (!(filter instanceof Serializable)) throw new IgniteException("Topology has nodes of the old versions. " + "In this case EntryEventFilter must implement java.io.Serializable " + "interface. Filter: " + filter); } jCacheFilter = new JCacheQueryRemoteFilter(filter, types0); hnd = new CacheContinuousQueryHandler( cctx.name(), TOPIC_CACHE.topic(topicPrefix, cctx.localNodeId(), seq.getAndIncrement()), locLsnr, securityAwareFilter(jCacheFilter), cfg.isOldValueRequired(), cfg.isSynchronous(), false, false); } return hnd; } }, ContinuousQuery.DFLT_PAGE_SIZE, ContinuousQuery.DFLT_TIME_INTERVAL, ContinuousQuery.DFLT_AUTO_UNSUBSCRIBE, false, false, false, keepBinary, onStart ); }
Example #19
Source File: ListenerCacheEventManager.java From triava with Apache License 2.0 | 4 votes |
@Override public void created(CacheEntryCreatedListener<K, V> listener, TCacheEntryEventCollection<K, V> eventColl) { listener.onCreated(eventColl.events()); }
Example #20
Source File: CacheEventManager.java From triava with Apache License 2.0 | votes |
void created(CacheEntryCreatedListener<K, V> listener, TCacheEntryEventCollection<K, V> eventColl);