List of usage examples for io.netty.resolver.dns DnsNameResolverBuilder channelFactory
ChannelFactory channelFactory
To view the source code for io.netty.resolver.dns DnsNameResolverBuilder channelFactory.
Click Source Link
From source file:chat.viska.xmpp.Connection.java
License:Apache License
private static Single<List<DnsRecord>> lookupDnsUsingNetty(final String query, final DnsRecordType type, @Nullable final Iterable<String> dns) { final NioEventLoopGroup threadPool = new NioEventLoopGroup(); final DnsNameResolverBuilder builder = new DnsNameResolverBuilder(threadPool.next()); builder.channelFactory(new ReflectiveChannelFactory<>(NioDatagramChannel.class)); builder.decodeIdn(true);//from w w w.ja va 2 s. c o m if (dns != null) { builder.searchDomains(dns); } return Single.fromFuture(builder.build().query(new DefaultDnsQuestion(query, type))) .map(AddressedEnvelope::content).map(message -> { final int recordsSize = message.count(DnsSection.ANSWER); final List<DnsRecord> records = new ArrayList<>(recordsSize); for (int it = 0; it < recordsSize; ++it) { records.add(message.recordAt(DnsSection.ANSWER, it)); } return records; }).doFinally(threadPool::shutdownGracefully); }
From source file:io.vertx.core.impl.HostnameResolver.java
License:Open Source License
public HostnameResolver(VertxImpl vertx, HostnameResolverOptions options) { DnsNameResolverBuilder builder = new DnsNameResolverBuilder(vertx.createEventLoopContext(null, null, new JsonObject(), Thread.currentThread().getContextClassLoader()).nettyEventLoop()); builder.channelFactory(NioDatagramChannel::new); if (options != null) { List<String> dnsServers = options.getServers(); if (dnsServers != null && dnsServers.size() > 0) { List<InetSocketAddress> serverList = new ArrayList<>(); for (String dnsServer : dnsServers) { int sep = dnsServer.indexOf(':'); String ipAddress; int port; if (sep != -1) { ipAddress = dnsServer.substring(0, sep); port = Integer.parseInt(dnsServer.substring(sep + 1)); } else { ipAddress = dnsServer; port = 53;// w w w. j a v a 2s . c o m } try { serverList.add(new InetSocketAddress( InetAddress.getByAddress(NetUtil.createByteArrayFromIpAddressString(ipAddress)), port)); } catch (UnknownHostException e) { throw new VertxException(e); } } DnsServerAddresses nameServerAddresses = DnsServerAddresses.sequential(serverList); builder.nameServerAddresses(nameServerAddresses); } builder.optResourceEnabled(options.isOptResourceEnabled()); builder.ttl(options.getCacheMinTimeToLive(), options.getCacheMaxTimeToLive()); builder.negativeTtl(options.getCacheNegativeTimeToLive()); builder.queryTimeoutMillis(options.getQueryTimeout()); builder.maxQueriesPerResolve(options.getMaxQueries()); builder.recursionDesired(options.getRdFlag()); } this.resolver = builder.build(); this.vertx = vertx; }