use of com.linkedin.d2.balancer.LoadBalancerClusterListener in project rest.li by linkedin.
the class SimpleLoadBalancerState method shutdown.
@Override
public void shutdown(final PropertyEventShutdownCallback shutdown) {
trace(_log, "shutdown");
// shutdown all three registries, all tracker clients, and the event thread
_executor.execute(new PropertyEvent("shutdown load balancer state") {
@Override
public void innerRun() {
// Need to shutdown loadBalancerStrategies before the transportClients are shutdown
for (Map<String, LoadBalancerStrategy> strategyEntry : _serviceStrategies.values()) {
strategyEntry.values().forEach(LoadBalancerStrategy::shutdown);
}
// put all tracker clients into a single set for convenience
Set<TransportClient> transportClients = new HashSet<>();
for (Map<String, TransportClient> clientsByScheme : _serviceClients.values()) {
transportClients.addAll(clientsByScheme.values());
}
Callback<None> trackerCallback = Callbacks.countDown(Callbacks.<None>adaptSimple(new SimpleCallback() {
@Override
public void onDone() {
shutdown.done();
}
}), transportClients.size());
info(_log, "shutting down cluster clients");
for (TransportClient transportClient : transportClients) {
transportClient.shutdown(trackerCallback);
}
// so it is needed to notify all the listeners
for (SimpleLoadBalancerStateListener listener : _listeners) {
// Notify the strategy removal
for (Map.Entry<String, Map<String, LoadBalancerStrategy>> serviceStrategy : _serviceStrategies.entrySet()) {
for (Map.Entry<String, LoadBalancerStrategy> strategyEntry : serviceStrategy.getValue().entrySet()) {
listener.onStrategyRemoved(serviceStrategy.getKey(), strategyEntry.getKey(), strategyEntry.getValue());
}
// Also notify the client removal
Map<URI, TrackerClient> trackerClients = _trackerClients.get(serviceStrategy.getKey());
if (trackerClients != null) {
for (TrackerClient client : trackerClients.values()) {
listener.onClientRemoved(serviceStrategy.getKey(), client);
}
}
}
}
// When SimpleLoadBalancerStateis shutdown, all the cluster listener also need to be notified.
for (LoadBalancerClusterListener clusterListener : _clusterListeners) {
for (String clusterName : _clusterInfo.keySet()) {
clusterListener.onClusterRemoved(clusterName);
}
}
}
});
}
use of com.linkedin.d2.balancer.LoadBalancerClusterListener in project rest.li by linkedin.
the class SimpleLoadBalancerState method unregisterClusterListener.
@Override
public void unregisterClusterListener(final LoadBalancerClusterListener listener) {
trace(_log, "unregister listener: ", listener);
_executor.execute(new PropertyEvent("remove cluster listener for state") {
@Override
public void innerRun() {
_clusterListeners.remove(listener);
}
});
}
use of com.linkedin.d2.balancer.LoadBalancerClusterListener in project rest.li by linkedin.
the class SimpleLoadBalancerState method registerClusterListener.
@Override
public void registerClusterListener(final LoadBalancerClusterListener listener) {
trace(_log, "register listener: ", listener);
_executor.execute(new PropertyEvent("add cluster listener for state") {
@Override
public void innerRun() {
if (!_clusterListeners.contains(listener)) {
// don't allow duplicates, there's no need for a cluster listener to be registered twice.
_clusterListeners.add(listener);
}
}
});
}
Aggregations