View Javadoc
1   /*
2    * Copyright 2020 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.testsuite.svm.client;
17  
18  import io.netty.channel.EventLoopGroup;
19  import io.netty.channel.MultiThreadIoEventLoopGroup;
20  import io.netty.channel.nio.NioIoHandler;
21  import io.netty.channel.socket.nio.NioDatagramChannel;
22  import io.netty.resolver.AddressResolver;
23  import io.netty.resolver.dns.DnsAddressResolverGroup;
24  import io.netty.resolver.dns.DnsServerAddressStreamProviders;
25  import io.netty.util.concurrent.DefaultThreadFactory;
26  
27  import java.net.InetSocketAddress;
28  
29  /**
30   * A client that uses netty-dns and gets compiled to a native image.
31   */
32  public final class DnsNativeClient {
33      /**
34       * Main entry point (not instantiable)
35       */
36      private DnsNativeClient() {
37      }
38  
39      public static void main(String[] args) throws Exception {
40          EventLoopGroup group = new MultiThreadIoEventLoopGroup(
41                  1, new DefaultThreadFactory("netty"), NioIoHandler.newFactory());
42  
43          DnsAddressResolverGroup resolverGroup = new DnsAddressResolverGroup(NioDatagramChannel.class,
44                  DnsServerAddressStreamProviders.platformDefault());
45          AddressResolver<InetSocketAddress> resolver = resolverGroup.getResolver(group.next());
46          System.out.println(resolver);
47  
48          resolver.close();
49          group.shutdownGracefully().get();
50      }
51  }