use of com.alibaba.nacos.api.config.listener.Listener in project incubator-skywalking by apache.
the class NacosConfigWatcherRegister method removeUninterestedKeys.
private void removeUninterestedKeys(final Set<String> interestedKeys) {
final String group = settings.getGroup();
final Set<String> uninterestedKeys = new HashSet<>(listenersByKey.keySet());
uninterestedKeys.removeAll(interestedKeys);
uninterestedKeys.forEach(k -> {
final Listener listener = listenersByKey.remove(k);
if (listener != null) {
configService.removeListener(k, group, listener);
}
});
}
use of com.alibaba.nacos.api.config.listener.Listener in project skywalking by apache.
the class NacosConfigWatcherRegister method registerKeyListeners.
private void registerKeyListeners(final Set<String> keys) {
final String group = settings.getGroup();
for (final String dataId : keys) {
if (listenersByKey.containsKey(dataId)) {
continue;
}
try {
listenersByKey.putIfAbsent(dataId, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
onDataIdValueChanged(dataId, configInfo);
}
});
configService.addListener(dataId, group, listenersByKey.get(dataId));
// the key is newly added, read the config for the first time
final String config = configService.getConfig(dataId, group, 1000);
onDataIdValueChanged(dataId, config);
} catch (NacosException e) {
log.warn("Failed to register Nacos listener for dataId: {}", dataId);
}
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class CacheDataTest method testListener.
@Test
public void testListener() {
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
final CacheData cacheData1 = new CacheData(filter, "name1", "key", "group", "tenant");
Listener listener = new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
}
};
cacheData1.addListener(listener);
Assert.assertEquals(1, cacheData1.getListeners().size());
Assert.assertEquals(listener, cacheData1.getListeners().get(0));
cacheData1.removeListener(listener);
Assert.assertEquals(0, cacheData1.getListeners().size());
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class ClientWorkerTest method testAddListenerWithoutTenant.
@Test
public void testAddListenerWithoutTenant() throws NacosException {
Properties prop = new Properties();
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
ServerListManager agent = Mockito.mock(ServerListManager.class);
ClientWorker clientWorker = new ClientWorker(filter, agent, prop);
String dataId = "a";
String group = "b";
Listener listener = new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
}
};
clientWorker.addListeners(dataId, group, Arrays.asList(listener));
List<Listener> listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(1, listeners.size());
Assert.assertEquals(listener, listeners.get(0));
clientWorker.removeListener(dataId, group, listener);
listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(0, listeners.size());
CacheData cacheData = clientWorker.addCacheDataIfAbsent(dataId, group);
Assert.assertEquals(cacheData, clientWorker.getCache(dataId, group));
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class NacosConfigServiceTest method testAddListener.
@Test
public void testAddListener() throws NacosException {
String dataId = "1";
String group = "2";
Listener listener = new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
}
};
nacosConfigService.addListener(dataId, group, listener);
Mockito.verify(mockWoker, Mockito.times(1)).addTenantListeners(dataId, group, Arrays.asList(listener));
}
Aggregations