Skip to content

AsyncClientBuilder cleanup #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2018
Merged

Conversation

zoewangg
Copy link
Contributor

Various AsynClientBuilder clean up.

  • Drop async prefix in the builder(but we are gonna need to cast the httpClient builder in SdkDefaultClientBuilder see comments in the PR)
  • Validate duration are positive.
  • Create SdkEventLoopGroup as wrapper class to hold EventLoopGroup and ChannelFactory to be used for Netty client.

Here's how NettyNioAsyncHttpClient configuration looks like:

  • using custom EventLoopGroup and channel factory
    SdkAsyncHttpClient customClient =
        NettyNioAsyncHttpClient.builder()
                               .eventLoopGroup(SdkEventLoopGroup.create(eventLoopGroup, NioSocketChannel::new))
                               .build();
  • using SDK-managed eventLoopGroup but providing configurations
    SdkAsyncHttpClient customClient =
        NettyNioAsyncHttpClient.builder()
                               .eventLoopGroupBuilder(SdkEventLoopGroup.builder()
                                                                       .threadFactory(threadFactory)
                                                                       .numberOfThreads(threadCount))
                               .build();

Notes

  • Now there are two different ways to create SdkEventLoopGroup
    • using SdkEventLoopGroup.create(eventLoopGroup, channelFactory)
    • using SdkEventLoopGroup.builder() and the builder doesn't have eventLoopGroup() interface defined.

This might be confusing to customers and I considered moving the builder to a different class but I find keeping them in the same class helps discoverability.

  • .eventLoopGroupBuilder() is taking the builder class as parameter

@@ -140,7 +140,7 @@ public void clientFactoryProvided_ClientIsManagedBySdk() {
public void asyncHttpClientFactoryProvided_ClientIsManagedBySdk() {
TestAsyncClient client = testAsyncClientBuilder()
.region(Region.US_WEST_2)
.asyncHttpClientBuilder(serviceDefaults -> {
.httpClientBuilder((SdkAsyncHttpClient.Builder) serviceDefaults -> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to cast it here since SdkDefaultClientBuilder implements both SdkAsyncClientBuilder and SdkSyncClientBuilder and has overloads of httpClientBuilder for async and sync. I think this is fine as SdkDefaultClientBuilder is protected api

@zoewangg zoewangg requested review from shorea and millems June 21, 2018 16:50

/**
* Sets the {@link EventLoopGroupFactory} which will be used to create the {@link EventLoopGroup} for the Netty
* Sets the {@link SdkEventLoopGroup.Builder} which will be used to create the {@link SdkEventLoopGroup} for the Netty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many event loops could an event loop group if an event loop could group loops? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, what a tongue twister!

public static Builder builder() {
return new DefaultBuilder();
private ChannelFactory<? extends Channel> resolveChannelFactory() {
// Currently we only support NioEvenLoopGroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing t


private final EventLoopGroup eventLoopGroup;
private final ChannelFactory<? extends Channel> channelFactory;
private final Integer numberOfThreads;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have fields for number of threads and thread factory or can we just use them to create an event loop group at build time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking customers can retrieve the value by calling numberOfThreads(). But that's not necessary and can be confusing to customers who use SdkEventLoopGroup.create method to create the class. Removed.

* @param eventLoopGroup the event loop group to determine the {@link ChannelFactory} for
* @return A {@link ChannelFactory} instance for the given event loop group.
*/
public static ChannelFactory<? extends Channel> resolveSocketChannelFactoryClass(EventLoopGroup eventLoopGroup) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated SharedSdkEventLoopGroup to store SdkEventLoopGroup so that we can get default channel factory associated with the default event loop group.

* @param channelFactory the channel factor to be used
* @return a new instance of SdkEventLoopGroup
*/
public static SdkEventLoopGroup create(EventLoopGroup eventLoopGroup, ChannelFactory<? extends Channel> channelFactory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an overload for the channel class that creates the reflective factory

@zoewangg zoewangg force-pushed the zoewang-asyncClientBuilderCleanup branch from 2cca22a to 3d03c6a Compare June 22, 2018 22:22
…oupLoop to allow users provide both EventGroupLoop and ChannelFactory.
@zoewangg zoewangg force-pushed the zoewang-asyncClientBuilderCleanup branch from 3d03c6a to 7e4fc08 Compare June 22, 2018 22:48
@zoewangg zoewangg merged commit 9518f51 into master Jun 22, 2018
@zoewangg zoewangg deleted the zoewang-asyncClientBuilderCleanup branch June 22, 2018 23:06
aws-sdk-java-automation added a commit that referenced this pull request Jul 19, 2019
…65ef9b07

Pull request: release <- staging/6386348e-edae-4494-89cf-efc865ef9b07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants