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