Search in sources :

Example 1 with GroupListener

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

the class ChannelCommandDispatcherFactory method viewAccepted.

@Override
public void viewAccepted(View view) {
    View oldView = this.view.getAndSet(view);
    if (oldView != null) {
        List<Address> leftMembers = View.leftMembers(oldView, view);
        if (leftMembers != null) {
            this.members.keySet().removeAll(leftMembers);
        }
        if (!this.listeners.isEmpty()) {
            Address localAddress = this.dispatcher.getChannel().getAddress();
            ViewMembership oldMembership = new ViewMembership(localAddress, oldView, this);
            ViewMembership membership = new ViewMembership(localAddress, view, 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(oldMembership, membership, view instanceof MergeView);
                        } catch (Throwable e) {
                            ClusteringLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e);
                        }
                    }
                };
                try {
                    executor.submit(listenerTask);
                } catch (RejectedExecutionException e) {
                // Executor was shutdown
                }
            }
        }
    }
}
Also used : MergeView(org.jgroups.MergeView) IpAddress(org.jgroups.stack.IpAddress) Address(org.jgroups.Address) InetSocketAddress(java.net.InetSocketAddress) GroupListener(org.wildfly.clustering.group.GroupListener) DefaultExecutorService(org.jboss.as.clustering.context.DefaultExecutorService) ExecutorService(java.util.concurrent.ExecutorService) MergeView(org.jgroups.MergeView) View(org.jgroups.View) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with GroupListener

use of org.wildfly.clustering.group.GroupListener 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 3 with GroupListener

use of org.wildfly.clustering.group.GroupListener 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)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 DefaultExecutorService (org.jboss.as.clustering.context.DefaultExecutorService)3 GroupListener (org.wildfly.clustering.group.GroupListener)3 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 Membership (org.wildfly.clustering.group.Membership)2 InetSocketAddress (java.net.InetSocketAddress)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 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 Address (org.jgroups.Address)1 MergeView (org.jgroups.MergeView)1 View (org.jgroups.View)1