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

Replace original EventDispatcher with NotifyCenter in the config module. #3313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package com.alibaba.nacos.config.server.model.event;

import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
import com.alibaba.nacos.common.notify.Event;
import org.apache.commons.lang3.StringUtils;

/**
* ConfigDataChangeEvent.
*
* @author Nacos
*/
public class ConfigDataChangeEvent implements Event {
public class ConfigDataChangeEvent extends Event {

public final boolean isBeta;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.alibaba.nacos.config.server.model.event;

import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
import com.alibaba.nacos.common.notify.Event;

import java.util.List;

Expand All @@ -25,7 +25,7 @@
*
* @author Nacos
*/
public class LocalDataChangeEvent implements Event {
public class LocalDataChangeEvent extends Event {

public final String groupKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.CacheItem;
Expand All @@ -26,7 +27,6 @@
import com.alibaba.nacos.config.server.utils.GroupKey;
import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -67,12 +67,12 @@ public static boolean hasGroupKey(String groupKey) {
/**
* Save config file and update md5 value in cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param lastModifiedTs lastModifiedTs.
* @param type file type.
* @param type file type.
* @return dumpChange success or not.
*/
public static boolean dump(String dataId, String group, String tenant, String content, long lastModifiedTs,
Expand Down Expand Up @@ -120,12 +120,12 @@ public static boolean dump(String dataId, String group, String tenant, String co
/**
* Save config file and update md5 value in cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param lastModifiedTs lastModifiedTs.
* @param betaIps betaIps string value.
* @param betaIps betaIps string value.
* @return dumpChange success or not.
*/
public static boolean dumpBeta(String dataId, String group, String tenant, String content, long lastModifiedTs,
Expand Down Expand Up @@ -165,12 +165,12 @@ public static boolean dumpBeta(String dataId, String group, String tenant, Strin
/**
* Save config file and update md5 value in cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param lastModifiedTs lastModifiedTs.
* @param tag tag string value.
* @param tag tag string value.
* @return dumpChange success or not.
*/
public static boolean dumpTag(String dataId, String group, String tenant, String tag, String content,
Expand Down Expand Up @@ -209,10 +209,10 @@ public static boolean dumpTag(String dataId, String group, String tenant, String
/**
* Save config file and update md5 value in cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param content content string value.
* @param lastModifiedTs lastModifiedTs.
* @return dumpChange success or not.
*/
Expand Down Expand Up @@ -313,6 +313,7 @@ public static void reloadConfig() {

/**
* Check md5.
*
* @return return diff result list.
*/
public static List<String> checkMd5() {
Expand Down Expand Up @@ -343,20 +344,20 @@ public static List<String> checkMd5() {
* Delete config file, and delete cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param group group string value.
* @param tenant tenant string value.
* @return remove success or not.
*/
public static boolean remove(String dataId, String group, String tenant) {
final String groupKey = GroupKey2.getKey(dataId, group, tenant);
final int lockResult = tryWriteLock(groupKey);

// If data is non-existent.
if (0 == lockResult) {
DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
return true;
}

// try to lock failed
if (lockResult < 0) {
DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
Expand All @@ -368,7 +369,7 @@ public static boolean remove(String dataId, String group, String tenant) {
DiskUtil.removeConfigInfo(dataId, group, tenant);
}
CACHE.remove(groupKey);
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey));

return true;
} finally {
Expand All @@ -380,7 +381,7 @@ public static boolean remove(String dataId, String group, String tenant) {
* Delete beta config file, and delete cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param group group string value.
* @param tenant tenant string value.
* @return remove success or not.
*/
Expand All @@ -393,7 +394,7 @@ public static boolean removeBeta(String dataId, String group, String tenant) {
DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
return true;
}

// try to lock failed
if (lockResult < 0) {
DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
Expand All @@ -404,7 +405,7 @@ public static boolean removeBeta(String dataId, String group, String tenant) {
if (!PropertyUtil.isDirectRead()) {
DiskUtil.removeConfigInfo4Beta(dataId, group, tenant);
}
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
CACHE.get(groupKey).setBeta(false);
CACHE.get(groupKey).setIps4Beta(null);
CACHE.get(groupKey).setMd54Beta(Constants.NULL);
Expand All @@ -418,21 +419,21 @@ public static boolean removeBeta(String dataId, String group, String tenant) {
* Delete tag config file, and delete cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param group group string value.
* @param tenant tenant string value.
* @param tag tag string value.
* @param tag tag string value.
* @return remove success or not.
*/
public static boolean removeTag(String dataId, String group, String tenant, String tag) {
final String groupKey = GroupKey2.getKey(dataId, group, tenant);
final int lockResult = tryWriteLock(groupKey);

// If data is non-existent.
if (0 == lockResult) {
DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
return true;
}

// try to lock failed
if (lockResult < 0) {
DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
Expand All @@ -447,7 +448,7 @@ public static boolean removeTag(String dataId, String group, String tenant, Stri
CacheItem ci = CACHE.get(groupKey);
ci.tagMd5.remove(tag);
ci.tagLastModifiedTs.remove(tag);
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
return true;
} finally {
releaseWriteLock(groupKey);
Expand All @@ -457,25 +458,25 @@ public static boolean removeTag(String dataId, String group, String tenant, Stri
/**
* Update md5 value.
*
* @param groupKey groupKey string value.
* @param md5 md5 string value.
* @param groupKey groupKey string value.
* @param md5 md5 string value.
* @param lastModifiedTs lastModifiedTs long value.
*/
public static void updateMd5(String groupKey, String md5, long lastModifiedTs) {
CacheItem cache = makeSure(groupKey);
if (cache.md5 == null || !cache.md5.equals(md5)) {
cache.md5 = md5;
cache.lastModifiedTs = lastModifiedTs;
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey));
}
}

/**
* Update Beta md5 value.
*
* @param groupKey groupKey string value.
* @param md5 md5 string value.
* @param ips4Beta ips4Beta List.
* @param groupKey groupKey string value.
* @param md5 md5 string value.
* @param ips4Beta ips4Beta List.
* @param lastModifiedTs lastModifiedTs long value.
*/
public static void updateBetaMd5(String groupKey, String md5, List<String> ips4Beta, long lastModifiedTs) {
Expand All @@ -485,16 +486,16 @@ public static void updateBetaMd5(String groupKey, String md5, List<String> ips4B
cache.md54Beta = md5;
cache.lastModifiedTs4Beta = lastModifiedTs;
cache.ips4Beta = ips4Beta;
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, true, ips4Beta));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, true, ips4Beta));
}
}

/**
* Update tag md5 value.
*
* @param groupKey groupKey string value.
* @param tag tag string value.
* @param md5 md5 string value.
* @param groupKey groupKey string value.
* @param tag tag string value.
* @param md5 md5 string value.
* @param lastModifiedTs lastModifiedTs long value.
*/
public static void updateTagMd5(String groupKey, String tag, String md5, long lastModifiedTs) {
Expand All @@ -510,13 +511,13 @@ public static void updateTagMd5(String groupKey, String tag, String md5, long la
} else {
cache.tagLastModifiedTs.put(tag, lastModifiedTs);
}
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
return;
}
if (cache.tagMd5.get(tag) == null || !cache.tagMd5.get(tag).equals(md5)) {
cache.tagMd5.put(tag, md5);
cache.tagLastModifiedTs.put(tag, lastModifiedTs);
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import com.alibaba.nacos.core.utils.ApplicationUtils;

/**
Expand All @@ -30,13 +30,14 @@ public class ConfigChangePublisher {

/**
* Notify ConfigChange.
*
* @param event ConfigDataChangeEvent instance.
*/
public static void notifyConfigChange(ConfigDataChangeEvent event) {
if (PropertyUtil.isEmbeddedStorage() && !ApplicationUtils.getStandaloneMode()) {
return;
}
EventDispatcher.fireEvent(event);
NotifyCenter.publishEvent(event);
}

}
Loading