Commit bcc9e135 by Nepxion

重构策略模块

parent 5c9cd160
...@@ -17,13 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,13 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.util.JsonUtil; import com.nepxion.discovery.common.util.JsonUtil;
import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledAdapter; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledAdapter;
import com.nepxion.discovery.plugin.strategy.extension.DiscoveryEnabledExtension; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewayStrategyContext; import com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewayStrategyContext;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter { public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
@Autowired(required = false) @Autowired(required = false)
private DiscoveryEnabledExtension discoveryEnabledExtension; private DiscoveryEnabledStrategy discoveryEnabledStrategy;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
...@@ -63,10 +63,10 @@ public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter { ...@@ -63,10 +63,10 @@ public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
} }
private boolean applyExtension(Server server, Map<String, String> metadata) { private boolean applyExtension(Server server, Map<String, String> metadata) {
if (discoveryEnabledExtension == null) { if (discoveryEnabledStrategy == null) {
return true; return true;
} }
return discoveryEnabledExtension.apply(server, metadata); return discoveryEnabledStrategy.apply(server, metadata);
} }
} }
\ No newline at end of file
...@@ -19,12 +19,12 @@ import org.springframework.web.context.request.ServletRequestAttributes; ...@@ -19,12 +19,12 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.util.JsonUtil; import com.nepxion.discovery.common.util.JsonUtil;
import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledAdapter; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledAdapter;
import com.nepxion.discovery.plugin.strategy.extension.DiscoveryEnabledExtension; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter { public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
@Autowired(required = false) @Autowired(required = false)
private DiscoveryEnabledExtension discoveryEnabledExtension; private DiscoveryEnabledStrategy discoveryEnabledStrategy;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
...@@ -68,10 +68,10 @@ public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter { ...@@ -68,10 +68,10 @@ public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
} }
private boolean applyExtension(Server server, Map<String, String> metadata) { private boolean applyExtension(Server server, Map<String, String> metadata) {
if (discoveryEnabledExtension == null) { if (discoveryEnabledStrategy == null) {
return true; return true;
} }
return discoveryEnabledExtension.apply(server, metadata); return discoveryEnabledStrategy.apply(server, metadata);
} }
} }
\ No newline at end of file
...@@ -17,13 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,13 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.util.JsonUtil; import com.nepxion.discovery.common.util.JsonUtil;
import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledAdapter; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledAdapter;
import com.nepxion.discovery.plugin.strategy.extension.DiscoveryEnabledExtension; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter { public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
@Autowired(required = false) @Autowired(required = false)
private DiscoveryEnabledExtension discoveryEnabledExtension; private DiscoveryEnabledStrategy discoveryEnabledStrategy;
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
...@@ -63,10 +63,10 @@ public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter { ...@@ -63,10 +63,10 @@ public class VersionDiscoveryEnabledAdapter implements DiscoveryEnabledAdapter {
} }
private boolean applyExtension(Server server, Map<String, String> metadata) { private boolean applyExtension(Server server, Map<String, String> metadata) {
if (discoveryEnabledExtension == null) { if (discoveryEnabledStrategy == null) {
return true; return true;
} }
return discoveryEnabledExtension.apply(server, metadata); return discoveryEnabledStrategy.apply(server, metadata);
} }
} }
\ No newline at end of file
package com.nepxion.discovery.plugin.strategy.extension; package com.nepxion.discovery.plugin.strategy.adapter;
/** /**
* <p>Title: Nepxion Discovery</p> * <p>Title: Nepxion Discovery</p>
...@@ -13,6 +13,6 @@ import java.util.Map; ...@@ -13,6 +13,6 @@ import java.util.Map;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
public interface DiscoveryEnabledExtension { public interface DiscoveryEnabledStrategy {
boolean apply(Server server, Map<String, String> metadata); boolean apply(Server server, Map<String, String> metadata);
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -14,7 +14,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.gateway.extension.MyDiscoveryEnabledExtension; import com.nepxion.discovery.plugin.example.gateway.extension.MyDiscoveryEnabledStrategy;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
...@@ -24,8 +24,8 @@ public class DiscoveryApplicationGateway { ...@@ -24,8 +24,8 @@ public class DiscoveryApplicationGateway {
} }
@Bean @Bean
public MyDiscoveryEnabledExtension myDiscoveryEnabledExtension() { public MyDiscoveryEnabledStrategy myDiscoveryEnabledStrategy() {
return new MyDiscoveryEnabledExtension(); return new MyDiscoveryEnabledStrategy();
} }
/*@Bean /*@Bean
......
...@@ -15,13 +15,13 @@ import org.apache.commons.lang3.StringUtils; ...@@ -15,13 +15,13 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.nepxion.discovery.plugin.strategy.extension.DiscoveryEnabledExtension; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewayStrategyContext; import com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewayStrategyContext;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
// 实现了组合策略,版本路由策略+自定义策略 // 实现了组合策略,版本路由策略+自定义策略
public class MyDiscoveryEnabledExtension implements DiscoveryEnabledExtension { public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
private static final Logger LOG = LoggerFactory.getLogger(MyDiscoveryEnabledExtension.class); private static final Logger LOG = LoggerFactory.getLogger(MyDiscoveryEnabledStrategy.class);
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
......
...@@ -18,7 +18,7 @@ import org.springframework.context.annotation.Bean; ...@@ -18,7 +18,7 @@ import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.service.extension.MyDiscoveryListener; import com.nepxion.discovery.plugin.example.service.extension.MyDiscoveryListener;
import com.nepxion.discovery.plugin.example.service.extension.MyLoadBalanceListener; import com.nepxion.discovery.plugin.example.service.extension.MyLoadBalanceListener;
import com.nepxion.discovery.plugin.example.service.extension.MyRegisterListener; import com.nepxion.discovery.plugin.example.service.extension.MyRegisterListener;
import com.nepxion.discovery.plugin.example.service.extension.MyDiscoveryEnabledExtension; import com.nepxion.discovery.plugin.example.service.extension.MyDiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.example.service.extension.MySubscriber; import com.nepxion.discovery.plugin.example.service.extension.MySubscriber;
@SpringBootApplication @SpringBootApplication
...@@ -52,7 +52,7 @@ public class DiscoveryApplicationA1 { ...@@ -52,7 +52,7 @@ public class DiscoveryApplicationA1 {
} }
@Bean @Bean
public MyDiscoveryEnabledExtension myDiscoveryEnabledExtension() { public MyDiscoveryEnabledStrategy myDiscoveryEnabledStrategy() {
return new MyDiscoveryEnabledExtension(); return new MyDiscoveryEnabledStrategy();
} }
} }
\ No newline at end of file
...@@ -18,14 +18,14 @@ import org.springframework.web.context.request.RequestContextHolder; ...@@ -18,14 +18,14 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import com.nepxion.discovery.common.constant.DiscoveryConstant; import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.plugin.strategy.extension.DiscoveryEnabledExtension; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.nepxion.discovery.plugin.strategy.extension.service.constant.ServiceStrategyConstant; import com.nepxion.discovery.plugin.strategy.extension.service.constant.ServiceStrategyConstant;
import com.nepxion.discovery.plugin.strategy.extension.service.context.ServiceStrategyContext; import com.nepxion.discovery.plugin.strategy.extension.service.context.ServiceStrategyContext;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
// 实现了组合策略,版本路由策略+自定义策略 // 实现了组合策略,版本路由策略+自定义策略
public class MyDiscoveryEnabledExtension implements DiscoveryEnabledExtension { public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
private static final Logger LOG = LoggerFactory.getLogger(MyDiscoveryEnabledExtension.class); private static final Logger LOG = LoggerFactory.getLogger(MyDiscoveryEnabledStrategy.class);
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
......
...@@ -15,7 +15,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; ...@@ -15,7 +15,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.zuul.extension.MyDiscoveryEnabledExtension; import com.nepxion.discovery.plugin.example.zuul.extension.MyDiscoveryEnabledStrategy;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
...@@ -26,7 +26,7 @@ public class DiscoveryApplicationZuul { ...@@ -26,7 +26,7 @@ public class DiscoveryApplicationZuul {
} }
@Bean @Bean
public MyDiscoveryEnabledExtension myDiscoveryEnabledExtension() { public MyDiscoveryEnabledStrategy myDiscoveryEnabledStrategy() {
return new MyDiscoveryEnabledExtension(); return new MyDiscoveryEnabledStrategy();
} }
} }
\ No newline at end of file
...@@ -15,13 +15,13 @@ import org.apache.commons.lang3.StringUtils; ...@@ -15,13 +15,13 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.nepxion.discovery.plugin.strategy.extension.DiscoveryEnabledExtension; import com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
// 实现了组合策略,版本路由策略+自定义策略 // 实现了组合策略,版本路由策略+自定义策略
public class MyDiscoveryEnabledExtension implements DiscoveryEnabledExtension { public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
private static final Logger LOG = LoggerFactory.getLogger(MyDiscoveryEnabledExtension.class); private static final Logger LOG = LoggerFactory.getLogger(MyDiscoveryEnabledStrategy.class);
@Override @Override
public boolean apply(Server server, Map<String, String> metadata) { public boolean apply(Server server, Map<String, String> metadata) {
......
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