use of org.apache.dubbo.common.config.configcenter.ConfigurationListener in project dubbo by alibaba.
the class ApolloDynamicConfigurationTest method testAddListener.
/**
* Test add listener.
*
* @throws Exception the exception
*/
@Test
@Order(3)
public void testAddListener() throws Exception {
String mockKey = "mockKey3";
String mockValue = String.valueOf(new Random().nextInt());
final SettableFuture<org.apache.dubbo.common.config.configcenter.ConfigChangedEvent> future = SettableFuture.create();
apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
apolloDynamicConfiguration.addListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() {
@Override
public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) {
future.set(event);
}
});
putData(mockKey, mockValue);
org.apache.dubbo.common.config.configcenter.ConfigChangedEvent result = future.get(3000, TimeUnit.MILLISECONDS);
assertEquals(mockValue, result.getContent());
assertEquals(mockKey, result.getKey());
assertEquals(ConfigChangeType.MODIFIED, result.getChangeType());
}
use of org.apache.dubbo.common.config.configcenter.ConfigurationListener in project dubbo by alibaba.
the class CacheListener method dataChanged.
@Override
public void dataChanged(String path, Object value, EventType eventType) {
ConfigChangeType changeType;
if (EventType.NodeCreated.equals(eventType)) {
changeType = ConfigChangeType.ADDED;
} else if (value == null) {
changeType = ConfigChangeType.DELETED;
} else {
changeType = ConfigChangeType.MODIFIED;
}
String key = pathToKey(path);
ConfigChangedEvent configChangeEvent = new ConfigChangedEvent(key, getGroup(path), (String) value, changeType);
Set<ConfigurationListener> listeners = keyListeners.get(path);
if (CollectionUtils.isNotEmpty(listeners)) {
listeners.forEach(listener -> listener.process(configChangeEvent));
}
}
use of org.apache.dubbo.common.config.configcenter.ConfigurationListener in project dubbo by alibaba.
the class FileSystemDynamicConfiguration method doInListener.
private void doInListener(String configFilePath, BiConsumer<File, List<ConfigurationListener>> consumer) {
watchService.ifPresent(watchService -> {
File configFile = new File(configFilePath);
executeMutually(configFile.getParentFile(), () -> {
// process the WatchEvents if not start
if (!isProcessingWatchEvents()) {
processWatchEvents(watchService);
}
List<ConfigurationListener> listeners = getListeners(configFile);
consumer.accept(configFile, listeners);
// Nothing to return
return null;
});
});
}
use of org.apache.dubbo.common.config.configcenter.ConfigurationListener in project dubbo by alibaba.
the class ApolloDynamicConfigurationTest method testRemoveListener.
/**
* Test remove listener.
*
* @throws Exception the exception
*/
@Test
@Order(4)
public void testRemoveListener() throws Exception {
String mockKey = "mockKey4";
String mockValue = String.valueOf(new Random().nextInt());
final SettableFuture<org.apache.dubbo.common.config.configcenter.ConfigChangedEvent> future = SettableFuture.create();
apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
apolloDynamicConfiguration.addListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() {
@Override
public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) {
future.set(event);
}
});
putData(mockKey, mockValue);
future.get(3000, TimeUnit.MILLISECONDS);
apolloDynamicConfiguration.removeListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() {
@Override
public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) {
future.set(event);
}
});
deleteData(mockKey);
org.apache.dubbo.common.config.configcenter.ConfigChangedEvent result = future.get(3000, TimeUnit.MILLISECONDS);
assertEquals(mockValue, result.getContent());
assertEquals(mockKey, result.getKey());
assertEquals(ConfigChangeType.MODIFIED, result.getChangeType());
}
Aggregations