All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.loadbalancer.ribbon.config.InternalRibbonClientConfigurer Maven / Gradle / Ivy

package org.zodiac.loadbalancer.ribbon.config;

import org.zodiac.core.application.AppInstance;
import org.zodiac.core.bootstrap.breaker.routing.AbstractAppRouter;
import org.zodiac.core.bootstrap.breaker.routing.AppRoutingInfo;
import org.zodiac.core.bootstrap.discovery.AppDiscoveryClient;
import org.zodiac.loadbalancer.ribbon.RibbonPropertiesFactory;
import org.zodiac.loadbalancer.ribbon.breaker.routing.BaseServiceRoutingRule;
import org.zodiac.loadbalancer.ribbon.breaker.routing.DefaultAbstractServiceRoutingRule;
import org.zodiac.loadbalancer.ribbon.constants.PlatformRibbonClientInfo;
import org.zodiac.loadbalancer.ribbon.discovery.InternalDiscoveryServerList;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;

public abstract class InternalRibbonClientConfigurer {

    private AppRoutingInfo appRoutingInfo;
    private PlatformRibbonClientInfo platFormRibbonClientInfo;
    private RibbonPropertiesFactory ribbonPropertiesFactory;

    public InternalRibbonClientConfigurer(AppRoutingInfo appRoutingInfo, PlatformRibbonClientInfo platFormRibbonClientInfo,
        RibbonPropertiesFactory ribbonPropertiesFactory) {
        this.appRoutingInfo = appRoutingInfo;
        this.platFormRibbonClientInfo = platFormRibbonClientInfo;
        this.ribbonPropertiesFactory = ribbonPropertiesFactory;
    }

    protected ServerList ribbonServerList(AppDiscoveryClient appDiscoveryClient, IClientConfig config) {
        String name = obtainRibbonClientName();
        if (this.ribbonPropertiesFactory.isSet(ServerList.class, name)) {
            return this.ribbonPropertiesFactory.get(ServerList.class, config, name);
        } else {
            InternalDiscoveryServerList serverList = new InternalDiscoveryServerList(appDiscoveryClient);
            serverList.initWithNiwsConfig(config);
            return serverList;
        }
    }

    protected IRule rule(IClientConfig config, AbstractAppRouter serviceRoutingRouter,
        AppDiscoveryClient appDiscoveryClient) {
        if(this.ribbonPropertiesFactory.isSet(IRule.class, config.getClientName())){
            return this.ribbonPropertiesFactory.get(IRule.class,config, config.getClientName());
        }
        BaseServiceRoutingRule serviceRoutingRule = obtainServiceRoutingRule(serviceRoutingRouter, appDiscoveryClient);
        serviceRoutingRule.initWithNiwsConfig(config);
        return serviceRoutingRule;
    }

    protected BaseServiceRoutingRule obtainServiceRoutingRule(AbstractAppRouter serviceRoutingRouter, AppDiscoveryClient appDiscoveryClient) {
        return new DefaultAbstractServiceRoutingRule(appRoutingInfo, serviceRoutingRouter, appDiscoveryClient);
    }

    protected String obtainRibbonClientName() {
        return this.platFormRibbonClientInfo.getName();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy