-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/io/lettuce/core/resource/AddressResolverGroupProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.lettuce.core.resource; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import io.lettuce.core.Transports; | ||
import io.netty.channel.socket.SocketChannel; | ||
import io.netty.resolver.AddressResolverGroup; | ||
import io.netty.resolver.DefaultAddressResolverGroup; | ||
import io.netty.resolver.dns.DnsAddressResolverGroup; | ||
import io.netty.resolver.dns.DnsNameResolverBuilder; | ||
import io.netty.util.internal.logging.InternalLogger; | ||
import io.netty.util.internal.logging.InternalLoggerFactory; | ||
|
||
/** | ||
* Wraps and provides {@link AddressResolverGroup} classes. This is to protect the user from {@link ClassNotFoundException}'s | ||
* caused by the absence of the {@literal netty-dns-resolver} library during runtime. This class will be deleted when | ||
* {@literal netty-dns-resolver} becomes mandatory. Internal API. | ||
* | ||
* @author Yohei Ueki | ||
* @since xxx | ||
*/ | ||
class AddressResolverGroupProvider { | ||
|
||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(AddressResolverGroupProvider.class); | ||
|
||
private static final AddressResolverGroup<?> ADDRESS_RESOLVER_GROUP; | ||
|
||
static { | ||
boolean dnsResolverAvailable; | ||
try { | ||
Class.forName("io.netty.resolver.dns.DnsAddressResolverGroup"); | ||
dnsResolverAvailable = true; | ||
} catch (ClassNotFoundException e) { | ||
dnsResolverAvailable = false; | ||
} | ||
|
||
// create addressResolverGroup instance via Supplier to avoid NoClassDefFoundError. | ||
Supplier<AddressResolverGroup<?>> supplier; | ||
if (dnsResolverAvailable) { | ||
logger.debug("Starting with netty's non-blocking DNS resolver library"); | ||
supplier = AddressResolverGroupProvider::defaultDnsAddressResolverGroup; | ||
} else { | ||
logger.debug("Starting without optional netty's non-blocking DNS resolver library"); | ||
supplier = () -> DefaultAddressResolverGroup.INSTANCE; | ||
} | ||
ADDRESS_RESOLVER_GROUP = supplier.get(); | ||
} | ||
|
||
/** | ||
* Returns the {@link AddressResolverGroup} for dns resolution. | ||
* | ||
* @return the {@link DnsAddressResolverGroup} if {@literal netty-dns-resolver} is available, otherwise return | ||
* {@link DefaultAddressResolverGroup#INSTANCE}. | ||
* @since xxx | ||
*/ | ||
static AddressResolverGroup<?> addressResolverGroup() { | ||
return ADDRESS_RESOLVER_GROUP; | ||
} | ||
|
||
private static DnsAddressResolverGroup defaultDnsAddressResolverGroup() { | ||
return new DnsAddressResolverGroup(new DnsNameResolverBuilder().channelType(Transports.datagramChannelClass()) | ||
.socketChannelType(Transports.socketChannelClass().asSubclass(SocketChannel.class))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters