Skip to content

[Enhancement]: RestProtocol - #3480

Merged
lixiaojiee merged 2 commits into
apache:masterfrom
kezhenxu94:cleanup/rest
Feb 17, 2019
Merged

lixiaojiee merged 2 commits into
apache:masterfrom
kezhenxu94:cleanup/rest

Conversation

@kezhenxu94

@kezhenxu94 kezhenxu94 commented Feb 14, 2019 •

Copy link
Copy Markdown
Member
  • use Map#computeIfAbsent to replace check-and-create
  • use lambdas to replace annonymous inner types

What is the purpose of the change

XXXXX

Brief changelog

XXXXX

Verifying this change

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GITHUB_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GITHUB issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [Dubbo-XXX] Fix UnknownException when host config not exist #XXX. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn clean install -DskipTests=false & mvn clean test-compile failsafe:integration-test to make sure unit-test and integration-test pass.
  • If this contribution is large, please follow the Software Donation Guide.

- use `Map#computeIfAbsent` to replace check-and-create
- use lambdas to replace annonymous inner types
@kezhenxu94 kezhenxu94 changed the title optimization: RestProtocol [Enhancement]: RestProtocol Feb 14, 2019
@codecov-io

codecov-io commented Feb 14, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #3480 into master will decrease coverage by 0.03%.
The diff coverage is 64.7%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3480      +/-   ##
============================================
- Coverage      64.1%   64.06%   -0.04%     
  Complexity       71       71              
============================================
  Files           664      664              
  Lines         28605    28604       -1     
  Branches       4769     4768       -1     
============================================
- Hits          18338    18326      -12     
- Misses         8060     8068       +8     
- Partials       2207     2210       +3
Impacted Files Coverage Δ Complexity Δ
...g/apache/dubbo/rpc/protocol/rest/RestProtocol.java 73.77% <64.7%> (+0.59%) 0 <0> (ø) ⬇️
...apache/dubbo/common/config/ConfigurationUtils.java 40% <0%> (-8%) 0% <0%> (ø)
...ava/org/apache/dubbo/config/DubboShutdownHook.java 75% <0%> (-6.25%) 0% <0%> (ø)
.../apache/dubbo/remoting/transport/AbstractPeer.java 63.04% <0%> (-4.35%) 0% <0%> (ø)
...bo/rpc/cluster/support/FailbackClusterInvoker.java 67.21% <0%> (-3.28%) 0% <0%> (ø)
...dubbo/remoting/exchange/support/DefaultFuture.java 70.94% <0%> (-2.71%) 0% <0%> (ø)
...pache/dubbo/registry/support/AbstractRegistry.java 79.13% <0%> (-2.37%) 0% <0%> (ø)
.../java/org/apache/dubbo/config/ReferenceConfig.java 57.89% <0%> (+0.37%) 0% <0%> (ø) ⬇️
.../apache/dubbo/qos/protocol/QosProtocolWrapper.java 82.05% <0%> (+12.82%) 0% <0%> (ø) ⬇️

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 d33784d...7131e86. Read the comment docs.

server.start(url);
servers.put(addr, server);
}
RestServer server = servers.computeIfAbsent(addr, addr0 -> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is recommended to change addr0 to restServer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

why??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@CrazyHZM please refer to the JavaDoc of computeIfAbsent, note the second parameter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a grammatical error, just add readability

server.start(url);
servers.put(addr, server);
}
RestServer server = servers.computeIfAbsent(addr, addr0 -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also think we should replace addr0 into restServer. the addr0 is not clear for people to understand.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

but I'm wondering why renaming a variable of type String to restServer increases readability

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This has nothing to do with whether it is a String type, but using restServer in the meaning description will be clearer than addr0.
This is also to let others see the source code, know that the second parameter of the servers is a RestServer type.

@kezhenxu94 kezhenxu94 Feb 16, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@scxwhite @CrazyHZM Since the changes is controversial, I've reverted the changes, as for

This is also to let others see the source code, know that the second parameter of the servers is a RestServer type.

I'd rather suggest renaming the servers to something like serversKeyedByAddress or anything else but what you said.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That part of the code does not need to reverted, I think you modified is good, just change addr0 to restServer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changes are made as requested

@lixiaojiee lixiaojiee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks good to me, thank you for your contribution.

@lixiaojiee
lixiaojiee merged commit 813fed5 into apache:master Feb 17, 2019
@kezhenxu94
kezhenxu94 deleted the cleanup/rest branch February 17, 2019 05:52
@beiwei30 beiwei30 added this to the 2.7.1 milestone Mar 4, 2019
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.

6 participants