com.nepxion.discovery.plugin.configcenter.zookeeper.adapter.ZookeeperConfigAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-config-center-starter-zookeeper Show documentation
Show all versions of discovery-plugin-config-center-starter-zookeeper Show documentation
Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent
package com.nepxion.discovery.plugin.configcenter.zookeeper.adapter;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author rotten
* @author Ning Zhang
* @version 1.0
*/
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.common.entity.ConfigType;
import com.nepxion.discovery.common.zookeeper.operation.ZookeeperListener;
import com.nepxion.discovery.common.zookeeper.operation.ZookeeperOperation;
import com.nepxion.discovery.common.zookeeper.operation.ZookeeperSubscribeCallback;
import com.nepxion.discovery.plugin.configcenter.adapter.ConfigAdapter;
public class ZookeeperConfigAdapter extends ConfigAdapter {
@Autowired
private ZookeeperOperation zookeeperOperation;
private ZookeeperListener partialZookeeperListener;
private ZookeeperListener globalZookeeperListener;
@Override
public String getConfig(String group, String dataId) throws Exception {
return zookeeperOperation.getConfig(group, dataId);
}
@PostConstruct
@Override
public void subscribeConfig() {
partialZookeeperListener = subscribeConfig(false);
globalZookeeperListener = subscribeConfig(true);
}
private ZookeeperListener subscribeConfig(boolean globalConfig) {
String group = getGroup();
String dataId = getDataId(globalConfig);
logSubscribeStarted(globalConfig);
try {
return zookeeperOperation.subscribeConfig(group, dataId, new ZookeeperSubscribeCallback() {
@Override
public void callback(String config) {
callbackConfig(config, globalConfig);
}
});
} catch (Exception e) {
logSubscribeFailed(e, globalConfig);
}
return null;
}
@Override
public void unsubscribeConfig() {
unsubscribeConfig(partialZookeeperListener, false);
unsubscribeConfig(globalZookeeperListener, true);
}
private void unsubscribeConfig(ZookeeperListener zookeeperListener, boolean globalConfig) {
if (zookeeperListener == null) {
return;
}
String group = getGroup();
String dataId = getDataId(globalConfig);
logUnsubscribeStarted(globalConfig);
try {
zookeeperOperation.unsubscribeConfig(group, dataId, zookeeperListener);
} catch (Exception e) {
logUnsubscribeFailed(e, globalConfig);
}
}
@Override
public ConfigType getConfigType() {
return ConfigType.ZOOKEEPER;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy