You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/03/14 10:46:12 UTC

[GitHub] [dubbo] zcbbpo opened a new pull request #9780: Add instanceOf before class cast

zcbbpo opened a new pull request #9780:
URL: https://github.com/apache/dubbo/pull/9780


   Fixed for [telnet for ls commond](https://github.com/apache/dubbo/issues/9765)
   1. modify dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/ServiceCheckUtils.java
   2. add unit test at dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/ServiceCheckUtilsTest.java
   
   
   
   <!-- Follow this checklist to help us incorporate your contribution quickly and easily: -->
   
   ## Checklist
   - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) 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.
   - [x] Each commit in the pull request should have a meaningful subject line and body.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
   - [x] 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 sample in [dubbo samples](https://github.com/apache/dubbo-samples) project.
   - [x] Add some description to [dubbo-website](https://github.com/apache/dubbo-website) project if you are requesting to add a feature.
   - [x] GitHub Actions works fine on your own branch.
   - [x] If this contribution is large, please follow the [Software Donation Guide](https://github.com/apache/dubbo/wiki/Software-donation-guide).
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zcbbpo commented on pull request #9780: Add instanceOf before class cast

Posted by GitBox <gi...@apache.org>.
zcbbpo commented on pull request #9780:
URL: https://github.com/apache/dubbo/pull/9780#issuecomment-1066636859


   Hi chickenlj
   
   by the way ,The project cannot use stream?
   This code was not approve?
   ```
   public static int getConsumerAddressNum(ConsumerModel consumerModel) {
           // TODO, only check one registry by default.
           int num = 0;
   
           RegistryManager registryManager = consumerModel.getModuleModel().getApplicationModel().getBeanFactory().getBean(RegistryManager.class);
           Collection<Registry> registries = registryManager.getRegistries();
           if (CollectionUtils.isEmpty(registries)) {
               return num;
           }
           return registries.stream()
               .filter(v -> v instanceof AbstractRegistry)
               .findFirst()
               .map(v -> (AbstractRegistry)v)
               .flatMap(abstractRegistry -> abstractRegistry.getNotified().entrySet().stream()
                   .filter(kv -> kv.getKey().getServiceKey().equals(consumerModel.getServiceKey()))
                   .filter(kv -> CollectionUtils.isNotEmptyMap(kv.getValue()))
                   .findFirst()
                   .map(kv -> kv.getValue().size()))
               .orElse(num);
       }
   ```
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] chickenlj commented on pull request #9780: Add instanceOf before class cast

Posted by GitBox <gi...@apache.org>.
chickenlj commented on pull request #9780:
URL: https://github.com/apache/dubbo/pull/9780#issuecomment-1067534633


   > Hi chickenlj
   > 
   > by the way ,The project cannot use stream? This code was not approve?
   > 
   > ```
   > public static int getConsumerAddressNum(ConsumerModel consumerModel) {
   >         // TODO, only check one registry by default.
   >         int num = 0;
   > 
   >         RegistryManager registryManager = consumerModel.getModuleModel().getApplicationModel().getBeanFactory().getBean(RegistryManager.class);
   >         Collection<Registry> registries = registryManager.getRegistries();
   >         if (CollectionUtils.isEmpty(registries)) {
   >             return num;
   >         }
   >         return registries.stream()
   >             .filter(v -> v instanceof AbstractRegistry)
   >             .findFirst()
   >             .map(v -> (AbstractRegistry)v)
   >             .flatMap(abstractRegistry -> abstractRegistry.getNotified().entrySet().stream()
   >                 .filter(kv -> kv.getKey().getServiceKey().equals(consumerModel.getServiceKey()))
   >                 .filter(kv -> CollectionUtils.isNotEmptyMap(kv.getValue()))
   >                 .findFirst()
   >                 .map(kv -> kv.getValue().size()))
   >             .orElse(num);
   >     }
   > ```
   
   There's no restriction on using stream. For this case, we'd better not use the stream for the following reasons:
   1. Avoid unnecessary code refactor for potential bugs.
   2. I don't see the stream snippet above more clear than the previous for loop.


-- 
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: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] chickenlj merged pull request #9780: Add instanceOf before class cast

Posted by GitBox <gi...@apache.org>.
chickenlj merged pull request #9780:
URL: https://github.com/apache/dubbo/pull/9780


   


-- 
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: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org