1. 修复在极端情况下UserId变化不会触发重新分配
This commit is contained in:
parent
61e402a401
commit
55c2d84bef
|
|
@ -38,7 +38,7 @@ public class AlarmProcessServer {
|
|||
processThreads.add(tmpThread);
|
||||
}
|
||||
logger.info("Successfully launched {} processing threads.", Config.Server.PROCESS_THREAD_SIZE);
|
||||
new UserInfoInspectThread().start();
|
||||
new UserNumberInspectThread().start();
|
||||
logger.info("Successfully launched the thread that inspect the number of user");
|
||||
logger.info("Alarm process server successfully started.");
|
||||
while (true) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ai.cloud.skywalking.alarm;
|
|||
|
||||
import com.ai.cloud.skywalking.alarm.conf.Config;
|
||||
import com.ai.cloud.skywalking.alarm.dao.AlarmMessageDao;
|
||||
import com.ai.cloud.skywalking.alarm.util.MD5Encryption;
|
||||
import com.ai.cloud.skywalking.alarm.util.ZKUtil;
|
||||
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -10,13 +11,13 @@ import org.apache.logging.log4j.Logger;
|
|||
import java.sql.SQLException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class UserInfoInspectThread extends Thread {
|
||||
public class UserNumberInspectThread extends Thread {
|
||||
|
||||
private boolean isInspector = false;
|
||||
private InterProcessMutex inspectorLock = new InterProcessMutex(ZKUtil.getZkClient(),
|
||||
Config.ZKPath.INSPECTOR_LOCK_PATH);
|
||||
private int userHashCode;
|
||||
private Logger logger = LogManager.getLogger(UserInfoInspectThread.class);
|
||||
private String userIdsEncryptedStr;
|
||||
private Logger logger = LogManager.getLogger(UserNumberInspectThread.class);
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
|
|
@ -28,7 +29,7 @@ public class UserInfoInspectThread extends Thread {
|
|||
}
|
||||
|
||||
isInspector = true;
|
||||
userHashCode = AlarmMessageDao.selectAllUserIds().toString().hashCode();
|
||||
userIdsEncryptedStr = MD5Encryption.getEncryption(AlarmMessageDao.selectAllUserIds().toString());
|
||||
}
|
||||
|
||||
// 判断上次用户数量是否发生变化
|
||||
|
|
@ -46,11 +47,11 @@ public class UserInfoInspectThread extends Thread {
|
|||
}
|
||||
|
||||
private boolean checkUserNumber() throws SQLException {
|
||||
int currentUserHashCode = AlarmMessageDao.selectAllUserIds().toString().hashCode();
|
||||
if (userHashCode == currentUserHashCode) {
|
||||
String currentUserIdsEncryptedStr = MD5Encryption.getEncryption(AlarmMessageDao.selectAllUserIds().toString());
|
||||
if (userIdsEncryptedStr == currentUserIdsEncryptedStr) {
|
||||
return false;
|
||||
}
|
||||
userHashCode = currentUserHashCode;
|
||||
userIdsEncryptedStr = currentUserIdsEncryptedStr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.ai.cloud.skywalking.alarm.util;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class MD5Encryption {
|
||||
private static Logger logger = LogManager.getLogger(DBConnectUtil.class);
|
||||
|
||||
private MD5Encryption() {
|
||||
}
|
||||
|
||||
public static String getEncryption(String originString) {
|
||||
String result = null;
|
||||
if (originString != null) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte bytes[] = md.digest(originString.getBytes());
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
String str = Integer.toHexString(bytes[i] & 0xFF);
|
||||
if (str.length() == 1) {
|
||||
str += "F";
|
||||
}
|
||||
result += str;
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
logger.error("No such algorithmException.", e);
|
||||
return originString;
|
||||
}
|
||||
}
|
||||
return result.toUpperCase();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue