@CacheEntryCreated @CacheEntryModified public void event(CacheEntryEvent<Address, Map.Entry<K, V>> event) { if (event.isOriginLocal() || event.isPre()) return; if (!this.listeners.isEmpty()) { Map.Entry<K, V> entry = event.getValue(); if (entry != null) { this.notifyListeners(event.getType(), entry); } } }
@CacheEntryRemoved public void removed(CacheEntryRemovedEvent<Address, Map.Entry<K, V>> event) { if (event.isOriginLocal() || event.isPre()) return; if (!this.listeners.isEmpty()) { Map.Entry<K, V> entry = event.getOldValue(); // WFLY-4938 For some reason, the old value can be null if (entry != null) { this.notifyListeners(event.getType(), entry); } } }
@DataRehashed public void dataRehashed(DataRehashedEvent<BeanKey<I>, BeanEntry<I>> event) { Locality newLocality = new ConsistentHashLocality(event.getCache(), event.getConsistentHashAtEnd());
@CacheEntryVisited @CacheEntryActivated @CacheEntryModified @CacheEntryRemoved @CacheEntryCreated @CacheEntryInvalidated @CacheEntryPassivated public void listenEvent(CacheEntryEvent event) { events.add(event); } }
@CacheEntryVisited @CacheEntryRemoved public void callback(Event e) { } }
@CacheEntriesEvicted public void evicted(CacheEntriesEvictedEvent<Key<String>, ?> event) { if (!event.isPre()) { Cache<SessionAccessMetaDataKey, SessionAccessMetaData> cache = this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION); for (Key<String> key : event.getEntries().keySet()) { // Workaround for ISPN-8324 if (key instanceof SessionCreationMetaDataKey) { cache.evict(new SessionAccessMetaDataKey(key.getValue())); } } } } }
@CacheEntryActivated public void activated(CacheEntryActivatedEvent<SessionCreationMetaDataKey, ?> event) { if (!event.isPre() && !this.properties.isPersistent()) { String id = event.getKey().getValue(); InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s was activated", id); Map.Entry<MV, AV> value = this.factory.findValue(id); if (value != null) { ImmutableSession session = this.factory.createImmutableSession(id, value); this.triggerPostActivationEvents(session); } } }
@CacheEntryPassivated public void passivated(CacheEntryPassivatedEvent<SessionCreationMetaDataKey, ?> event) { if (event.isPre() && !this.properties.isPersistent()) { String id = event.getKey().getValue(); InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be passivated", id); Map.Entry<MV, AV> value = this.factory.findValue(id); if (value != null) { ImmutableSession session = this.factory.createImmutableSession(id, value); this.triggerPrePassivationEvents(session); } } }
@TopologyChanged public void topologyChanged(TopologyChangedEvent<?, ?> event) { if (event.isPre()) return; int viewId = event.getCache().getCacheManager().getTransport().getViewId(); if (!this.listeners.isEmpty()) { Address localAddress = event.getCache().getCacheManager().getAddress(); Membership previousMembership = new CacheMembership(localAddress, event.getWriteConsistentHashAtStart(), this); Membership membership = new CacheMembership(localAddress, event.getWriteConsistentHashAtEnd(), this); Boolean status = this.views.get(viewId); boolean merged = (status != null) ? status.booleanValue() : false; for (Map.Entry<GroupListener, ExecutorService> entry : this.listeners.entrySet()) { GroupListener listener = entry.getKey(); ExecutorService executor = entry.getValue(); try { executor.submit(() -> { try { listener.membershipChanged(previousMembership, membership, merged); } catch (Throwable e) { ClusteringServerLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } }); } catch (RejectedExecutionException e) { // Listener was unregistered } } } // Purge obsolete views this.views.headMap(viewId).clear(); }
@CacheEntryVisited @CacheEntryActivated @CacheEntryModified @CacheEntryRemoved @CacheEntryCreated @CacheEntryInvalidated @CacheEntryPassivated public void listenEvent(CacheEntryEvent event) { events.add(event); } }
@CacheEntryCreated @CacheEntryModified public void modified(CacheEntryEvent<T, Set<Address>> event) { if (event.isPre()) return; Map.Entry<Listener, ExecutorService> entry = this.listeners.get(event.getKey()); if (entry != null) { Listener listener = entry.getKey(); if (listener != null) { ExecutorService executor = entry.getValue(); Set<Node> members = new TreeSet<>(); for (Address address : event.getValue()) { members.add(this.group.createNode(address)); } try { executor.submit(() -> { try { listener.providersChanged(members); } catch (Throwable e) { ClusteringServerLogger.ROOT_LOGGER.serviceProviderRegistrationListenerFailed(e, this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName(), this.cache.getName(), members); } }); } catch (RejectedExecutionException e) { // Executor was shutdown } } } } }
@CacheEntryRemoved @CacheEntryVisited public void callback(Event nme) { } }
@CacheEntryRemoved public void removed(CacheEntryRemovedEvent<SessionCreationMetaDataKey, ?> event) { if (event.isPre()) { String id = event.getKey().getValue(); InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be removed", id); Map.Entry<MV, AV> value = this.factory.findValue(id); if (value != null) { ImmutableSession session = this.factory.createImmutableSession(id, value); ImmutableSessionAttributes attributes = session.getAttributes(); HttpSession httpSession = new ImmutableHttpSessionAdapter(session, this.context); for (String name: attributes.getAttributeNames()) { Object attribute = attributes.getAttribute(name); if (attribute instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener = (HttpSessionBindingListener) attribute; listener.valueUnbound(new HttpSessionBindingEvent(httpSession, name, attribute)); } } if (this.recorder != null) { this.recorder.record(session); } } } }
@CacheEntriesEvicted public void evicted(CacheEntriesEvictedEvent<Key<String>, ?> event) { if (!event.isPre()) { Cache<SessionAttributesKey, V> cache = this.cache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION); for (Key<String> key : event.getEntries().keySet()) { // Workaround for ISPN-8324 if (key instanceof SessionCreationMetaDataKey) { cache.evict(new SessionAttributesKey(key.getValue())); } } } } }
@CacheEntryActivated public void activated(CacheEntryActivatedEvent<BeanGroupKey<I>, BeanGroupEntry<I, T>> event) { if (!event.isPre()) { BeanGroupEntry<I, T> entry = event.getValue(); try (BeanGroup<I, T> group = new InfinispanBeanGroup<>(event.getKey().getId(), entry, this.context, Mutator.PASSIVE, this)) { for (I beanId : group.getBeans()) { BeanKey<I> beanKey = new InfinispanBeanKey<>(beanId); BeanEntry<I> beanEntry = this.beanCache.get(beanKey); if ((beanEntry != null) && this.beanFilter.test(new AbstractMap.SimpleImmutableEntry<>(beanKey, beanEntry))) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Activating bean %s", beanKey); this.passiveCount.decrementAndGet(); group.postActivate(beanId, this.passivationListener); } } } catch (Exception e) { InfinispanEjbLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } } }
@CacheEntryPassivated public void passivated(CacheEntryPassivatedEvent<BeanGroupKey<I>, BeanGroupEntry<I, T>> event) { if (event.isPre()) { BeanGroupEntry<I, T> entry = event.getValue(); try (BeanGroup<I, T> group = new InfinispanBeanGroup<>(event.getKey().getId(), entry, this.context, Mutator.PASSIVE, this)) { for (I beanId : group.getBeans()) { BeanKey<I> beanKey = new InfinispanBeanKey<>(beanId); BeanEntry<I> beanEntry = this.beanCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).get(beanKey); if ((beanEntry != null) && this.beanFilter.test(new AbstractMap.SimpleImmutableEntry<>(beanKey, beanEntry))) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Passivating bean %s", beanKey); this.passiveCount.incrementAndGet(); group.prePassivate(beanId, this.passivationListener); // Cascade evict to bean entry this.beanCache.evict(beanKey); } } } catch (Exception e) { InfinispanEjbLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } }
@TopologyChanged public void topologyChanged(TopologyChangedEvent<Address, Map.Entry<K, V>> event) { if (event.isPre()) return;
@DataRehashed public void dataRehashed(DataRehashedEvent<SessionCreationMetaDataKey, ?> event) { Cache<SessionCreationMetaDataKey, ?> cache = event.getCache(); Locality newLocality = new ConsistentHashLocality(cache, event.getConsistentHashAtEnd()); if (event.isPre()) { Future<?> future = this.rehashFuture.getAndSet(null); if (future != null) { future.cancel(true); } try { this.executor.submit(() -> this.dispatcher.getContext().cancel(newLocality)); } catch (RejectedExecutionException e) { // Executor was shutdown } } else { Locality oldLocality = new ConsistentHashLocality(cache, event.getConsistentHashAtStart()); try { this.rehashFuture.set(this.executor.submit(() -> this.schedule(oldLocality, newLocality))); } catch (RejectedExecutionException e) { // Executor was shutdown } } }
@CacheEntryVisited @CacheEntryActivated @CacheEntryModified @CacheEntryRemoved @CacheEntryCreated @CacheEntryInvalidated @CacheEntryPassivated public void listenEvent(CacheEntryEvent event) { events.add(event); } }
@CacheEntriesEvicted public void evicted(CacheEntriesEvictedEvent<Key<String>, ?> event) { if (!event.isPre()) { Set<SessionAttributeNamesKey> keys = new HashSet<>(); for (Key<String> key : event.getEntries().keySet()) { // Workaround for ISPN-8324 if (key instanceof SessionCreationMetaDataKey) { keys.add(new SessionAttributeNamesKey(key.getValue())); } } if (!keys.isEmpty()) { Cache<SessionAttributeKey, V> cache = this.attributeCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION); for (Map.Entry<SessionAttributeNamesKey, Map<String, UUID>> entry : this.namesCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_LOAD, Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).getAll(keys).entrySet()) { Map<String, UUID> names = entry.getValue(); if (names != null) { String sessionId = entry.getKey().getValue(); for (UUID attributeId : names.values()) { cache.evict(new SessionAttributeKey(sessionId, attributeId)); } } this.namesCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION).evict(entry.getKey()); } } } } }