com.github.javaclub.configcenter.client.conf.AppCfg Maven / Gradle / Ivy
The newest version!
package com.github.javaclub.configcenter.client.conf;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.javaclub.configcenter.client.ConfigChangeListener;
/**
* Appy应用维度的配置项key列表 及 相关变更监听器
*/
public class AppCfg {
static Logger log = LoggerFactory.getLogger(AppCfg.class);
public int appid;
public String appkey;
public List configKeyList = new ArrayList();
public Map> listeners = new HashMap>();
public Object lock = new Object();
public void addConfigKey(String configkey, ConfigChangeListener configListener) {
synchronized (lock) {
if (!configKeyList.contains(configkey)) {
configKeyList.add(configkey);
}
if (null != configListener) {
if (null == listeners.get(configkey)) {
listeners.put(configkey, new ArrayList());
}
if (!listeners.get(configkey).contains(configListener)) {
listeners.get(configkey).add(configListener);
}
}
}
}
public void removeConfigKey(String configkey) {
boolean withLock = ConfigRemoveFlagHolder.get();
if (!withLock) {
this.doRemoveKey(configkey);
return;
}
synchronized (lock) {
this.doRemoveKey(configkey);
}
}
void doRemoveKey(String configkey) {
if (null != configKeyList && configKeyList.contains(configkey)) {
configKeyList.remove(configkey);
}
if (null != listeners && listeners.containsKey(configkey)) {
listeners.remove(configkey);
}
if (log.isInfoEnabled()) {
log.info("Removed configKeyList and configKeyListener: {}", configkey);
}
}
public void init(int appId, String appKey) {
this.appid = appId;
this.appkey = appKey;
}
public int getAppid() {
return appid;
}
public void setAppid(int appid) {
this.appid = appid;
}
public String getAppkey() {
return appkey;
}
public void setAppkey(String appkey) {
this.appkey = appkey;
}
@Override
public String toString() {
return "AppCfg [appid=" + appid + ", appkey=" + appkey + ", configKeyList=" + configKeyList + ", listeners=" + listeners
+ ", lock=" + lock + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy