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

com.nepxion.discovery.plugin.configcenter.zookeeper.adapter.ZookeeperConfigAdapter Maven / Gradle / Ivy

Go to download

Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.plugin.configcenter.zookeeper.adapter;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author rotten * @author pegasus * @version 1.0 */ import javax.annotation.PostConstruct; import org.apache.curator.framework.recipes.cache.TreeCacheListener; import org.springframework.beans.factory.annotation.Autowired; import com.nepxion.discovery.common.zookeeper.constant.ZookeeperConstant; import com.nepxion.discovery.common.zookeeper.operation.ZookeeperOperation; import com.nepxion.discovery.common.zookeeper.operation.ZookeeperSubscribeCallback; import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter; import com.nepxion.discovery.plugin.configcenter.logger.ConfigLogger; public class ZookeeperConfigAdapter extends ConfigAdapter { @Autowired private ZookeeperOperation zookeeperOperation; @Autowired private ConfigLogger configLogger; private TreeCacheListener partialListener; private TreeCacheListener globalListener; @Override public String getConfig(String group, String dataId) throws Exception { return zookeeperOperation.getConfig(group, dataId); } @PostConstruct @Override public void subscribeConfig() { partialListener = subscribeConfig(false); globalListener = subscribeConfig(true); } private TreeCacheListener subscribeConfig(boolean globalConfig) { String group = getGroup(); String dataId = getDataId(globalConfig); configLogger.logSubscribeStarted(globalConfig); try { return zookeeperOperation.subscribeConfig(group, dataId, new ZookeeperSubscribeCallback() { @Override public void callback(String config) { callbackConfig(config, globalConfig); } }); } catch (Exception e) { configLogger.logSubscribeFailed(e, globalConfig); } return null; } @Override public void unsubscribeConfig() { unsubscribeConfig(partialListener, false); unsubscribeConfig(globalListener, true); zookeeperOperation.close(); } private void unsubscribeConfig(TreeCacheListener configListener, boolean globalConfig) { if (configListener == null) { return; } String group = getGroup(); String dataId = getDataId(globalConfig); configLogger.logUnsubscribeStarted(globalConfig); try { zookeeperOperation.unsubscribeConfig(group, dataId, configListener); } catch (Exception e) { configLogger.logUnsubscribeFailed(e, globalConfig); } } @Override public String getConfigType() { return ZookeeperConstant.ZOOKEEPER_TYPE; } @Override public boolean isConfigSingleKey() { return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy