You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/09/21 07:04:14 UTC
[incubator-eventmesh] branch master updated: [ISSUE #1356] update WebhookFileListener for operating the webhook config
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new a796f4bc [ISSUE #1356] update WebhookFileListener for operating the webhook config
new 49a32d71 Merge pull request #1357 from githublaohu/webhook-repair5
a796f4bc is described below
commit a796f4bc7eeae167fb34d4bda2f9622bdbfdfbc7
Author: githublaohu <Ni...@989898>
AuthorDate: Wed Sep 21 14:25:53 2022 +0800
[ISSUE #1356] update WebhookFileListener for operating the webhook config
---
.../receive/storage/WebhookFileListener.java | 35 +++++++++++++---------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java
index 1c020302..2165e70f 100644
--- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java
+++ b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java
@@ -49,16 +49,12 @@ import org.slf4j.LoggerFactory;
public class WebhookFileListener {
+ private final Set<String> pathSet = new LinkedHashSet<>(); // monitored subdirectory
+ private final Map<WatchKey, String> watchKeyPathMap = new HashMap<>(); // WatchKey's path
public Logger logger = LoggerFactory.getLogger(this.getClass());
-
private String filePath;
-
private Map<String, WebHookConfig> cacheWebHookConfig;
- private final Set<String> pathSet = new LinkedHashSet<>(); // monitored subdirectory
-
- private final Map<WatchKey, String> watchKeyPathMap = new HashMap<>(); // WatchKey's path
-
public WebhookFileListener() {
}
@@ -113,7 +109,11 @@ public class WebhookFileListener {
logger.error("cacheInit failed", e);
}
WebHookConfig webHookConfig = JsonUtils.deserialize(fileContent.toString(), WebHookConfig.class);
- cacheWebHookConfig.put(webHookConfig.getCallbackPath(), webHookConfig);
+ cacheWebHookConfig.put(webhookConfigFile.getName(), webHookConfig);
+ }
+
+ public void deleteConfig(File webhookConfigFile) {
+ cacheWebHookConfig.remove(webhookConfigFile.getName());
}
/**
@@ -155,18 +155,25 @@ public class WebhookFileListener {
for (WatchEvent<?> event : key.pollEvents()) {
String flashPath = watchKeyPathMap.get(key);
// manufacturer change
- if (flashPath.equals(filePath)) {
- if (ENTRY_CREATE == event.kind()) {
+ String path = flashPath + "/" + event.context();
+ File file = new File(path);
+ if (ENTRY_CREATE == event.kind() || ENTRY_MODIFY == event.kind()) {
+ if (file.isFile()) {
+ cacheInit(file);
+ } else {
try {
- key = Paths.get(filePath + WebHookOperationConstant.FILE_SEPARATOR + event.context())
- .register(service, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE);
+ key = Paths.get(path).register(service, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE);
+ watchKeyPathMap.put(key, path);
} catch (IOException e) {
logger.error("registerWatchKey failed", e);
}
- watchKeyPathMap.put(key, filePath + WebHookOperationConstant.FILE_SEPARATOR + event.context());
}
- } else { // config change
- cacheInit(new File(flashPath + WebHookOperationConstant.FILE_SEPARATOR + event.context()));
+ } else if (ENTRY_DELETE == event.kind()) {
+ if (file.isDirectory()) {
+ watchKeyPathMap.remove(key);
+ } else {
+ deleteConfig(file);
+ }
}
}
if (!key.reset()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org