sunxi92 commented on a change in pull request #3761:
URL: https://github.com/apache/rocketmq/pull/3761#discussion_r790222836
##########
File path:
common/src/main/java/org/apache/rocketmq/common/protocol/body/ClusterAclVersionInfo.java
##########
@@ -19,13 +19,15 @@
import org.apache.rocketmq.common.DataVersion;
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
+import java.util.Map;
+
public class ClusterAclVersionInfo extends RemotingSerializable {
private String brokerName;
private String brokerAddr;
- private DataVersion aclConfigDataVersion;
Review comment:
done
##########
File path:
srvutil/src/main/java/org/apache/rocketmq/srvutil/AclFileWatchService.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.rocketmq.srvutil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.common.ServiceThread;
+import org.apache.rocketmq.common.UtilAll;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.MessageDigest;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AclFileWatchService extends ServiceThread {
+ private static final InternalLogger log =
InternalLoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME);
+
+ private final String aclPath;
+ private int aclFilesNum;
+ private final Map<String, String> fileCurrentHash;
+ private final AclFileWatchService.Listener listener;
+ private static final int WATCH_INTERVAL = 500;
+ private MessageDigest md = MessageDigest.getInstance("MD5");
+
+ public AclFileWatchService(String path, final AclFileWatchService.Listener
listener) throws Exception {
+ this.aclPath = path;
+ this.fileCurrentHash = new HashMap<>();
+ this.listener = listener;
+
+ File aclDir = new File(path);
+ String[] aclFileNames = aclDir.list();
+ this.aclFilesNum = aclFileNames.length;
+ for (int i = 0; i < aclFilesNum; i++) {
+ String aclFilePath = this.aclPath + aclFileNames[i];
+ if (StringUtils.isNotEmpty(aclFileNames[i]) && new
File(aclFilePath).exists()) {
+ this.fileCurrentHash.put(aclFilePath, hash(aclFilePath));
+ }
+ }
+
+ }
+
+ @Override
+ public String getServiceName() {
+ return "AclFileWatchService";
+ }
+
+ @Override
+ public void run() {
+ log.info(this.getServiceName() + " service started");
+
+ while (!this.isStopped()) {
+ try {
+ this.waitForRunning(WATCH_INTERVAL);
+
+ File aclDir = new File(aclPath);
+ File[] aclFiles = aclDir.listFiles();
+ int realAclFilesNum = aclFiles.length;
+
+ if (aclFilesNum != realAclFilesNum) {
+ log.info("aclFilesNum: " + aclFilesNum + "
realAclFilesNum: " + realAclFilesNum);
+ aclFilesNum = realAclFilesNum;
+ log.info("aclFilesNum: " + aclFilesNum + "
realAclFilesNum: " + realAclFilesNum);
+ listener.onFileNumChanged(aclPath);
+ } else {
+ for (int i = 0; i < aclFilesNum; i++) {
+ String fileName = aclFiles[i].getAbsolutePath();
+ String newHash = hash(fileName);
Review comment:
done
##########
File path:
srvutil/src/main/java/org/apache/rocketmq/srvutil/AclFileWatchService.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.rocketmq.srvutil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.common.ServiceThread;
+import org.apache.rocketmq.common.UtilAll;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.MessageDigest;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AclFileWatchService extends ServiceThread {
+ private static final InternalLogger log =
InternalLoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME);
+
+ private final String aclPath;
+ private int aclFilesNum;
+ private final Map<String, String> fileCurrentHash;
+ private final AclFileWatchService.Listener listener;
+ private static final int WATCH_INTERVAL = 500;
+ private MessageDigest md = MessageDigest.getInstance("MD5");
+
+ public AclFileWatchService(String path, final AclFileWatchService.Listener
listener) throws Exception {
+ this.aclPath = path;
+ this.fileCurrentHash = new HashMap<>();
+ this.listener = listener;
+
+ File aclDir = new File(path);
+ String[] aclFileNames = aclDir.list();
+ this.aclFilesNum = aclFileNames.length;
+ for (int i = 0; i < aclFilesNum; i++) {
+ String aclFilePath = this.aclPath + aclFileNames[i];
+ if (StringUtils.isNotEmpty(aclFileNames[i]) && new
File(aclFilePath).exists()) {
+ this.fileCurrentHash.put(aclFilePath, hash(aclFilePath));
+ }
+ }
+
+ }
+
+ @Override
+ public String getServiceName() {
+ return "AclFileWatchService";
+ }
+
+ @Override
+ public void run() {
+ log.info(this.getServiceName() + " service started");
+
+ while (!this.isStopped()) {
+ try {
+ this.waitForRunning(WATCH_INTERVAL);
+
+ File aclDir = new File(aclPath);
+ File[] aclFiles = aclDir.listFiles();
+ int realAclFilesNum = aclFiles.length;
+
+ if (aclFilesNum != realAclFilesNum) {
+ log.info("aclFilesNum: " + aclFilesNum + "
realAclFilesNum: " + realAclFilesNum);
+ aclFilesNum = realAclFilesNum;
+ log.info("aclFilesNum: " + aclFilesNum + "
realAclFilesNum: " + realAclFilesNum);
+ listener.onFileNumChanged(aclPath);
+ } else {
+ for (int i = 0; i < aclFilesNum; i++) {
+ String fileName = aclFiles[i].getAbsolutePath();
+ String newHash = hash(fileName);
+ if (!newHash.equals(fileCurrentHash.get(i))) {
Review comment:
done
##########
File path:
srvutil/src/main/java/org/apache/rocketmq/srvutil/AclFileWatchService.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.rocketmq.srvutil;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.common.ServiceThread;
+import org.apache.rocketmq.common.UtilAll;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.MessageDigest;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AclFileWatchService extends ServiceThread {
+ private static final InternalLogger log =
InternalLoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME);
+
+ private final String aclPath;
+ private int aclFilesNum;
+ private final Map<String, String> fileCurrentHash;
+ private final AclFileWatchService.Listener listener;
+ private static final int WATCH_INTERVAL = 500;
Review comment:
done
--
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]