Skip to content
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

Use HttpConnectionProvider mutate method #2462

Closed
yangbongsoo opened this issue Sep 4, 2022 · 0 comments · Fixed by #2483
Closed

Use HttpConnectionProvider mutate method #2462

yangbongsoo opened this issue Sep 4, 2022 · 0 comments · Fixed by #2483
Labels
type/bug A general bug
Milestone

Comments

@yangbongsoo
Copy link

yangbongsoo commented Sep 4, 2022

Motivation

I want to make new ConnectionProvider using defaultHttpClient.configuration().connectionProvider().mutate() operation.
However I can't use mutate() method.

  return new ReactorClientHttpConnector(reactorResourceFactory, defaultHttpClient -> {
    // builder value is always null.
    Builder builder = defaultHttpClient.configuration().connectionProvider().mutate();

  }
}

Because HttpConnectionProvider(defaultHttpClient type is HttpConnectionProvider) don't override mutate() method and default mutate() method return null.

@FunctionalInterface
public interface ConnectionProvider extends Disposable {
	@Nullable
	default Builder mutate() {
		return null;
	}
}

Desired solution

private ReactorClientHttpConnector customize(maxIdleTimeoutMillis, maxLifeTimeoutMillis) {
  return new ReactorClientHttpConnector(reactorResourceFactory, defaultHttpClient -> {
    ConnectionProvider provider = defaultHttpClient.configuration().connectionProvider()
        .mutate()
        .name("provider")
        .maxIdleTime(Duration.ofMillis(maxIdleTimeoutMillis))
        .maxLifeTime(Duration.ofMillis(maxLifeTimeoutMillis))
        .build();

    HttpClient httpClient = HttpClient.create(provider)
  }
}

I made PR #2463

Considered alternatives

I have a question. Violetagg told me that defaultHttpClient.configuration().connectionProvider() should return the original ConnectionProvider.

So I made below test code. I think that configuredConnectionProvider.http1ConnectionProvider return the original ConnectionProvider. Isn't it? Please tell me if I'm mistaken.

@Test
void configuredConnectionProviderShouldReturnTheOriginalConnectionProvider() {
	ConnectionProvider provider = ConnectionProvider.create("provider");
	try {
		HttpClient client = HttpClient.create(provider);
		HttpConnectionProvider configuredConnectionProvider =
				(HttpConnectionProvider) client.configuration().connectionProvider();
		assertThat(provider.getClass().getName())
				.isEqualTo(configuredConnectionProvider.http1ConnectionProvider.getClass().getName());
	}
	finally {
		provider.disposeLater()
				.block(Duration.ofSeconds(5));
	}
}

스크린샷 2022-09-04 오후 12 56 37

@yangbongsoo yangbongsoo added status/need-triage A new issue that still need to be evaluated as a whole type/enhancement A general enhancement labels Sep 4, 2022
@yangbongsoo yangbongsoo changed the title Return new Builder in ConnectionProvider mutate default method Use HttpConnectionProvider mutate method Sep 4, 2022
yangbongsoo added a commit to yangbongsoo/reactor-netty that referenced this issue Sep 4, 2022
@violetagg violetagg added type/bug A general bug and removed type/enhancement A general enhancement status/need-triage A new issue that still need to be evaluated as a whole labels Sep 7, 2022
@violetagg violetagg added this to the 1.0.x Backlog milestone Sep 7, 2022
@violetagg violetagg linked a pull request Sep 7, 2022 that will close this issue
yangbongsoo added a commit to yangbongsoo/reactor-netty that referenced this issue Sep 8, 2022
violetagg added a commit that referenced this issue Sep 14, 2022
@violetagg violetagg modified the milestones: 1.0.x Backlog, 1.0.24 Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment