Search in sources :

Example 1 with IntObjectHashMap

use of io.netty.util.collection.IntObjectHashMap in project netty by netty.

the class DnsQueryContextManager method getOrCreateContextMap.

private IntObjectMap<DnsQueryContext> getOrCreateContextMap(InetSocketAddress nameServerAddr) {
    synchronized (map) {
        final IntObjectMap<DnsQueryContext> contexts = map.get(nameServerAddr);
        if (contexts != null) {
            return contexts;
        }
        final IntObjectMap<DnsQueryContext> newContexts = new IntObjectHashMap<DnsQueryContext>();
        final InetAddress a = nameServerAddr.getAddress();
        final int port = nameServerAddr.getPort();
        map.put(nameServerAddr, newContexts);
        if (a instanceof Inet4Address) {
            // Also add the mapping for the IPv4-compatible IPv6 address.
            final Inet4Address a4 = (Inet4Address) a;
            if (a4.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST6, port), newContexts);
            } else {
                map.put(new InetSocketAddress(toCompatAddress(a4), port), newContexts);
            }
        } else if (a instanceof Inet6Address) {
            // Also add the mapping for the IPv4 address if this IPv6 address is compatible.
            final Inet6Address a6 = (Inet6Address) a;
            if (a6.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST4, port), newContexts);
            } else if (a6.isIPv4CompatibleAddress()) {
                map.put(new InetSocketAddress(toIPv4Address(a6), port), newContexts);
            }
        }
        return newContexts;
    }
}
Also used : Inet4Address(java.net.Inet4Address) IntObjectHashMap(io.netty.util.collection.IntObjectHashMap) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

IntObjectHashMap (io.netty.util.collection.IntObjectHashMap)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1