2014-09-19 15:36:32 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2014 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package io.netty.resolver.dns;
|
|
|
|
|
|
|
|
import io.netty.channel.ChannelFactory;
|
|
|
|
import io.netty.channel.EventLoop;
|
|
|
|
import io.netty.channel.ReflectiveChannelFactory;
|
|
|
|
import io.netty.channel.socket.DatagramChannel;
|
|
|
|
import io.netty.resolver.NameResolver;
|
|
|
|
import io.netty.resolver.NameResolverGroup;
|
|
|
|
import io.netty.util.concurrent.EventExecutor;
|
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
2015-12-07 10:43:32 +01:00
|
|
|
import static io.netty.resolver.dns.DnsNameResolver.ANY_LOCAL_ADDR;
|
2014-09-19 15:36:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A {@link NameResolverGroup} of {@link DnsNameResolver}s.
|
|
|
|
*/
|
2015-12-07 10:43:32 +01:00
|
|
|
public class DnsNameResolverGroup extends NameResolverGroup<InetSocketAddress> {
|
2014-09-19 15:36:32 +02:00
|
|
|
|
|
|
|
private final ChannelFactory<? extends DatagramChannel> channelFactory;
|
|
|
|
private final InetSocketAddress localAddress;
|
2015-08-19 04:51:15 +02:00
|
|
|
private final DnsServerAddresses nameServerAddresses;
|
2014-09-19 15:36:32 +02:00
|
|
|
|
|
|
|
public DnsNameResolverGroup(
|
2015-08-19 04:51:15 +02:00
|
|
|
Class<? extends DatagramChannel> channelType, DnsServerAddresses nameServerAddresses) {
|
2014-09-19 15:36:32 +02:00
|
|
|
this(channelType, ANY_LOCAL_ADDR, nameServerAddresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
public DnsNameResolverGroup(
|
|
|
|
Class<? extends DatagramChannel> channelType,
|
2015-08-19 04:51:15 +02:00
|
|
|
InetSocketAddress localAddress, DnsServerAddresses nameServerAddresses) {
|
2014-09-19 15:36:32 +02:00
|
|
|
this(new ReflectiveChannelFactory<DatagramChannel>(channelType), localAddress, nameServerAddresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
public DnsNameResolverGroup(
|
2015-08-19 04:51:15 +02:00
|
|
|
ChannelFactory<? extends DatagramChannel> channelFactory, DnsServerAddresses nameServerAddresses) {
|
2014-09-19 15:36:32 +02:00
|
|
|
this(channelFactory, ANY_LOCAL_ADDR, nameServerAddresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
public DnsNameResolverGroup(
|
|
|
|
ChannelFactory<? extends DatagramChannel> channelFactory,
|
2015-08-19 04:51:15 +02:00
|
|
|
InetSocketAddress localAddress, DnsServerAddresses nameServerAddresses) {
|
2014-09-19 15:36:32 +02:00
|
|
|
this.channelFactory = channelFactory;
|
|
|
|
this.localAddress = localAddress;
|
|
|
|
this.nameServerAddresses = nameServerAddresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-07 10:43:32 +01:00
|
|
|
protected final NameResolver<InetSocketAddress> newResolver(EventExecutor executor) throws Exception {
|
2014-09-19 15:36:32 +02:00
|
|
|
if (!(executor instanceof EventLoop)) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"unsupported executor type: " + StringUtil.simpleClassName(executor) +
|
|
|
|
" (expected: " + StringUtil.simpleClassName(EventLoop.class));
|
|
|
|
}
|
|
|
|
|
2015-12-07 10:43:32 +01:00
|
|
|
return newResolver((EventLoop) executor, channelFactory, localAddress, nameServerAddresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link DnsNameResolver}. Override this method to create an alternative {@link DnsNameResolver}
|
|
|
|
* implementation or override the default configuration.
|
|
|
|
*/
|
|
|
|
protected DnsNameResolver newResolver(
|
|
|
|
EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory,
|
|
|
|
InetSocketAddress localAddress, DnsServerAddresses nameServerAddresses) throws Exception {
|
|
|
|
|
|
|
|
return new DnsNameResolver(
|
|
|
|
eventLoop, channelFactory, localAddress, nameServerAddresses);
|
2014-09-19 15:36:32 +02:00
|
|
|
}
|
|
|
|
}
|