mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
update ACM listener logic and publish a refresh event instead of invoke refresh method
This commit is contained in:
parent
5268c7fcaa
commit
04ff0dc067
@ -25,11 +25,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
||||
import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmIntegrationProperties;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.cloud.endpoint.event.RefreshEvent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@ -43,7 +47,8 @@ import com.alibaba.edas.acm.listener.ConfigChangeListener;
|
||||
*
|
||||
* @author juven.xuxb, 5/13/16.
|
||||
*/
|
||||
public class AcmContextRefresher implements ApplicationListener<ApplicationReadyEvent> {
|
||||
public class AcmContextRefresher
|
||||
implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(AcmContextRefresher.class);
|
||||
|
||||
@ -53,6 +58,8 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
|
||||
private final AcmRefreshHistory refreshHistory;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private final AcmPropertySourceRepository acmPropertySourceRepository;
|
||||
|
||||
private Map<String, ConfigChangeListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||
@ -74,19 +81,10 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
|
||||
private void registerDiamondListenersForApplications() {
|
||||
if (acmIntegrationProperties.getAcmProperties().isRefreshEnabled()) {
|
||||
for (AcmPropertySource acmPropertySource : acmPropertySourceRepository
|
||||
.getAll()) {
|
||||
if (acmPropertySource.isGroupLevel()) {
|
||||
continue;
|
||||
}
|
||||
String dataId = acmPropertySource.getDataId();
|
||||
for (String dataId : acmIntegrationProperties
|
||||
.getApplicationConfigurationDataIds()) {
|
||||
registerDiamondListener(dataId);
|
||||
}
|
||||
if (acmPropertySourceRepository.getAll().isEmpty()) {
|
||||
|
||||
registerDiamondListener(acmIntegrationProperties
|
||||
.getApplicationConfigurationDataIdWithoutGroup());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +107,8 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
}
|
||||
}
|
||||
refreshHistory.add(dataId, md5);
|
||||
contextRefresher.refresh();
|
||||
applicationContext.publishEvent(
|
||||
new RefreshEvent(this, md5, "ACM Refresh, dataId=" + dataId));
|
||||
}
|
||||
|
||||
};
|
||||
@ -120,4 +119,9 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
acmIntegrationProperties.getAcmProperties().getGroup(), listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user