Search in sources :

Example 1 with Membership

use of org.wildfly.clustering.group.Membership 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)

Example 2 with Membership

use of org.wildfly.clustering.group.Membership in project wildfly by wildfly.

the class CacheGroup method topologyChanged.

@TopologyChanged
public CompletionStage<Void> topologyChanged(TopologyChangedEvent<?, ?> event) {
    if (!event.isPre()) {
        int viewId = event.getCache().getAdvancedCache().getRpcManager().getTransport().getViewId();
        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 : false;
        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, merged);
                    } catch (Throwable e) {
                        ClusteringServerLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e);
                    }
                }
            };
            try {
                executor.submit(listenerTask);
            } catch (RejectedExecutionException e) {
            // Listener was unregistered
            }
        }
        // Purge obsolete views
        this.views.headMap(viewId).clear();
    }
    return CompletableFutures.completedNull();
}
Also used : JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) Address(org.infinispan.remoting.transport.Address) LocalModeAddress(org.infinispan.remoting.transport.LocalModeAddress) GroupListener(org.wildfly.clustering.group.GroupListener) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) 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) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged)

Aggregations

Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 DefaultExecutorService (org.jboss.as.clustering.context.DefaultExecutorService)2 GroupListener (org.wildfly.clustering.group.GroupListener)2 Membership (org.wildfly.clustering.group.Membership)2 TopologyChanged (org.infinispan.notifications.cachelistener.annotation.TopologyChanged)1 Merged (org.infinispan.notifications.cachemanagerlistener.annotation.Merged)1 ViewChanged (org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged)1 Address (org.infinispan.remoting.transport.Address)1 LocalModeAddress (org.infinispan.remoting.transport.LocalModeAddress)1 JGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddress)1