Skip to content

Commit

Permalink
Delete unsed code (#36)
Browse files Browse the repository at this point in the history
Some code in TraceIdGenerator is not used, so delete those code.
  • Loading branch information
khotyn authored and guanchao-yang committed Jul 24, 2018
1 parent ae85cc0 commit 67df0d9
Showing 1 changed file with 3 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,20 @@
import com.alipay.common.tracer.core.utils.TracerUtils;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

public class TraceIdGenerator {

private static String IP_16 = "ffffffff";
private static String IP_int = "255255255255";

private static final String regex = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b";
private static final Pattern pattern = Pattern.compile(regex);
private static AtomicInteger count = new AtomicInteger(1000);
private static String IP_16 = "ffffffff";
private static AtomicInteger count = new AtomicInteger(1000);

static {
try {
String ipAddress = TracerUtils.getInetAddress();
if (ipAddress != null) {
IP_16 = getIP_16(ipAddress);
IP_int = getIP_int(ipAddress);
}
} catch (Throwable e) {
/**
/*
* empty catch block
*/
}
Expand All @@ -54,34 +48,6 @@ public static String generate() {
return getTraceId(IP_16, System.currentTimeMillis(), getNextId());
}

static String generate(String ip) {
if (ip != null && !ip.isEmpty() && validate(ip)) {
return getTraceId(getIP_16(ip), System.currentTimeMillis(), getNextId());
} else {
return generate();
}
}

static String generateIpv4Id() {
return IP_int;
}

static String generateIpv4Id(String ip) {
if (ip != null && !ip.isEmpty() && validate(ip)) {
return getIP_int(ip);
} else {
return IP_int;
}
}

private static boolean validate(String ip) {
try {
return pattern.matcher(ip).matches();
} catch (Throwable e) {
return false;
}
}

private static String getIP_16(String ip) {
String[] ips = ip.split("\\.");
StringBuilder sb = new StringBuilder();
Expand All @@ -97,10 +63,6 @@ private static String getIP_16(String ip) {
return sb.toString();
}

private static String getIP_int(String ip) {
return ip.replace(".", "");
}

private static int getNextId() {
for (;;) {
int current = count.get();
Expand Down

0 comments on commit 67df0d9

Please sign in to comment.