提取正则表达式为成员变量,利用Java预编译功能使得匹配更高效

This commit is contained in:
wanglihui
2020-07-03 17:52:56 +08:00
parent 2d543b3df9
commit 46a21fb308

View File

@@ -28,6 +28,8 @@ public class BaseClickhouseData {
private static HashMap<Integer, HashMap<String, HashMap<String, BaseEdgeDocument>>> eFqdnAddressIpMap = new HashMap<>();
private static HashMap<Integer, HashMap<String, HashMap<String, BaseEdgeDocument>>> eIpVisitFqdnMap = new HashMap<>();
private static Pattern pattern = Pattern.compile("^[\\d]*$");
private static long[] getTimeLimit() {
long maxTime = System.currentTimeMillis() / 1000;
long minTime = maxTime - 3600;
@@ -237,36 +239,13 @@ public class BaseClickhouseData {
}
}
@Deprecated
private static String commonSchemaGetFqdn(String commonSchemaType, ResultSet resultSet) {
String vFqdn = "";
try {
switch (commonSchemaType) {
case "HTTP":
vFqdn = resultSet.getString("http_host");
break;
case "SSL":
vFqdn = resultSet.getString("ssl_sni");
break;
default:
LOG.warn("不支持该类型common_schema_type" + commonSchemaType);
}
} catch (Exception e) {
LOG.error(e.getMessage());
}
if (isDomain(vFqdn)) {
return vFqdn;
}
return "";
}
private static boolean isDomain(String fqdn) {
try {
String[] fqdnArr = fqdn.split("\\.");
if (fqdnArr.length < 4 || fqdnArr.length > 4) {
return true;
}
Pattern pattern = Pattern.compile("^[\\d]*$");
for (String f : fqdnArr) {
if (pattern.matcher(f).matches()) {
int i = Integer.parseInt(f);
@@ -323,4 +302,27 @@ public class BaseClickhouseData {
return "SELECT * FROM ((" + sslSql + ") UNION ALL (" + httpSql + "))WHERE FQDN != ''";
}
@Deprecated
private static String commonSchemaGetFqdn(String commonSchemaType, ResultSet resultSet) {
String vFqdn = "";
try {
switch (commonSchemaType) {
case "HTTP":
vFqdn = resultSet.getString("http_host");
break;
case "SSL":
vFqdn = resultSet.getString("ssl_sni");
break;
default:
LOG.warn("不支持该类型common_schema_type" + commonSchemaType);
}
} catch (Exception e) {
LOG.error(e.getMessage());
}
if (isDomain(vFqdn)) {
return vFqdn;
}
return "";
}
}