Commit 5f29ed3b by Nepxion

优化类结构

parent eda35bf7
......@@ -13,11 +13,9 @@ import javax.annotation.PostConstruct;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.consul.discovery.ConsulServer;
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.constant.ConsulConstant;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
......@@ -25,14 +23,11 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
import com.netflix.loadbalancer.Server;
public class ConsulAdapter extends AbstractPluginAdapter {
@Autowired
private ConfigurableEnvironment environment;
private String version;
@PostConstruct
private void initialize() {
String value = environment.getProperty(ConsulConstant.METADATA_VERSION);
String value = pluginContextAware.getEnvironment().getProperty(ConsulConstant.METADATA_VERSION);
if (StringUtils.isEmpty(value)) {
return;
}
......
......@@ -9,10 +9,8 @@ package com.nepxion.discovery.plugin.framework.adapter;
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.constant.EurekaConstant;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
......@@ -21,9 +19,6 @@ import com.netflix.loadbalancer.Server;
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
public class EurekaAdapter extends AbstractPluginAdapter {
@Autowired
private ConfigurableEnvironment environment;
@Override
public String getIpAddress(Registration registration) {
if (registration instanceof EurekaRegistration) {
......@@ -59,6 +54,6 @@ public class EurekaAdapter extends AbstractPluginAdapter {
@Override
public String getLocalVersion() {
return environment.getProperty(EurekaConstant.METADATA_VERSION);
return pluginContextAware.getEnvironment().getProperty(EurekaConstant.METADATA_VERSION);
}
}
\ No newline at end of file
......@@ -9,11 +9,9 @@ package com.nepxion.discovery.plugin.framework.adapter;
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.zookeeper.discovery.ZookeeperServer;
import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.constant.ZookeeperConstant;
......@@ -21,9 +19,6 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
import com.netflix.loadbalancer.Server;
public class ZookeeperAdapter extends AbstractPluginAdapter {
@Autowired
private ConfigurableEnvironment environment;
@Override
public String getIpAddress(Registration registration) {
if (registration instanceof ZookeeperRegistration) {
......@@ -59,6 +54,6 @@ public class ZookeeperAdapter extends AbstractPluginAdapter {
@Override
public String getLocalVersion() {
return environment.getProperty(ZookeeperConstant.METADATA_VERSION);
return pluginContextAware.getEnvironment().getProperty(ZookeeperConstant.METADATA_VERSION);
}
}
\ No newline at end of file
......@@ -14,10 +14,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.plugin.framework.cache.PluginCache;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
public abstract class AbstractPluginAdapter implements PluginAdapter {
@Autowired
private PluginCache pluginCache;
protected PluginContextAware pluginContextAware;
@Autowired
protected PluginCache pluginCache;
@Override
public String getVersion() {
......@@ -43,4 +47,12 @@ public abstract class AbstractPluginAdapter implements PluginAdapter {
public void clearDynamicVersion() {
pluginCache.clear(PluginConstant.VERSION);
}
public PluginContextAware getPluginContextAware() {
return pluginContextAware;
}
public PluginCache getPluginCache() {
return pluginCache;
}
}
\ No newline at end of file
......@@ -10,23 +10,15 @@ package com.nepxion.discovery.plugin.framework.listener;
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
public class BasicListener implements Listener {
@Autowired
protected ConfigurableApplicationContext applicationContext;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
public class BasicListener implements Listener {
@Autowired
protected ConfigurableEnvironment environment;
@Override
public ConfigurableApplicationContext getApplicationContext() {
return applicationContext;
}
protected PluginContextAware pluginContextAware;
@Override
public ConfigurableEnvironment getEnvironment() {
return environment;
public PluginContextAware getPluginContextAware() {
return pluginContextAware;
}
}
\ No newline at end of file
......@@ -9,11 +9,8 @@ package com.nepxion.discovery.plugin.framework.listener;
* @version 1.0
*/
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
public interface Listener {
ConfigurableApplicationContext getApplicationContext();
ConfigurableEnvironment getEnvironment();
PluginContextAware getPluginContextAware();
}
\ No newline at end of file
......@@ -88,7 +88,7 @@ public class CountFilterRegisterListener extends AbstractRegisterListener {
private void onRegisterFailure(int maxCount, String serviceId, String ipAddress, int port) {
String description = ipAddress + " isn't allowed to register to Register server, reach max limited count=" + maxCount;
Boolean registerFailureEventEnabled = environment.getProperty(PluginConstant.SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED, Boolean.class, Boolean.FALSE);
Boolean registerFailureEventEnabled = pluginContextAware.getEnvironment().getProperty(PluginConstant.SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED, Boolean.class, Boolean.FALSE);
if (registerFailureEventEnabled) {
pluginPublisher.asyncPublish(new RegisterFailureEvent(PluginConstant.REACH_MAX_LIMITED_COUNT, description, serviceId, ipAddress, port));
}
......
......@@ -113,7 +113,7 @@ public class IpAddressFilterRegisterListener extends AbstractRegisterListener {
private void onRegisterFailure(FilterType filterType, List<String> allFilterValueList, String serviceId, String ipAddress, int port) {
String description = ipAddress + " isn't allowed to register to Register server, not match IP address " + filterType + "=" + allFilterValueList;
Boolean registerFailureEventEnabled = environment.getProperty(PluginConstant.SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED, Boolean.class, Boolean.FALSE);
Boolean registerFailureEventEnabled = pluginContextAware.getEnvironment().getProperty(PluginConstant.SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED, Boolean.class, Boolean.FALSE);
if (registerFailureEventEnabled) {
pluginPublisher.asyncPublish(new RegisterFailureEvent(filterType.toString(), description, serviceId, ipAddress, port));
}
......
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