Pil0tXia commented on code in PR #4344: URL: https://github.com/apache/eventmesh/pull/4344#discussion_r1296674504
########## eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/common/SharedLatchHolder.java: ########## @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.webhook.api.common; + +import java.util.concurrent.CountDownLatch; + +public class SharedLatchHolder { + public static CountDownLatch latch = new CountDownLatch(1); Review Comment: Reasonable and done. Don't worry too much about it. We have reviewers, and we can also add comments in similar places to make convention outweigh implementation. ########## eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java: ########## @@ -173,18 +175,25 @@ private WebHookConfig getWebHookConfigFromFile(final File webhookConfigFile) { } public static boolean writeToFile(final File webhookConfigFile, final WebHookConfig webHookConfig) { - try (FileOutputStream fos = new FileOutputStream(webhookConfigFile); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8))) { - // lock this file, and will auto release after fos close - fos.getChannel().lock(); - bw.write(Objects.requireNonNull(JsonUtils.toJSONString(webHookConfig))); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("write webhookConfig {} to file error", webHookConfig.getCallbackPath()); + // Wait for the previous cacheInit to complete and ensure the atomicity of countDown in case of concurrency + synchronized (SharedLatchHolder.lock) { + // Reset latch count + SharedLatchHolder.latch = new CountDownLatch(1); Review Comment: Reasonable. The ENTRY_MODIFY event is triggered inside `writeToFile` and `cacheInit` will wait for write completion. -- 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]
