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
9258223c8e
commit
452fa5c564
@ -25,11 +25,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
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.alicloud.context.acm.AcmIntegrationProperties;
|
||||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
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.context.ApplicationListener;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@ -43,7 +46,8 @@ import com.alibaba.edas.acm.listener.ConfigChangeListener;
|
|||||||
*
|
*
|
||||||
* @author juven.xuxb, 5/13/16.
|
* @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);
|
private Logger logger = LoggerFactory.getLogger(AcmContextRefresher.class);
|
||||||
|
|
||||||
@ -53,6 +57,8 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
|||||||
|
|
||||||
private final AcmRefreshHistory refreshHistory;
|
private final AcmRefreshHistory refreshHistory;
|
||||||
|
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
private final AcmPropertySourceRepository acmPropertySourceRepository;
|
private final AcmPropertySourceRepository acmPropertySourceRepository;
|
||||||
|
|
||||||
private Map<String, ConfigChangeListener> listenerMap = new ConcurrentHashMap<>(16);
|
private Map<String, ConfigChangeListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||||
@ -74,19 +80,10 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
|||||||
|
|
||||||
private void registerDiamondListenersForApplications() {
|
private void registerDiamondListenersForApplications() {
|
||||||
if (acmIntegrationProperties.getAcmProperties().isRefreshEnabled()) {
|
if (acmIntegrationProperties.getAcmProperties().isRefreshEnabled()) {
|
||||||
for (AcmPropertySource acmPropertySource : acmPropertySourceRepository
|
for (String dataId : acmIntegrationProperties
|
||||||
.getAll()) {
|
.getApplicationConfigurationDataIds()) {
|
||||||
if (acmPropertySource.isGroupLevel()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String dataId = acmPropertySource.getDataId();
|
|
||||||
registerDiamondListener(dataId);
|
registerDiamondListener(dataId);
|
||||||
}
|
}
|
||||||
if (acmPropertySourceRepository.getAll().isEmpty()) {
|
|
||||||
|
|
||||||
registerDiamondListener(acmIntegrationProperties
|
|
||||||
.getApplicationConfigurationDataIdWithoutGroup());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,11 +107,17 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
refreshHistory.add(dataId, md5);
|
refreshHistory.add(dataId, md5);
|
||||||
contextRefresher.refresh();
|
applicationContext.publishEvent(new RefreshEvent(this, md5,
|
||||||
|
"ACM Refresh, dataId=" + dataId));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ConfigService.addListener(dataId,
|
ConfigService.addListener(dataId,
|
||||||
acmIntegrationProperties.getAcmProperties().getGroup(), listener);
|
acmIntegrationProperties.getAcmProperties().getGroup(), listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext)
|
||||||
|
throws BeansException {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user