memberActivatedEvent.getServiceName(), memberActivatedEvent.getClusterId()));
}
return;
}
// Cluster not found in load balancer context, add it
Service service = TopologyManager.getTopology().getService(memberActivatedEvent.getServiceName());
if (service != null) {
Cluster cluster = service.getCluster(memberActivatedEvent.getClusterId());
if (cluster != null) {
LoadBalancerContextUtil.addClusterToLbContext(cluster);
} else {
if (log.isErrorEnabled()) {
log.error(String.format("Cluster not found in topology: [service] %s [cluster] %s",
memberActivatedEvent.getServiceName(), memberActivatedEvent.getClusterId()));
}
}
} else {
if (log.isErrorEnabled()) {
log.error(String.format("Service not found in topology: [service] %s", memberActivatedEvent.getServiceName()));
}
}
} catch (Exception e) {
log.error("Error processing event", e);
} finally {
TopologyManager.releaseReadLock();
}
}
});
topologyEventReceiver.addEventListener(new ClusterRemovedEventListener() {
@Override
protected void onEvent(Event event) {
try {
TopologyManager.acquireReadLock();
// Remove cluster from context
ClusterRemovedEvent clusterRemovedEvent = (ClusterRemovedEvent) event;
Cluster cluster = LoadBalancerContext.getInstance().getClusterIdClusterMap().getCluster(clusterRemovedEvent.getClusterId());
if (cluster != null) {
LoadBalancerContextUtil.removeClusterFromLbContext(cluster.getClusterId());
} else {
if (log.isWarnEnabled()) {
log.warn(String.format("Cluster not found in load balancer context: [service] %s [cluster] %s",
clusterRemovedEvent.getServiceName(), clusterRemovedEvent.getClusterId()));
}
}
} catch (Exception e) {
log.error("Error processing event", e);
} finally {
TopologyManager.releaseReadLock();
}
}
});
topologyEventReceiver.addEventListener(new ServiceRemovedEventListener() {
@Override
protected void onEvent(Event event) {
try {
TopologyManager.acquireReadLock();
// Remove all clusters of given service from context
ServiceRemovedEvent serviceRemovedEvent = (ServiceRemovedEvent) event;
Service service = TopologyManager.getTopology().getService(serviceRemovedEvent.getServiceName());
if (service != null) {
for (Cluster cluster : service.getClusters()) {
LoadBalancerContextUtil.removeClusterFromLbContext(cluster.getClusterId());
}
} else {
if (log.isWarnEnabled()) {
log.warn(String.format("Service not found in topology: [service] %s", serviceRemovedEvent.getServiceName()));