-
Notifications
You must be signed in to change notification settings - Fork 882
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now it's possible to configure NettyNioAsyncHttpClient in order to use a
non blocking DNS resolver.
- Loading branch information
1 parent
b4f070b
commit 489a66b
Showing
22 changed files
with
928 additions
and
219 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"category": "Netty NIO HTTP Client", | ||
"contributor": "martinKindall", | ||
"type": "bugfix", | ||
"description": "By default, Netty threads are blocked during dns resolution, namely InetAddress.getByName is used under the hood. Now, there's an option to configure the NettyNioAsyncHttpClient in order to use a non blocking dns resolution strategy." | ||
} |
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
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
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
63 changes: 63 additions & 0 deletions
63
...lient/src/main/java/software/amazon/awssdk/http/nio/netty/internal/DnsResolverLoader.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,63 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.nio.netty.internal; | ||
|
||
import io.netty.channel.ChannelFactory; | ||
import io.netty.channel.socket.DatagramChannel; | ||
import io.netty.resolver.AddressResolverGroup; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.net.InetSocketAddress; | ||
import software.amazon.awssdk.annotations.SdkProtectedApi; | ||
import software.amazon.awssdk.utils.ClassLoaderHelper; | ||
|
||
/** | ||
* Utility class for instantiating netty dns resolvers only if they're available on the class path. | ||
*/ | ||
@SdkProtectedApi | ||
public class DnsResolverLoader { | ||
|
||
private DnsResolverLoader() { | ||
} | ||
|
||
public static AddressResolverGroup<InetSocketAddress> init(ChannelFactory<? extends DatagramChannel> datagramChannelFactory) { | ||
try { | ||
Class<?> addressResolver = ClassLoaderHelper.loadClass(getAddressResolverGroup(), false, (Class) null); | ||
Class<?> dnsNameResolverBuilder = ClassLoaderHelper.loadClass(getDnsNameResolverBuilder(), false, (Class) null); | ||
|
||
Object dnsResolverObj = dnsNameResolverBuilder.newInstance(); | ||
Method method = dnsResolverObj.getClass().getMethod("channelFactory", ChannelFactory.class); | ||
method.invoke(dnsResolverObj, datagramChannelFactory); | ||
|
||
Object e = addressResolver.getConstructor(dnsNameResolverBuilder).newInstance(dnsResolverObj); | ||
return (AddressResolverGroup<InetSocketAddress>) e; | ||
} catch (ClassNotFoundException e) { | ||
throw new IllegalStateException("Cannot find module io.netty.resolver.dns " | ||
+ " To use netty non blocking dns," + | ||
" the 'netty-resolver-dns' module from io.netty must be on the class path. ", e); | ||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) { | ||
throw new IllegalStateException("Failed to create AddressResolverGroup", e); | ||
} | ||
} | ||
|
||
private static String getAddressResolverGroup() { | ||
return "io.netty.resolver.dns.DnsAddressResolverGroup"; | ||
} | ||
|
||
private static String getDnsNameResolverBuilder() { | ||
return "io.netty.resolver.dns.DnsNameResolverBuilder"; | ||
} | ||
} |
Oops, something went wrong.