Commit 5f29ed3b by Nepxion

优化类结构

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