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

Switch to static builder() methods #2221

Merged
merged 1 commit into from Nov 5, 2019
Merged

Switch to static builder() methods #2221

merged 1 commit into from Nov 5, 2019

Conversation

trustin
Copy link
Member

@trustin trustin commented Oct 30, 2019

Related: #1719
Motivation:

We decided to switch from new *Builder() to *.builder().

Modifications:

  • Switch to static builder() methods in:
    • ClientFactory
    • ClientOptions
    • ClientDecoration
    • ClientConnectionTimings
    • HttpClient
    • LoggingClient
    • LoggingService
    • EndpointInfo
    • FieldInfo
    • ClientCacheControl
    • ServerCacheControl
    • ClientRequestContext
    • ServiceRequestContext
    • RequestContextCurrentTraceContext
    • RetrofitMeterIdPrefixFunction
      • (Breaking) RetrofitMeterIfPrefixFunctionBuilder is now a top-level class without a public constructor.
  • Miscellaneous:
    • Increase the test timeout for ArmeriaSpringActuatorAutoConfigurationTest for less flakiness
    • Maybe fixes the flakiness in GracefulShutdownSupportTest

Comment on lines 64 to 67
ClientFactory DEFAULT = new ClientFactoryBuilder().build();
ClientFactory DEFAULT = builder().build();
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we switch to ofDefault()?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 I would lean towards using ofDefaults()

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Let me take care of it in another pull request.

@trustin
Copy link
Member Author

trustin commented Oct 30, 2019

While working on this, I found the following builder classes do not match well with the new pattern:

  • ClientBuilder
    • Adding Client.builder() doesn't sound right. We can add Clients.builder() though. Let me know if you have a better idea.
  • ArmeriaRetrofitBuilder
    • There's no ArmeriaRetrofit. Should we create an interface ArmeriaRetrofit that extends Retrofit? Thoughts?

@codecov
Copy link

codecov bot commented Oct 31, 2019

Codecov Report

Merging #2221 into master will increase coverage by 0.02%.
The diff coverage is 84.73%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2221      +/-   ##
============================================
+ Coverage     73.52%   73.55%   +0.02%     
- Complexity     9720     9749      +29     
============================================
  Files           848      849       +1     
  Lines         37535    37555      +20     
  Branches       4610     4610              
============================================
+ Hits          27599    27624      +25     
+ Misses         7575     7568       -7     
- Partials       2361     2363       +2
Impacted Files Coverage Δ Complexity Δ
.../linecorp/armeria/client/ClientFactoryBuilder.java 53.84% <ø> (ø) 26 <0> (ø) ⬇️
...p/armeria/server/ServiceRequestContextBuilder.java 76.11% <ø> (-1.5%) 19 <0> (-1)
...ecorp/armeria/server/docs/EndpointInfoBuilder.java 73.33% <ø> (ø) 16 <0> (ø) ⬇️
.../linecorp/armeria/client/ClientOptionsBuilder.java 100% <ø> (ø) 3 <0> (ø) ⬇️
...armeria/client/ClientConnectionTimingsBuilder.java 75.67% <ø> (ø) 16 <0> (ø) ⬇️
...linecorp/armeria/server/docs/FieldInfoBuilder.java 70% <ø> (ø) 6 <0> (ø) ⬇️
...corp/armeria/common/ClientCacheControlBuilder.java 95.45% <ø> (ø) 22 <0> (ø) ⬇️
...corp/armeria/common/ServerCacheControlBuilder.java 97.5% <ø> (ø) 23 <0> (ø) ⬇️
.../main/java/example/armeria/proxy/ProxyService.java 0% <0%> (ø) 0 <0> (ø) ⬇️
.../armeria/client/circuitbreaker/CircuitBreaker.java 50% <0%> (ø) 2 <0> (ø) ⬇️
... and 56 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update affd7d8...68cc53e. Read the comment docs.

@minwoox
Copy link
Member

minwoox commented Oct 31, 2019

+1 for Clients.builder().

Should we create an interface ArmeriaRetrofit that extends Retrofit?

Retrofit is a final class so we cannot extend it. I'm not sure which one is the best. 😢

@trustin
Copy link
Member Author

trustin commented Nov 1, 2019

Gentle ping, guys 😆

@trustin
Copy link
Member Author

trustin commented Nov 1, 2019

Took advantage of review lag to migrate more builders. 😝

@trustin
Copy link
Member Author

trustin commented Nov 1, 2019

Note to self: Use (class [^ ]+Builder|new [^ ]+(?<!String)Builder|@(link|linkplain|see) [^ ]+Builder) to find the candidates.

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Nice work! 👍

@trustin trustin force-pushed the builders branch 2 times, most recently from 6d61a55 to 92aa64b Compare November 4, 2019 13:38
Related: line#1719
Motivation:

We decided to switch from `new *Builder()` to `*.builder()`.

Modifications:

- Switch to static `builder()` methods in:
  - `ClientFactory`
  - `ClientOptions`
  - `ClientDecoration`
  - `ClientConnectionTimings`
  - `HttpClient`
  - `LoggingClient`
  - `LoggingService`
  - `EndpointInfo`
  - `FieldInfo`
  - `ClientCacheControl`
  - `ServerCacheControl`
  - `ClientRequestContext`
  - `ServiceRequestContext`
  - `RequestContextCurrentTraceContext`
  - `RetrofitMeterIdPrefixFunction`
    - (Breaking) `RetrofitMeterIfPrefixFunctionBuilder` is now a top-level class without a public constructor.
- Miscellaneous:
  - Increase the test timeout for `ArmeriaSpringActuatorAutoConfigurationTest` for less flakiness
  - Maybe fixes the flakiness in `GracefulShutdownSupportTest`
@trustin
Copy link
Member Author

trustin commented Nov 4, 2019

Sneaking in two miscellaneous changes, but I guess it's OK. Will merge tomorrow morning. Leave a message if you'd like them as a separate PR.

@trustin trustin merged commit 879437e into line:master Nov 5, 2019
@trustin trustin deleted the builders branch November 5, 2019 02:19
eugene70 pushed a commit to eugene70/armeria that referenced this pull request Nov 10, 2019
Related: line#1719
Motivation:

We decided to switch from `new *Builder()` to `*.builder()`.

Modifications:

- Switch to static `builder()` methods in:
  - `ClientFactory`
  - `ClientOptions`
  - `ClientDecoration`
  - `ClientConnectionTimings`
  - `HttpClient`
  - `LoggingClient`
  - `LoggingService`
  - `EndpointInfo`
  - `FieldInfo`
  - `ClientCacheControl`
  - `ServerCacheControl`
  - `ClientRequestContext`
  - `ServiceRequestContext`
  - `RequestContextCurrentTraceContext`
  - `RetrofitMeterIdPrefixFunction`
    - (Breaking) `RetrofitMeterIfPrefixFunctionBuilder` is now a top-level class without a public constructor.
- Miscellaneous:
  - Increase the test timeout for `ArmeriaSpringActuatorAutoConfigurationTest` for less flakiness
  - Maybe fixes the flakiness in `GracefulShutdownSupportTest`
trustin pushed a commit that referenced this pull request Dec 30, 2019
Related: #2221 

* Makes user to use ServerListener.builder() to get ServerListenerBuilder
* Makes user to use SimpleCompositeService.builder() to get SimplecompositeServiceBuilder
* Makes user to use SimpleCompositeRpcService.builder() to get SimplecompositeRpcServiceBuilder
* Makes user to use CorsPolicy.builder() to get CorsPolicyBuilder
* Makes user to use DocService.builder() to get DocServiceBuilder
* Makes user to use LoggingService.builder() to get LoggingServiceBuilder
* Makes user to use JettyService.builder() to get JettyServiceBuilder
* Makes user to use SamlServiceProvider.builder() to get SamlServiceProviderBuilder
* Makes user to use ZooKeeperUpdatingListener.builder() to get ZooKeeperUpdatingListenerBuilder
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Related: line#1719
Motivation:

We decided to switch from `new *Builder()` to `*.builder()`.

Modifications:

- Switch to static `builder()` methods in:
  - `ClientFactory`
  - `ClientOptions`
  - `ClientDecoration`
  - `ClientConnectionTimings`
  - `HttpClient`
  - `LoggingClient`
  - `LoggingService`
  - `EndpointInfo`
  - `FieldInfo`
  - `ClientCacheControl`
  - `ServerCacheControl`
  - `ClientRequestContext`
  - `ServiceRequestContext`
  - `RequestContextCurrentTraceContext`
  - `RetrofitMeterIdPrefixFunction`
    - (Breaking) `RetrofitMeterIfPrefixFunctionBuilder` is now a top-level class without a public constructor.
- Miscellaneous:
  - Increase the test timeout for `ArmeriaSpringActuatorAutoConfigurationTest` for less flakiness
  - Maybe fixes the flakiness in `GracefulShutdownSupportTest`
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
)

Related: line#2221 

* Makes user to use ServerListener.builder() to get ServerListenerBuilder
* Makes user to use SimpleCompositeService.builder() to get SimplecompositeServiceBuilder
* Makes user to use SimpleCompositeRpcService.builder() to get SimplecompositeRpcServiceBuilder
* Makes user to use CorsPolicy.builder() to get CorsPolicyBuilder
* Makes user to use DocService.builder() to get DocServiceBuilder
* Makes user to use LoggingService.builder() to get LoggingServiceBuilder
* Makes user to use JettyService.builder() to get JettyServiceBuilder
* Makes user to use SamlServiceProvider.builder() to get SamlServiceProviderBuilder
* Makes user to use ZooKeeperUpdatingListener.builder() to get ZooKeeperUpdatingListenerBuilder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants