Commit 381689dc by Nepxion

优化事件机制

parent ce17ec18
...@@ -290,9 +290,9 @@ public class DiscoveryConfigAdapter extends ConfigAdapter { ...@@ -290,9 +290,9 @@ public class DiscoveryConfigAdapter extends ConfigAdapter {
// 订阅远程配置中心的规则更新(推送策略自己决定,可以所有服务都只对应一个规则信息,也可以根据服务名获取对应的规则信息) // 订阅远程配置中心的规则更新(推送策略自己决定,可以所有服务都只对应一个规则信息,也可以根据服务名获取对应的规则信息)
@PostConstruct @PostConstruct
public void publish() { public void update() {
InputStream inputStream = ...; InputStream inputStream = ...;
fireRuleChanged(new RuleChangedEvent(inputStream), true); fireRuleUpdated(new RuleUpdatedEvent(inputStream), true);
} }
} }
``` ```
......
...@@ -31,7 +31,7 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant; ...@@ -31,7 +31,7 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware; import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.entity.RuleEntity; import com.nepxion.discovery.plugin.framework.entity.RuleEntity;
import com.nepxion.discovery.plugin.framework.event.PluginEventWapper; import com.nepxion.discovery.plugin.framework.event.PluginEventWapper;
import com.nepxion.discovery.plugin.framework.event.RuleChangedEvent; import com.nepxion.discovery.plugin.framework.event.RuleUpdatedEvent;
@RestController @RestController
@Api(tags = { "配置接口" }) @Api(tags = { "配置接口" })
...@@ -80,7 +80,7 @@ public class ConfigEndpoint { ...@@ -80,7 +80,7 @@ public class ConfigEndpoint {
try { try {
InputStream inputStream = IOUtils.toInputStream(config, PluginConstant.ENCODING_UTF_8); InputStream inputStream = IOUtils.toInputStream(config, PluginConstant.ENCODING_UTF_8);
pluginEventWapper.fireRuleChanged(new RuleChangedEvent(inputStream), async); pluginEventWapper.fireRuleUpdated(new RuleUpdatedEvent(inputStream), async);
} catch (IOException e) { } catch (IOException e) {
return toExceptionResponseEntity(e, true); return toExceptionResponseEntity(e, true);
} }
......
...@@ -13,13 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,13 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader; import com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader;
import com.nepxion.discovery.plugin.framework.event.PluginEventWapper; import com.nepxion.discovery.plugin.framework.event.PluginEventWapper;
import com.nepxion.discovery.plugin.framework.event.RuleChangedEvent; import com.nepxion.discovery.plugin.framework.event.RuleUpdatedEvent;
public abstract class ConfigAdapter extends AbstractConfigLoader { public abstract class ConfigAdapter extends AbstractConfigLoader {
@Autowired @Autowired
private PluginEventWapper pluginEventWapper; private PluginEventWapper pluginEventWapper;
public void fireRuleChanged(RuleChangedEvent ruleChangedEvent, boolean async) { public void fireRuleUpdated(RuleUpdatedEvent ruleUpdatedEvent, boolean async) {
pluginEventWapper.fireRuleChanged(ruleChangedEvent, async); pluginEventWapper.fireRuleUpdated(ruleUpdatedEvent, async);
} }
} }
\ No newline at end of file
...@@ -18,11 +18,11 @@ public class PluginEventWapper { ...@@ -18,11 +18,11 @@ public class PluginEventWapper {
@Autowired @Autowired
private PluginSubscriber pluginSubscriber; private PluginSubscriber pluginSubscriber;
public void fireRuleChanged(RuleChangedEvent ruleChangedEvent, boolean async) { public void fireRuleUpdated(RuleUpdatedEvent ruleUpdatedEvent, boolean async) {
if (async) { if (async) {
pluginPublisher.asyncPublish(ruleChangedEvent); pluginPublisher.asyncPublish(ruleUpdatedEvent);
} else { } else {
pluginSubscriber.onRuleChanged(ruleChangedEvent); pluginSubscriber.onRuleUpdated(ruleUpdatedEvent);
} }
} }
......
...@@ -42,7 +42,7 @@ public class PluginSubscriber { ...@@ -42,7 +42,7 @@ public class PluginSubscriber {
private LoadBalanceListenerExecutor loadBalanceListenerExecutor; private LoadBalanceListenerExecutor loadBalanceListenerExecutor;
@Subscribe @Subscribe
public void onRuleChanged(RuleChangedEvent ruleChangedEvent) { public void onRuleUpdated(RuleUpdatedEvent ruleUpdatedEvent) {
Boolean discoveryControlEnabled = pluginContextAware.isDiscoveryControlEnabled(); Boolean discoveryControlEnabled = pluginContextAware.isDiscoveryControlEnabled();
Boolean remoteConfigEnabled = pluginContextAware.isRemoteConfigEnabled(); Boolean remoteConfigEnabled = pluginContextAware.isRemoteConfigEnabled();
...@@ -58,13 +58,13 @@ public class PluginSubscriber { ...@@ -58,13 +58,13 @@ public class PluginSubscriber {
return; return;
} }
LOG.info("********** Remote config changing has been triggered **********"); LOG.info("********** Remote rule updating has been triggered **********");
if (ruleChangedEvent == null) { if (ruleUpdatedEvent == null) {
throw new PluginException("RuleChangedEvent can't be null"); throw new PluginException("RuleUpdatedEvent can't be null");
} }
InputStream inputStream = ruleChangedEvent.getInputStream(); InputStream inputStream = ruleUpdatedEvent.getInputStream();
try { try {
pluninConfigParser.parse(inputStream); pluninConfigParser.parse(inputStream);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -12,12 +12,12 @@ package com.nepxion.discovery.plugin.framework.event; ...@@ -12,12 +12,12 @@ package com.nepxion.discovery.plugin.framework.event;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
public class RuleChangedEvent implements Serializable { public class RuleUpdatedEvent implements Serializable {
private static final long serialVersionUID = 2315578803987663866L; private static final long serialVersionUID = 2315578803987663866L;
private InputStream inputStream; private InputStream inputStream;
public RuleChangedEvent(InputStream inputStream) { public RuleUpdatedEvent(InputStream inputStream) {
this.inputStream = inputStream; this.inputStream = inputStream;
} }
......
...@@ -48,7 +48,7 @@ public class MyConfigAdapter extends ConfigAdapter { ...@@ -48,7 +48,7 @@ public class MyConfigAdapter extends ConfigAdapter {
public void publish() { public void publish() {
try { try {
InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule.xml")); InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule.xml"));
fireRuleChanged(new RuleChangedEvent(inputStream), true); fireRuleUpdated(new RuleUpdatedEvent(inputStream), true);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment