
com.nepxion.discovery.plugin.framework.context.ZookeeperApplicationContextInitializer Maven / Gradle / Ivy
package com.nepxion.discovery.plugin.framework.context;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties;
import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.plugin.framework.constant.ZookeeperConstant;
import com.nepxion.discovery.plugin.framework.decorator.ZookeeperServiceRegistryDecorator;
import com.nepxion.discovery.plugin.framework.util.MetadataUtil;
public class ZookeeperApplicationContextInitializer extends PluginApplicationContextInitializer {
@Override
protected Object afterInitialization(ConfigurableApplicationContext applicationContext, Object bean, String beanName) throws BeansException {
if (bean instanceof ZookeeperServiceRegistry) {
ZookeeperServiceRegistry zookeeperServiceRegistry = (ZookeeperServiceRegistry) bean;
return new ZookeeperServiceRegistryDecorator(zookeeperServiceRegistry, applicationContext);
} else if (bean instanceof ZookeeperDiscoveryProperties) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
ZookeeperDiscoveryProperties zookeeperDiscoveryProperties = (ZookeeperDiscoveryProperties) bean;
zookeeperDiscoveryProperties.setPreferIpAddress(true);
Map metadata = zookeeperDiscoveryProperties.getMetadata();
if (!metadata.containsKey(DiscoveryConstant.GROUP)) {
metadata.put(DiscoveryConstant.GROUP, DiscoveryConstant.DEFAULT);
}
if (!metadata.containsKey(DiscoveryConstant.VERSION)) {
metadata.put(DiscoveryConstant.VERSION, DiscoveryConstant.DEFAULT);
}
if (!metadata.containsKey(DiscoveryConstant.REGION)) {
metadata.put(DiscoveryConstant.REGION, DiscoveryConstant.DEFAULT);
}
metadata.put(DiscoveryConstant.SPRING_APPLICATION_NAME, PluginContextAware.getApplicationName(environment));
metadata.put(DiscoveryConstant.SPRING_APPLICATION_TYPE, PluginContextAware.getApplicationType(environment));
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, ZookeeperConstant.DISCOVERY_PLUGIN);
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION);
metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString());
metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED, PluginContextAware.isDiscoveryControlEnabled(environment).toString());
metadata.put(DiscoveryConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED, PluginContextAware.isConfigRestControlEnabled(environment).toString());
metadata.put(DiscoveryConstant.SPRING_APPLICATION_GROUP_KEY, PluginContextAware.getGroupKey(environment));
metadata.put(DiscoveryConstant.SPRING_APPLICATION_CONTEXT_PATH, PluginContextAware.getContextPath(environment));
MetadataUtil.filter(metadata);
return bean;
} else {
return bean;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy