Search in sources :

Example 1 with ViewChanged

use of org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged in project wildfly by wildfly.

the class CacheGroup method viewChanged.

@Merged
@ViewChanged
public CompletionStage<Void> viewChanged(ViewChangedEvent event) {
    if (this.cache.getAdvancedCache().getDistributionManager() != null) {
        // Record view status for use by @TopologyChanged event
        this.views.put(event.getViewId(), event.isMergeView());
    } else {
        Membership previousMembership = new CacheMembership(event.getLocalAddress(), event.getOldMembers(), this);
        Membership membership = new CacheMembership(event.getLocalAddress(), event.getNewMembers(), this);
        for (Map.Entry<GroupListener, ExecutorService> entry : this.listeners.entrySet()) {
            GroupListener listener = entry.getKey();
            ExecutorService executor = entry.getValue();
            Runnable listenerTask = new Runnable() {

                @Override
                public void run() {
                    try {
                        listener.membershipChanged(previousMembership, membership, event.isMergeView());
                    } catch (Throwable e) {
                        ClusteringServerLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e);
                    }
                }
            };
            try {
                executor.submit(listenerTask);
            } catch (RejectedExecutionException e) {
            // Listener was unregistered
            }
        }
    }
    return CompletableFutures.completedNull();
}
Also used : GroupListener(org.wildfly.clustering.group.GroupListener) DefaultExecutorService(org.jboss.as.clustering.context.DefaultExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Membership(org.wildfly.clustering.group.Membership) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Merged(org.infinispan.notifications.cachemanagerlistener.annotation.Merged) ViewChanged(org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged)

Aggregations

Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Merged (org.infinispan.notifications.cachemanagerlistener.annotation.Merged)1 ViewChanged (org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged)1 DefaultExecutorService (org.jboss.as.clustering.context.DefaultExecutorService)1 GroupListener (org.wildfly.clustering.group.GroupListener)1 Membership (org.wildfly.clustering.group.Membership)1