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

[#3117]Just Sink the Notify implementation into common module and optimize some parts #3118

Merged
merged 6 commits into from
Jun 21, 2020

Conversation

zongtanghu
Copy link
Collaborator

@zongtanghu zongtanghu commented Jun 19, 2020

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

Sink the Notify implementation into common module and optimize some parts

Brief changelog

Sink the Notify implementation into common module and optimize some parts.
And this pr is one part of another bigger pr.The link is #2859.

Verifying this change

XXXX

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

  • Make sure there is a Github issue filed 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 [ISSUE #123] Fix UnknownException when host config not exist. 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 -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@zongtanghu
Copy link
Collaborator Author

这个PR的几个改造要点:

(1):将原来core module里面的NofityCenter和DefaultPublisher等下沉至common的module中,同时由于common module本身只是支持 java 6的,所以我把原来Nofity里面涉及Lamba表达式和Java 8的东西,都替换掉了(其中为了去除原本java 8的default关键字,我用了abstract抽象类来代替;将BiFunction从JDK 8中剥离移到common module中),没有做实际的重构和改造,基本是保留原来春少的Nofity设计思路的;

(2):对于“System.currentTimeMillis()”设置sequence的方法,采用“AtomicInteger或者AtomicLong,减少对系统时间的查询”

@zongtanghu
Copy link
Collaborator Author

Please help to review this pr, @yanlinly @KomachiSion @chuntaojun

* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
* @author zongtanghu
*/
@SuppressWarnings("all")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If no special situation, please do not use SuppressWarnings

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay I will fix this in next commit.

@Documented
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE)
public @interface NotThreadSafe {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know you want to figure out some method may be not thread safe. But I want to know whether is project do like this? I think write some discription in Javadoc is enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some open source project use this annotation to present unsafe method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK

@SuppressWarnings({"PMD.AbstractClassShouldStartWithAbstractNamingRule", "PMD.ConstantFieldShouldBeUpperCaseRule"})
public abstract class Event implements Serializable {

private static final AtomicLong sequence = new AtomicLong(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean that no-->sequence the constant still is SEQUENCE.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, sorry , I disunderstand what's your meaning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will fix this in next commit.

KomachiSion
KomachiSion previously approved these changes Jun 21, 2020
@Documented
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE)
public @interface NotThreadSafe {
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK

@KomachiSion KomachiSion added kind/enhancement Category issues or prs related to enhancement. area/Nacos Core labels Jun 21, 2020
@KomachiSion KomachiSion added this to the 1.4.0 milestone Jun 21, 2020
}

private boolean hasSubscriber() {
return CollectionUtils.isNotEmpty(subscribers) || CollectionUtils.isNotEmpty(SMART_SUBSCRIBERS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not being empty in the smartSubscribers collection does not imply that there are listeners interested in the event

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, this issue has already been resolved in this pr.

// If you want to listen to multiple events, you do it separately,
// based on subclass's subscribeTypes method return list, it can register to publisher.
if (consumer instanceof SmartSubscriber) {
EventPublisher.SMART_SUBSCRIBERS.add((SmartSubscriber) consumer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete SMART_SUBSCRIBERS

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove this in next commit.

public static <T> void deregisterSubscriber(final Subscriber consumer) {
final Class<? extends Event> cls = consumer.subscribeType();
if (consumer instanceof SmartSubscriber) {
EventPublisher.SMART_SUBSCRIBERS.remove((SmartSubscriber) consumer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete SMART_SUBSCRIBERS

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove this in next commit.

@chuntaojun chuntaojun merged commit 1dc29f2 into alibaba:develop Jun 21, 2020
Copy link
Collaborator

@yanlinly yanlinly left a comment

Choose a reason for hiding this comment

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

后面建议把ut 也一起迁移下来。

@zongtanghu
Copy link
Collaborator Author

zongtanghu commented Jun 22, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Nacos Core kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants