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

org.zodiac.sentinel.base.cluster.client.ClusterClientInitFunc Maven / Gradle / Ivy

package org.zodiac.sentinel.base.cluster.client;

import org.zodiac.sentinel.base.cluster.ClusterInitFunc;

import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientAssignConfig;
import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientConfig;
import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientConfigManager;
import com.alibaba.csp.sentinel.cluster.registry.ConfigSupplierRegistry;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.util.AppNameUtil;

public abstract class ClusterClientInitFunc extends ClusterInitFunc {

    public ClusterClientInitFunc() {
        super();
    }

    public ClusterClientInitFunc(String namespacePrefix) {
        super(namespacePrefix);
    }

    @Override
    protected final void initialize() throws Exception {
        ClusterClientOption clusterClientOption = obtainClusterOption();

        ReadableDataSource ds = clusterClientOption.getClusterDataSource();
        ClusterClientConfigManager.registerServerAssignProperty(ds.getProperty());

        ReadableDataSource clusterModeDs = clusterClientOption.getClusterModeDataSource();
        ClusterStateManager.registerProperty(clusterModeDs.getProperty());

        ConfigSupplierRegistry.setNamespaceSupplier(() -> String.format("%s%s", getNamespacePrefix(), AppNameUtil.getAppName()));

        ReadableDataSource clientConfigDs = clusterClientOption.getClientConfigDataSource();
        ClusterClientConfigManager.registerClientConfigProperty(clientConfigDs.getProperty());
    }

    protected abstract ClusterClientOption obtainClusterOption();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy