use of org.apache.dubbo.common.config.configcenter.ConfigChangeType in project dubbo by alibaba.
the class FileSystemDynamicConfiguration method processWatchEvents.
/**
* Process the {@link WatchEvent WatchEvents} loop in async execution
*
* @param watchService {@link WatchService}
*/
private void processWatchEvents(WatchService watchService) {
getWatchEventsLoopThreadPool().execute(() -> {
// WatchEvents Loop
while (true) {
WatchKey watchKey = null;
try {
watchKey = watchService.take();
if (watchKey.isValid()) {
for (WatchEvent event : watchKey.pollEvents()) {
WatchEvent.Kind kind = event.kind();
// configChangeType's key to match WatchEvent's Kind
ConfigChangeType configChangeType = CONFIG_CHANGE_TYPES_MAP.get(kind.name());
if (configChangeType != null) {
Path configDirectoryPath = (Path) watchKey.watchable();
Path currentPath = (Path) event.context();
Path configFilePath = configDirectoryPath.resolve(currentPath);
File configDirectory = configDirectoryPath.toFile();
executeMutually(configDirectory, () -> {
fireConfigChangeEvent(configDirectory, configFilePath.toFile(), configChangeType);
signalConfigDirectory(configDirectory);
return null;
});
}
}
}
} catch (Exception e) {
return;
} finally {
if (watchKey != null) {
// reset
watchKey.reset();
}
}
}
});
}
use of org.apache.dubbo.common.config.configcenter.ConfigChangeType 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));
}
}
Aggregations