Commit 381689dc by Nepxion

优化事件机制

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