Make DnsAddressResolverGroup easier to extend

Motivation:

DnsAddressResolverGroup allows to override the newResolver(...) method to change the settings used by the user. We should better let the user override another method and always apply the InflightNameResolver.

Modifications:

- Mark newResolver(...) method as deprecated, we will make it private soon.
- Add newNameResolver(...) method that user can override.

Result:

Easier to extend DnsAddressResolverGroup
This commit is contained in:
Norman Maurer 2016-05-31 08:39:28 +02:00
parent dc816e9807
commit 9bd94ea021

View File

@ -74,6 +74,7 @@ public class DnsAddressResolverGroup extends AddressResolverGroup<InetSocketAddr
this.nameServerAddresses = nameServerAddresses; this.nameServerAddresses = nameServerAddresses;
} }
@SuppressWarnings("deprecation")
@Override @Override
protected final AddressResolver<InetSocketAddress> newResolver(EventExecutor executor) throws Exception { protected final AddressResolver<InetSocketAddress> newResolver(EventExecutor executor) throws Exception {
if (!(executor instanceof EventLoop)) { if (!(executor instanceof EventLoop)) {
@ -86,23 +87,34 @@ public class DnsAddressResolverGroup extends AddressResolverGroup<InetSocketAddr
} }
/** /**
* Creates a new {@link DnsNameResolver}. Override this method to create an alternative {@link DnsNameResolver} * @deprecated Override {@link #newNameResolver(EventLoop, ChannelFactory, InetSocketAddress, DnsServerAddresses)}.
* implementation or override the default configuration.
*/ */
@Deprecated
protected AddressResolver<InetSocketAddress> newResolver( protected AddressResolver<InetSocketAddress> newResolver(
EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory,
InetSocketAddress localAddress, DnsServerAddresses nameServerAddresses) throws Exception { InetSocketAddress localAddress, DnsServerAddresses nameServerAddresses) throws Exception {
final NameResolver<InetAddress> resolver = new InflightNameResolver<InetAddress>( final NameResolver<InetAddress> resolver = new InflightNameResolver<InetAddress>(
eventLoop, eventLoop,
new DnsNameResolverBuilder(eventLoop) newNameResolver(eventLoop, channelFactory, localAddress, nameServerAddresses),
.channelFactory(channelFactory)
.localAddress(localAddress)
.nameServerAddresses(nameServerAddresses)
.build(),
resolvesInProgress, resolvesInProgress,
resolveAllsInProgress); resolveAllsInProgress);
return new InetSocketAddressResolver(eventLoop, resolver); return new InetSocketAddressResolver(eventLoop, resolver);
} }
/**
* Creates a new {@link NameResolver}. Override this method to create an alternative {@link NameResolver}
* implementation or override the default configuration.
*/
protected NameResolver<InetAddress> newNameResolver(EventLoop eventLoop,
ChannelFactory<? extends DatagramChannel> channelFactory,
InetSocketAddress localAddress,
DnsServerAddresses nameServerAddresses) throws Exception {
return new DnsNameResolverBuilder(eventLoop)
.channelFactory(channelFactory)
.localAddress(localAddress)
.nameServerAddresses(nameServerAddresses)
.build();
}
} }