Skip to content

Commit

Permalink
Merge pull request alibaba#3305 from zongtanghu/feature_notifycenter_…
Browse files Browse the repository at this point in the history
…replace_v2

[ISSUE#3179]Replace the NotifyCenter with new refactor in the config and test module.
  • Loading branch information
KomachiSion authored Jul 13, 2020
2 parents 84b733a + 34fd36b commit ee3b16b
Show file tree
Hide file tree
Showing 13 changed files with 556 additions and 569 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.common.model.RestResultUtils;
import com.alibaba.nacos.common.utils.Objects;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.event.DerbyImportEvent;
import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource;
Expand All @@ -30,7 +31,6 @@
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.core.auth.ActionTypes;
import com.alibaba.nacos.core.auth.Secured;
import com.alibaba.nacos.core.notify.NotifyCenter;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.core.utils.WebUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package com.alibaba.nacos.config.server.filter;

import com.alibaba.nacos.common.utils.ExceptionUtil;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.SmartSubscriber;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent;
import com.alibaba.nacos.config.server.model.event.RaftDbErrorRecoverEvent;
Expand All @@ -26,9 +29,6 @@
import com.alibaba.nacos.core.cluster.MemberMetaDataConstants;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.core.code.ControllerMethodsCache;
import com.alibaba.nacos.core.notify.Event;
import com.alibaba.nacos.core.notify.NotifyCenter;
import com.alibaba.nacos.core.notify.listener.SmartSubscribe;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
Expand All @@ -41,6 +41,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -119,7 +120,7 @@ private void listenerSelfInCluster() {
}

private void registerSubscribe() {
NotifyCenter.registerSubscribe(new SmartSubscribe() {
NotifyCenter.registerSubscriber(new SmartSubscriber() {

@Override
public void onEvent(Event event) {
Expand All @@ -135,8 +136,8 @@ public void onEvent(Event event) {
}

@Override
public boolean canNotify(Event event) {
return (event instanceof RaftDbErrorEvent) || (event instanceof RaftDbErrorRecoverEvent);
public List<Class<? extends Event>> subscribeTypes() {
return Arrays.asList(RaftDbErrorRecoverEvent.class, RaftDbErrorEvent.class);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

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

import com.alibaba.nacos.core.notify.Event;
import com.alibaba.nacos.common.notify.Event;

/**
* ConfigDumpEvent.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class ConfigDumpEvent implements Event {
public class ConfigDumpEvent extends Event {

private static final long serialVersionUID = -8776888606458370294L;

Expand Down Expand Up @@ -222,7 +222,7 @@ public ConfigDumpEventBuilder lastModifiedTs(long lastModifiedTs) {
this.lastModifiedTs = lastModifiedTs;
return this;
}

/**
* Build a configDumpEvent.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

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

import com.alibaba.nacos.core.notify.SlowEvent;
import com.alibaba.nacos.common.notify.SlowEvent;

/**
* Data import event.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class DerbyImportEvent implements SlowEvent {
public class DerbyImportEvent extends SlowEvent {

private static final long serialVersionUID = 3299565864352399053L;

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

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

import com.alibaba.nacos.core.notify.SlowEvent;
import com.alibaba.nacos.common.notify.SlowEvent;

/**
* DerbyLoadEvent.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class DerbyLoadEvent implements SlowEvent {
public class DerbyLoadEvent extends SlowEvent {

public static final DerbyLoadEvent INSTANCE = new DerbyLoadEvent();

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

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

import com.alibaba.nacos.core.notify.SlowEvent;
import com.alibaba.nacos.common.notify.SlowEvent;

/**
* RaftDBErrorEvent.
*
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
*/
public class RaftDbErrorEvent implements SlowEvent {
public class RaftDbErrorEvent extends SlowEvent {

private static final long serialVersionUID = 101591819161802336L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package com.alibaba.nacos.config.server.model.event;

import com.alibaba.nacos.common.JustForTest;
import com.alibaba.nacos.core.notify.Event;
import com.alibaba.nacos.common.notify.Event;

/**
* RaftDBErrorRecoverEvent.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
@JustForTest
public class RaftDbErrorRecoverEvent implements Event {
public class RaftDbErrorRecoverEvent extends Event {

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@
package com.alibaba.nacos.config.server.service.dump;

import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
import com.alibaba.nacos.config.server.service.AggrWhitelist;
import com.alibaba.nacos.config.server.service.ClientIpWhiteList;
import com.alibaba.nacos.config.server.service.ConfigCacheService;
import com.alibaba.nacos.config.server.service.SwitchService;
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
import com.alibaba.nacos.core.notify.Event;
import com.alibaba.nacos.core.notify.listener.Subscribe;

/**
* Dump config subscriber.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class DumpConfigHandler implements Subscribe<ConfigDumpEvent> {
public class DumpConfigHandler extends Subscriber<ConfigDumpEvent> {

/**
* trigger config dump event.
*
* @param event {@link ConfigDumpEvent}
* @return {@code true} if the config dump task success , else
* {@code false}
* @return {@code true} if the config dump task success , else {@code false}
*/
public static boolean configDump(ConfigDumpEvent event) {
final String dataId = event.getDataId();
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.repository.embedded;

import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.config.server.model.event.DerbyLoadEvent;
import com.alibaba.nacos.config.server.service.datasource.DataSourceService;
import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource;
Expand All @@ -27,7 +28,6 @@
import com.alibaba.nacos.consistency.snapshot.Writer;
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
import com.alibaba.nacos.core.utils.DiskUtils;
import com.alibaba.nacos.core.notify.NotifyCenter;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.core.utils.TimerContext;
import com.alipay.sofa.jraft.util.CRC64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import com.alibaba.nacos.common.JustForTest;
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.common.model.RestResultUtils;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.common.utils.ExceptionUtil;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.LoggerUtils;
Expand Down Expand Up @@ -53,9 +56,6 @@
import com.alibaba.nacos.consistency.snapshot.SnapshotOperation;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.core.distributed.ProtocolManager;
import com.alibaba.nacos.core.notify.Event;
import com.alibaba.nacos.core.notify.NotifyCenter;
import com.alibaba.nacos.core.notify.listener.Subscribe;
import com.alibaba.nacos.core.utils.ClassUtils;
import com.alibaba.nacos.core.utils.DiskUtils;
import com.alibaba.nacos.core.utils.GenericType;
Expand Down Expand Up @@ -190,7 +190,7 @@ protected void init() throws Exception {
// Register the snapshot load event
NotifyCenter.registerToSharePublisher(DerbyLoadEvent.class);

NotifyCenter.registerSubscribe(new Subscribe<RaftDbErrorEvent>() {
NotifyCenter.registerSubscriber(new Subscriber<RaftDbErrorEvent>() {
@Override
public void onEvent(RaftDbErrorEvent event) {
dataSourceService.setHealthStatus("DOWN");
Expand All @@ -202,8 +202,8 @@ public Class<? extends Event> subscribeType() {
}
});

NotifyCenter.registerToPublisher(ConfigDumpEvent.class, NotifyCenter.RING_BUFFER_SIZE);
NotifyCenter.registerSubscribe(new DumpConfigHandler());
NotifyCenter.registerToPublisher(ConfigDumpEvent.class, NotifyCenter.ringBufferSize);
NotifyCenter.registerSubscriber(new DumpConfigHandler());

this.protocol.addLogProcessors(Collections.singletonList(this));
LogUtil.DEFAULT_LOG.info("use DistributedTransactionServicesImpl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.config.server.configuration.ConditionOnEmbeddedStorage;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.enums.FileTypeEnum;
Expand Down Expand Up @@ -48,7 +49,6 @@
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.core.notify.NotifyCenter;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
Expand Down
Loading

0 comments on commit ee3b16b

Please sign in to comment.