use of com.linkedin.d2.balancer.simple.SimpleLoadBalancerState.SimpleLoadBalancerStateListener in project rest.li by linkedin.
the class SimpleLoadBalancerState method removeTrackerClients.
void removeTrackerClients(String clusterName) {
warn(_log, "removing all tracker clients for cluster: ", clusterName);
Set<String> serviceNames = _servicesPerCluster.get(clusterName);
if (serviceNames != null) {
for (String serviceName : serviceNames) {
Map<URI, TrackerClient> clients = _trackerClients.remove(serviceName);
if (clients != null) {
for (TrackerClient client : clients.values()) {
// notify listeners of the removed client
for (SimpleLoadBalancerStateListener listener : _listeners) {
listener.onClientRemoved(serviceName, client);
}
}
}
}
}
}
use of com.linkedin.d2.balancer.simple.SimpleLoadBalancerState.SimpleLoadBalancerStateListener in project rest.li by linkedin.
the class D2ClientJmxManager method setSimpleLoadBalancerState.
public void setSimpleLoadBalancerState(SimpleLoadBalancerState state) {
_jmxManager.registerLoadBalancerState(_prefix + "-LoadBalancerState", state);
state.register(new SimpleLoadBalancerStateListener() {
@Override
public void onStrategyAdded(String serviceName, String scheme, LoadBalancerStrategy strategy) {
_jmxManager.registerLoadBalancerStrategy(getLoadBalancerStrategyJmxName(serviceName, scheme), strategy);
}
@Override
public void onStrategyRemoved(String serviceName, String scheme, LoadBalancerStrategy strategy) {
_jmxManager.unregister(getLoadBalancerStrategyJmxName(serviceName, scheme));
}
@Override
public void onClientAdded(String clusterName, TrackerClient client) {
// We currently think we can make this no-op as the info provided is not helpful
// _jmxManager.checkReg(new DegraderControl((DegraderImpl) client.getDegrader(DefaultPartitionAccessor.DEFAULT_PARTITION_ID)),
// _prefix + "-" + clusterName + "-" + client.getUri().toString().replace("://", "-") + "-TrackerClient-Degrader");
}
@Override
public void onClientRemoved(String clusterName, TrackerClient client) {
// We currently think we can make this no-op as the info provided is not helpful
// _jmxManager.unregister(_prefix + "-" + clusterName + "-" + client.getUri().toString().replace("://", "-") + "-TrackerClient-Degrader");
}
@Override
public void onClusterInfoUpdate(ClusterInfoItem clusterInfoItem) {
_jmxManager.registerClusterInfo(getClusterInfoJmxName(clusterInfoItem.getClusterPropertiesItem().getProperty().getClusterName()), clusterInfoItem);
}
@Override
public void onClusterInfoRemoval(ClusterInfoItem clusterInfoItem) {
_jmxManager.unregister(getClusterInfoJmxName(clusterInfoItem.getClusterPropertiesItem().getProperty().getClusterName()));
}
@Override
public void onServicePropertiesUpdate(LoadBalancerStateItem<ServiceProperties> serviceProperties) {
_jmxManager.registerServiceProperties(getServicePropertiesJmxName(serviceProperties.getProperty().getServiceName()), serviceProperties);
}
@Override
public void onServicePropertiesRemoval(LoadBalancerStateItem<ServiceProperties> serviceProperties) {
_jmxManager.unregister(getServicePropertiesJmxName(serviceProperties.getProperty().getServiceName()));
}
private String getClusterInfoJmxName(String clusterName) {
return String.format("%s-ClusterInfo", clusterName);
}
private String getServicePropertiesJmxName(String serviceName) {
return String.format("%s-ServiceProperties", serviceName);
}
private String getLoadBalancerStrategyJmxName(String serviceName, String scheme) {
return serviceName + "-" + scheme + "-LoadBalancerStrategy";
}
});
}
Aggregations