|
|
@ -59,7 +59,7 @@ public class Domains {
|
|
|
|
// a dns cache
|
|
|
|
// a dns cache
|
|
|
|
private static final ARC<String, InetAddress> NAME_CACHE_HIT = new ConcurrentARC<String, InetAddress>(MAX_NAME_CACHE_HIT_SIZE, CONCURRENCY_LEVEL);
|
|
|
|
private static final ARC<String, InetAddress> NAME_CACHE_HIT = new ConcurrentARC<String, InetAddress>(MAX_NAME_CACHE_HIT_SIZE, CONCURRENCY_LEVEL);
|
|
|
|
private static final ARC<String, String> NAME_CACHE_MISS = new ConcurrentARC<String, String>(MAX_NAME_CACHE_MISS_SIZE, CONCURRENCY_LEVEL);
|
|
|
|
private static final ARC<String, String> NAME_CACHE_MISS = new ConcurrentARC<String, String>(MAX_NAME_CACHE_MISS_SIZE, CONCURRENCY_LEVEL);
|
|
|
|
//private static final ConcurrentHashMap<String, Object> LOOKUP_SYNC = new ConcurrentHashMap<String, Object>();
|
|
|
|
private static final ConcurrentHashMap<String, Object> LOOKUP_SYNC = new ConcurrentHashMap<String, Object>(100, 0.75f, Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
private static List<Pattern> nameCacheNoCachingPatterns = Collections.synchronizedList(new LinkedList<Pattern>());
|
|
|
|
private static List<Pattern> nameCacheNoCachingPatterns = Collections.synchronizedList(new LinkedList<Pattern>());
|
|
|
|
private static final List<Pattern> LOCALHOST_PATTERNS = makePatterns(LOCAL_PATTERNS);
|
|
|
|
private static final List<Pattern> LOCALHOST_PATTERNS = makePatterns(LOCAL_PATTERNS);
|
|
|
|
public static long cacheHit_Hit = 0, cacheHit_Miss = 0, cacheHit_Insert = 0; // for statistics only; do not write
|
|
|
|
public static long cacheHit_Hit = 0, cacheHit_Miss = 0, cacheHit_Insert = 0; // for statistics only; do not write
|
|
|
@ -565,39 +565,40 @@ public class Domains {
|
|
|
|
cacheMiss_Miss++;
|
|
|
|
cacheMiss_Miss++;
|
|
|
|
|
|
|
|
|
|
|
|
// call dnsResolveNetBased(host) using concurrency to interrupt execution in case of a time-out
|
|
|
|
// call dnsResolveNetBased(host) using concurrency to interrupt execution in case of a time-out
|
|
|
|
//final Object sync_obj_new = new Object();
|
|
|
|
final Object sync_obj_new = new Object();
|
|
|
|
//Object sync_obj = LOOKUP_SYNC.putIfAbsent(host, sync_obj_new);
|
|
|
|
Object sync_obj = LOOKUP_SYNC.putIfAbsent(host, sync_obj_new);
|
|
|
|
//if (sync_obj == null) sync_obj = sync_obj_new;
|
|
|
|
if (sync_obj == null) sync_obj = sync_obj_new;
|
|
|
|
//synchronized (sync_obj) {
|
|
|
|
synchronized (sync_obj) {
|
|
|
|
// now look again if the host is in the cache where it may be meanwhile because of the synchronization
|
|
|
|
// now look again if the host is in the cache where it may be meanwhile because of the synchronization
|
|
|
|
/*
|
|
|
|
|
|
|
|
ip = NAME_CACHE_HIT.get(host);
|
|
|
|
ip = NAME_CACHE_HIT.get(host);
|
|
|
|
if (ip != null) {
|
|
|
|
if (ip != null) {
|
|
|
|
//System.out.println("DNSLOOKUP-CACHE-HIT(SYNC) " + host);
|
|
|
|
//System.out.println("DNSLOOKUP-CACHE-HIT(SYNC) " + host);
|
|
|
|
//LOOKUP_SYNC.remove(host);
|
|
|
|
LOOKUP_SYNC.remove(host);
|
|
|
|
cacheHit_Hit++;
|
|
|
|
cacheHit_Hit++;
|
|
|
|
return ip;
|
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cacheHit_Miss++;
|
|
|
|
cacheHit_Miss++;
|
|
|
|
if (NAME_CACHE_MISS.containsKey(host)) {
|
|
|
|
if (NAME_CACHE_MISS.containsKey(host)) {
|
|
|
|
//System.out.println("DNSLOOKUP-CACHE-MISS(SYNC) " + host);
|
|
|
|
//System.out.println("DNSLOOKUP-CACHE-MISS(SYNC) " + host);
|
|
|
|
//LOOKUP_SYNC.remove(host);
|
|
|
|
LOOKUP_SYNC.remove(host);
|
|
|
|
cacheMiss_Hit++;
|
|
|
|
cacheMiss_Hit++;
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cacheMiss_Miss++;
|
|
|
|
cacheMiss_Miss++;
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// do the dns lookup on the dns server
|
|
|
|
// do the dns lookup on the dns server
|
|
|
|
//if (!matchesList(host, nameCacheNoCachingPatterns)) System.out.println("DNSLOOKUP " + host);
|
|
|
|
//if (!matchesList(host, nameCacheNoCachingPatterns)) System.out.println("DNSLOOKUP " + host);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//System.out.println("DNSLOOKUP-*LOOKUP* " + host);
|
|
|
|
//final long t = System.currentTimeMillis();
|
|
|
|
ip = InetAddress.getByName(host); //TimeoutRequest.getByName(host, 1000); // this makes the DNS request to backbone
|
|
|
|
ip = InetAddress.getByName(host); //TimeoutRequest.getByName(host, 1000); // this makes the DNS request to backbone
|
|
|
|
|
|
|
|
//.out.println("DNSLOOKUP-*LOOKUP* " + host + ", time = " + (System.currentTimeMillis() - t) + "ms");
|
|
|
|
} catch (final UnknownHostException e) {
|
|
|
|
} catch (final UnknownHostException e) {
|
|
|
|
// add new entries
|
|
|
|
// add new entries
|
|
|
|
NAME_CACHE_MISS.insertIfAbsent(host, PRESENT);
|
|
|
|
NAME_CACHE_MISS.insertIfAbsent(host, PRESENT);
|
|
|
|
cacheMiss_Insert++;
|
|
|
|
cacheMiss_Insert++;
|
|
|
|
//LOOKUP_SYNC.remove(host);
|
|
|
|
LOOKUP_SYNC.remove(host);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -621,9 +622,9 @@ public class Domains {
|
|
|
|
} catch (final IOException e) {}
|
|
|
|
} catch (final IOException e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//LOOKUP_SYNC.remove(host);
|
|
|
|
LOOKUP_SYNC.remove(host);
|
|
|
|
return ip;
|
|
|
|
return ip;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private final static Pattern dotPattern = Pattern.compile("\\.");
|
|
|
|
private final static Pattern dotPattern = Pattern.compile("\\.");
|
|
|
|