forked from KNEMC/KLALB
KLALB V3.6.0 写了一半
This commit is contained in:
@@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@@ -14,6 +15,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
|
||||
public class KLALBUtils {
|
||||
public static Inet6Address uuidToIP(UUID uuid) {
|
||||
@@ -36,6 +38,18 @@ public class KLALBUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static IPv6Address randomKLALBIPv6Address() {
|
||||
SecureRandom sc = new SecureRandom();
|
||||
byte[] v = new byte[16];
|
||||
sc.nextBytes(v);
|
||||
v[0] = (byte) 0x24;
|
||||
v[1] = (byte) 0x86;
|
||||
v[2] = 0x00;
|
||||
v[3] = 0x01;
|
||||
return IPv6Address.valueOf(v);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(uuidToIP(new UUID(-1,-1)));
|
||||
}
|
||||
@@ -366,6 +380,37 @@ public static String parseAbbrIPv6(String IPv6Str) {
|
||||
}
|
||||
return join(arr, ":").replaceAll(":{2,}", "::");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class UUIDGenarator{
|
||||
|
||||
private final long id;
|
||||
private long counter=0;
|
||||
private UUID randUUID=UUID.randomUUID();
|
||||
private long time=System.nanoTime();
|
||||
private static final long INTERVAL=1000000L;
|
||||
public UUIDGenarator(long threadId) {
|
||||
this.id=threadId;
|
||||
}
|
||||
public UUID genarateUUID() {
|
||||
long curr=System.nanoTime();
|
||||
if(curr-time>INTERVAL) {
|
||||
time=curr;
|
||||
randUUID=UUID.randomUUID();
|
||||
}
|
||||
long h=randUUID.getMostSignificantBits()^id;
|
||||
long l=randUUID.getLeastSignificantBits()^counter;
|
||||
|
||||
UUID ret=new UUID(h, l);
|
||||
counter++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
private static ThreadLocal<UUIDGenarator> gens=ThreadLocal.withInitial(()->{
|
||||
return new UUIDGenarator(Thread.currentThread().threadId());
|
||||
});
|
||||
public static UUID createGlobalUUID() {
|
||||
//return UUID.randomUUID();
|
||||
return gens.get().genarateUUID();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user