You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/13 11:13:40 UTC

[GitHub] [pulsar] yws-tracy opened a new pull request #14670: Optimize ClientBuilderImpl

yws-tracy opened a new pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670


    Optimize ClientBuilderImpl        
             1. unify argument check logic using Preconditions instead of partly using Preconditions partly use if ...
             2. simplify if else logic on checking serviceUrlProvider
   
   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull request.
       Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   *(If this PR fixes a github issue, please add `Fixes #<xyz>`.)*
   
   Fixes #<xyz>
   
   *(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*
   
   Master Issue: #<xyz>
   
   ### Motivation
   
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API: (yes / no)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
     - The rest endpoints: (yes / no)
     - The admin cli options: (yes / no)
     - Anything that affects deployment: (yes / no / don't know)
   
   ### Documentation
   
   Check the box below or label this PR directly (if you have committer privilege).
   
   Need to update docs? 
   
   - [ ] `doc-required` 
     
     (If you need help on updating docs, create a doc issue)
     
   - [ ] `no-need-doc` 
     
     (Please explain why)
     
   - [ ] `doc` 
     
     (If this PR contains doc changes)
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825434321



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -339,7 +328,8 @@ public ClientBuilder enableTransaction(boolean enableTransaction) {
 
     @Override
     public ClientBuilder dnsLookupBind(String address, int port) {
-        checkArgument(port >= 0 && port <= 65535, "DnsLookBindPort need to be within the range of 0 and 65535");
+        checkArgument(port >= 0 && port <= 65535,

Review comment:
       it's too long,  I split into two line by the way  




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825434528



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -339,7 +328,8 @@ public ClientBuilder enableTransaction(boolean enableTransaction) {
 
     @Override
     public ClientBuilder dnsLookupBind(String address, int port) {
-        checkArgument(port >= 0 && port <= 65535, "DnsLookBindPort need to be within the range of 0 and 65535");
+        checkArgument(port >= 0 && port <= 65535,

Review comment:
       do I need to recover ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] github-actions[bot] commented on pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#issuecomment-1066079017


   @yws-tracy:Thanks for providing doc info!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Technoboy- commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825610664



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -323,9 +312,8 @@ public ClientBuilder clock(Clock clock) {
 
     @Override
     public ClientBuilder proxyServiceUrl(String proxyServiceUrl, ProxyProtocol proxyProtocol) {
-        if (StringUtils.isNotBlank(proxyServiceUrl) && proxyProtocol == null) {
-            throw new IllegalArgumentException("proxyProtocol must be present with proxyServiceUrl");
-        }
+        checkArgument(StringUtils.isBlank(proxyServiceUrl) || proxyProtocol != null,
+                "proxyProtocol must be present with proxyServiceUrl");

Review comment:
       Ah ?  is this equals ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] github-actions[bot] commented on pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#issuecomment-1066078948


   @yws-tracy:Thanks for your contribution. For this PR, do we need to update docs?
   (The [PR template contains info about doc](https://github.com/apache/pulsar/blob/master/.github/PULL_REQUEST_TEMPLATE.md#documentation), which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825434823



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -79,15 +75,13 @@ public ClientBuilder clone() {
     @Override
     public ClientBuilder loadConf(Map<String, Object> config) {
         conf = ConfigurationDataUtils.loadData(
-            config, conf, ClientConfigurationData.class);
+                config, conf, ClientConfigurationData.class);

Review comment:
       yeah,  I recover to normal
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825435852



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -79,15 +75,13 @@ public ClientBuilder clone() {
     @Override
     public ClientBuilder loadConf(Map<String, Object> config) {
         conf = ConfigurationDataUtils.loadData(
-            config, conf, ClientConfigurationData.class);
+                config, conf, ClientConfigurationData.class);

Review comment:
       recovered




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Technoboy- commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825675722



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -323,9 +312,8 @@ public ClientBuilder clock(Clock clock) {
 
     @Override
     public ClientBuilder proxyServiceUrl(String proxyServiceUrl, ProxyProtocol proxyProtocol) {
-        if (StringUtils.isNotBlank(proxyServiceUrl) && proxyProtocol == null) {
-            throw new IllegalArgumentException("proxyProtocol must be present with proxyServiceUrl");
-        }
+        checkArgument(StringUtils.isBlank(proxyServiceUrl) || proxyProtocol != null,
+                "proxyProtocol must be present with proxyServiceUrl");

Review comment:
       This makes the code unreadable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui merged pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
codelipenghui merged pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Shoothzj commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825613384



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -323,9 +312,8 @@ public ClientBuilder clock(Clock clock) {
 
     @Override
     public ClientBuilder proxyServiceUrl(String proxyServiceUrl, ProxyProtocol proxyProtocol) {
-        if (StringUtils.isNotBlank(proxyServiceUrl) && proxyProtocol == null) {
-            throw new IllegalArgumentException("proxyProtocol must be present with proxyServiceUrl");
-        }
+        checkArgument(StringUtils.isBlank(proxyServiceUrl) || proxyProtocol != null,
+                "proxyProtocol must be present with proxyServiceUrl");

Review comment:
       @Technoboy- Yes, the checkArgument method's arguement should be true, so reversed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] RobertIndie commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
RobertIndie commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825749327



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -323,9 +312,8 @@ public ClientBuilder clock(Clock clock) {
 
     @Override
     public ClientBuilder proxyServiceUrl(String proxyServiceUrl, ProxyProtocol proxyProtocol) {
-        if (StringUtils.isNotBlank(proxyServiceUrl) && proxyProtocol == null) {
-            throw new IllegalArgumentException("proxyProtocol must be present with proxyServiceUrl");
-        }
+        checkArgument(StringUtils.isBlank(proxyServiceUrl) || proxyProtocol != null,
+                "proxyProtocol must be present with proxyServiceUrl");

Review comment:
       @codelipenghui I think the expected behavior is to check that the `proxyProtocol` must be provided if the `proxyServiceUrl` is provided. I agree with @Technoboy- . I think we could make this more readable




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825743027



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -323,9 +312,8 @@ public ClientBuilder clock(Clock clock) {
 
     @Override
     public ClientBuilder proxyServiceUrl(String proxyServiceUrl, ProxyProtocol proxyProtocol) {
-        if (StringUtils.isNotBlank(proxyServiceUrl) && proxyProtocol == null) {
-            throw new IllegalArgumentException("proxyProtocol must be present with proxyServiceUrl");
-        }
+        checkArgument(StringUtils.isBlank(proxyServiceUrl) || proxyProtocol != null,
+                "proxyProtocol must be present with proxyServiceUrl");

Review comment:
       What is the expected behavior here? Both the `proxyServiceUrl` and `proxyProtocol` can not be null or empty?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Shoothzj commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825433125



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -339,7 +328,8 @@ public ClientBuilder enableTransaction(boolean enableTransaction) {
 
     @Override
     public ClientBuilder dnsLookupBind(String address, int port) {
-        checkArgument(port >= 0 && port <= 65535, "DnsLookBindPort need to be within the range of 0 and 65535");
+        checkArgument(port >= 0 && port <= 65535,

Review comment:
       is that a unnecessary format?

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -79,15 +75,13 @@ public ClientBuilder clone() {
     @Override
     public ClientBuilder loadConf(Map<String, Object> config) {
         conf = ConfigurationDataUtils.loadData(
-            config, conf, ClientConfigurationData.class);
+                config, conf, ClientConfigurationData.class);

Review comment:
       is that a unnecessary format?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on a change in pull request #14670: Optimize ClientBuilderImpl

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on a change in pull request #14670:
URL: https://github.com/apache/pulsar/pull/14670#discussion_r825435719



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientBuilderImpl.java
##########
@@ -339,7 +328,8 @@ public ClientBuilder enableTransaction(boolean enableTransaction) {
 
     @Override
     public ClientBuilder dnsLookupBind(String address, int port) {
-        checkArgument(port >= 0 && port <= 65535, "DnsLookBindPort need to be within the range of 0 and 65535");
+        checkArgument(port >= 0 && port <= 65535,

Review comment:
       recovered!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org