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

添加了一个新的注解EnableAutoResfresh #888

Closed
wants to merge 5 commits into from

Conversation

tonyDJB
Copy link

@tonyDJB tonyDJB commented Dec 18, 2017

这个注解的作用是在变量上声明需要框架自动刷新,这样就不需要自己再写onChange事件,对简单拆箱的变量能省不少事

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 50.087% when pulling 0d1b47f on tonyDJB:master into 11886fc on ctripcorp:master.

@codecov-io
Copy link

codecov-io commented Dec 18, 2017

Codecov Report

Merging #888 into master will decrease coverage by 0.1%.
The diff coverage is 48.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #888      +/-   ##
============================================
- Coverage     46.76%   46.65%   -0.11%     
- Complexity     1540     1545       +5     
============================================
  Files           352      352              
  Lines          9717     9767      +50     
  Branches        963      966       +3     
============================================
+ Hits           4544     4557      +13     
- Misses         4831     4866      +35     
- Partials        342      344       +2
Impacted Files Coverage Δ Complexity Δ
...rip/framework/apollo/internals/AbstractConfig.java 74.56% <15%> (-5.62%) 39 <3> (+1)
...o/spring/annotation/ApolloAnnotationProcessor.java 60.93% <59.01%> (-39.07%) 14 <13> (+2)
...work/apollo/biz/message/DatabaseMessageSender.java 66.66% <0%> (+10.41%) 8% <0%> (+2%) ⬆️

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 ac10768...894f1b8. Read the comment docs.

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

Thanks! Looks like a lot of changes, I will take a detailed look soon.

@tonyDJB
Copy link
Author

tonyDJB commented Dec 20, 2017

干的事情就是添加了一个名为EnableAutoResfresh 的注解
主要的逻辑在ApolloAnnotationProcessor.java

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e464ac8 on tonyDJB:master into ** on ctripcorp:master**.

@nobodyiam
Copy link
Member

好的,这几天比较忙,周末看下。

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

Thanks for the pull requests. Overall, it looks good.

Please check the comments.

Besides, there is a similar pr #898, which will update the value by default(no EnableAutoResfresh).

I'm not sure if we should change the value directly or allow the user to customize (in application level, or in method/field level)

processMethods(bean, clazz.getDeclaredMethods());
return bean;
}
@Override
Copy link
Member

Choose a reason for hiding this comment

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

Please use Apollo's code style so that we won't have code style differences.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your comment, I will reformat my code.

ReflectionUtils.makeAccessible(field);
//If it is the processing of complex data types, I suggest not to do AutoRefresh here or to handle it yourself
//add by 258737400@qq.com 2017-12-18
String type = field.getGenericType().toString();
Copy link
Member

Choose a reason for hiding this comment

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

Remember we should always use Spring's environment.getProperty() to get the property value because the key might be overridden in a different hierarchy.

Copy link
Author

Choose a reason for hiding this comment

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

What do you mean by modifying the code here?

/**
* @author tony Jiang(258737400@qq.com)
*/
public interface AutoConfigChangeListener {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need a new list of AutoConfigChangeListeners. If we want to make sure some listener is executed first, we could create a a new interface such as PriorityOrderedConfigChangeListener that extends ConfigChangeListener and allow the user to provide its order?

Copy link
Author

Choose a reason for hiding this comment

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

My idea is to provide a flexible refresh mode for users:

  1. based on ApolloConfigChangeListener annotation, let users write their own refresh code

  2. based on AutoConfigChangeListener annotation, automatic assembly of data for simple data types

In addition, with regard to #898, I do not agree with this coercion, which forces all configuration variables to be refreshed automatically, thus losing the flexibility of the user.

Above all, I think it's better to provide an independent annotation, because this is the two separate listener behavior, and there is no distinction between execution sequence.

/**
* Apollo namespace for the config, if not specified then default to application
*/
String value() default ConfigConsts.NAMESPACE_APPLICATION;
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't require the use to specify the namespace, since spring property source has hierarchies, which means one key could exist in different namespaces.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your comment.

If namespace is not named, does the key of the same name in different namespace be confused with each other?

/**
* @author tony jiang(258737400@qq.com)
*/
public class AutoRefreshDemo {
Copy link
Member

Choose a reason for hiding this comment

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

This change impacts a lot, so we should have more tests to cover the value change scenarios.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your comment.

I'm going to improve the test code.

@tonyDJB
Copy link
Author

tonyDJB commented Dec 29, 2017

Thank you for your advice in your busy schedule

I submitted comment under your question.

Copy link
Contributor

@weiguang-zz weiguang-zz left a comment

Choose a reason for hiding this comment

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

我觉得在绝大多数情况下,默认刷新的功能是用户所需要的,这也是配置中心所提供的主要功能。所以如果要对每一个field都添加注解的话,会比较麻烦,我觉得将刷新配置的功能做成默认的比较好。反而提供注解来禁止这一个功能做到灵活性。

2018-1-9 从origin更新代码
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 50.179% when pulling 894f1b8 on tonyDJB:master into ac10768 on ctripcorp:master.

@nobodyiam
Copy link
Member

@tonyDJB

非常感谢你提供的实现方式,考虑再三后,我们觉得可能对大部分用户而言,默认开启自动更新是有意义的,所以我们后来基于 #898 的提交做了一些改进,支持了对于各种情况下的placeholder值自动更新,具体细节可以参考 #972,再次感谢!

@nobodyiam nobodyiam closed this Jul 1, 2018
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.

5 participants