Pil0tXia commented on code in PR #4507:
URL: https://github.com/apache/eventmesh/pull/4507#discussion_r1375256694


##########
eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java:
##########
@@ -59,13 +60,27 @@ public FileWebHookConfigOperation(final Properties 
properties) throws FileNotFou
         this.webHookFilePath = webHookFilePath;
     }
 
+    public static boolean writeToFile(final File webhookConfigFile, final 
WebHookConfig webHookConfig) {
+        // Wait for the previous cacheInit to complete in case of concurrency
+        synchronized (SharedLatchHolder.lock) {
+            try (FileOutputStream fos = new 
FileOutputStream(webhookConfigFile);
+                BufferedWriter bw = new BufferedWriter(new 
OutputStreamWriter(fos, StandardCharsets.UTF_8))) {
+                // Lock this file to prevent concurrent modification and it 
will be automatically unlocked when fos closes
+                fos.getChannel().lock();
+                
bw.write(Objects.requireNonNull(JsonUtils.toJSONString(webHookConfig)));
+            } catch (IOException e) {
+                LogUtils.error(log, "write webhookConfig {} to file error", 
webHookConfig.getCallbackPath());
+                return false;
+            }
+            return true;
+        }
+    }
+
     @Override

Review Comment:
   Method sequence problem here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to