Example usage for io.netty.resolver.dns DnsCache clear

List of usage examples for io.netty.resolver.dns DnsCache clear

Introduction

In this page you can find the example usage for io.netty.resolver.dns DnsCache clear.

Prototype

void clear();

Source Link

Document

Clears all the resolved addresses cached by this resolver.

Usage

From source file:io.vertx.core.dns.impl.fix.DnsNameResolver.java

License:Apache License

/**
 * Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
 *
 * @param eventLoop the {@link EventLoop} which will perform the communication with the DNS servers
 * @param channelFactory the {@link ChannelFactory} that will create a {@link DatagramChannel}
 * @param nameServerAddresses the addresses of the DNS server. For each DNS query, a new stream is created from
 *                            this to determine which DNS server should be contacted for the next retry in case
 *                            of failure.
 * @param resolveCache the DNS resolved entries cache
 * @param queryTimeoutMillis timeout of each DNS query in millis
 * @param resolvedAddressTypes list of the protocol families
 * @param recursionDesired if recursion desired flag must be set
 * @param maxQueriesPerResolve the maximum allowed number of DNS queries for a given name resolution
 * @param traceEnabled if trace is enabled
 * @param maxPayloadSize the capacity of the datagram packet buffer
 * @param optResourceEnabled if automatic inclusion of a optional records is enabled
 * @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
 * @param searchDomains TODO//w w w . j a v  a 2 s .com
 * @param ndots TODO
 */
public DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory,
        DnsServerAddresses nameServerAddresses, DnsCache resolveCache, long queryTimeoutMillis,
        InternetProtocolFamily[] resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve,
        boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled,
        HostsFileEntriesResolver hostsFileEntriesResolver, List<String> searchDomains, int ndots) {

    super(eventLoop);
    checkNotNull(channelFactory, "channelFactory");
    this.nameServerAddresses = checkNotNull(nameServerAddresses, "nameServerAddresses");
    this.queryTimeoutMillis = checkPositive(queryTimeoutMillis, "queryTimeoutMillis");
    this.resolvedAddressTypes = checkNonEmpty(resolvedAddressTypes, "resolvedAddressTypes");
    this.recursionDesired = recursionDesired;
    this.maxQueriesPerResolve = checkPositive(maxQueriesPerResolve, "maxQueriesPerResolve");
    this.traceEnabled = traceEnabled;
    this.maxPayloadSize = checkPositive(maxPayloadSize, "maxPayloadSize");
    this.optResourceEnabled = optResourceEnabled;
    this.hostsFileEntriesResolver = checkNotNull(hostsFileEntriesResolver, "hostsFileEntriesResolver");
    this.resolveCache = resolveCache;
    this.searchDomains = checkNotNull(searchDomains, "searchDomains");
    this.ndots = checkPositive(ndots, "ndots");

    Bootstrap b = new Bootstrap();
    b.group(executor());
    b.channelFactory(channelFactory);
    b.option(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true);
    final DnsResponseHandler responseHandler = new DnsResponseHandler(executor().<Channel>newPromise());
    b.handler(new ChannelInitializer<DatagramChannel>() {
        @Override
        protected void initChannel(DatagramChannel ch) throws Exception {
            ch.pipeline().addLast(DECODER, ENCODER, responseHandler);
        }
    });

    channelFuture = responseHandler.channelActivePromise;
    ch = (DatagramChannel) b.register().channel();
    ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(maxPayloadSize));

    ch.closeFuture().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            resolveCache.clear();
        }
    });
}