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
}
}
}
}
}
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();
}
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();
}
Aggregations