Search in sources :

Example 6 with SimpleLoadBalancerStateListener

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);
                    }
                }
            }
        }
    }
}
Also used : TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) URI(java.net.URI)

Example 7 with SimpleLoadBalancerStateListener

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";
        }
    });
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) SimpleLoadBalancerStateListener(com.linkedin.d2.balancer.simple.SimpleLoadBalancerState.SimpleLoadBalancerStateListener) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ClusterInfoItem(com.linkedin.d2.balancer.simple.ClusterInfoItem)

Aggregations

TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)4 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)3 PropertyEvent (com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEvent)3 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Callback (com.linkedin.common.callback.Callback)1 SimpleCallback (com.linkedin.common.callback.SimpleCallback)1 None (com.linkedin.common.util.None)1 LoadBalancerClusterListener (com.linkedin.d2.balancer.LoadBalancerClusterListener)1 LoadBalancerStateItem (com.linkedin.d2.balancer.LoadBalancerStateItem)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1 ClusterInfoItem (com.linkedin.d2.balancer.simple.ClusterInfoItem)1 SimpleLoadBalancerStateListener (com.linkedin.d2.balancer.simple.SimpleLoadBalancerState.SimpleLoadBalancerStateListener)1 RelativeLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy)1 PropertyEventShutdownCallback (com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEventShutdownCallback)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1