All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.configcenter.spring.config.ConfigPropertySourcesProcessor Maven / Gradle / Ivy

The newest version!
package com.github.javaclub.configcenter.spring.config;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.github.javaclub.configcenter.ConfigServerConstants.Client;
import com.github.javaclub.configcenter.client.conf.LocalConfigserverConf;
import com.github.javaclub.configcenter.client.domain.ConfigKeysIncrEvent;
import com.github.javaclub.configcenter.spring.spi.ConfigPropertySourcesProcessorHelper;
import com.github.javaclub.configcenter.spring.utils.ServiceBootstrap;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;


/**
 * Config Property Sources processor for Spring XML Based Application
 */
public class ConfigPropertySourcesProcessor extends PropertySourcesProcessor implements BeanDefinitionRegistryPostProcessor, ApplicationListener {
	
	private static final Logger log = LoggerFactory.getLogger(ConfigPropertySourcesProcessor.class);

	private ConfigPropertySourcesProcessorHelper helper = ServiceBootstrap.loadPrimary(ConfigPropertySourcesProcessorHelper.class);

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		helper.postProcessBeanDefinitionRegistry(registry);
	}
	
	@Subscribe
    @AllowConcurrentEvents
    public void handleConfigKeysIncrEvent(ConfigKeysIncrEvent event) {
		List changedKeys = event.getIncrKeys();
		log.info("Subscribe ConfigKeysIncrEvent, changedKeys = {}", changedKeys);
		String appName = LocalConfigserverConf.getInstance().getAppName();
		ConfigPropertySource appServerConfigSource = configPropertySourceFactory.getConfigPropertySourceByName(appName);
		appServerConfigSource.getPropertyNames();
	}
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		ApplicationContext ac = event.getApplicationContext();
		if(null != ac && null == ac.getParent()) {
			Client.setClientAppInited(true);
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy