Commit f6871877 by Nepxion

重构类结构

parent e962149a
......@@ -17,6 +17,7 @@ import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.strategy.constant.StrategyConstant;
import com.nepxion.discovery.plugin.strategy.discovery.DiscoveryEnabledAdapter;
import com.nepxion.discovery.plugin.strategy.discovery.DiscoveryEnabledPredicate;
......@@ -27,6 +28,9 @@ import com.nepxion.discovery.plugin.strategy.discovery.DiscoveryEnabledRule;
@ConditionalOnProperty(value = StrategyConstant.SPRING_APPLICATION_STRATEGY_CONTROL_ENABLED, matchIfMissing = true)
public class StrategyAutoConfiguration {
@Autowired
protected PluginAdapter pluginAdapter;
@Autowired
private DiscoveryEnabledAdapter discoveryEnabledAdapter;
@Bean
......@@ -35,6 +39,7 @@ public class StrategyAutoConfiguration {
public DiscoveryEnabledRule discoveryEnabledRule() {
DiscoveryEnabledRule discoveryEnabledRule = new DiscoveryEnabledRule();
DiscoveryEnabledPredicate discoveryEnabledPredicate = discoveryEnabledRule.getDiscoveryEnabledPredicate();
discoveryEnabledPredicate.setPluginAdapter(pluginAdapter);
discoveryEnabledPredicate.setDiscoveryEnabledAdapter(discoveryEnabledAdapter);
return discoveryEnabledRule;
......
......@@ -9,8 +9,10 @@ package com.nepxion.discovery.plugin.strategy.discovery;
* @version 1.0
*/
import java.util.Map;
import com.netflix.loadbalancer.Server;
public interface DiscoveryEnabledAdapter {
boolean apply(Server server);
boolean apply(Server server, Map<String, String> metadata);
}
\ No newline at end of file
......@@ -9,12 +9,16 @@ package com.nepxion.discovery.plugin.strategy.discovery;
* @version 1.0
*/
import java.util.Map;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.netflix.loadbalancer.AbstractServerPredicate;
import com.netflix.loadbalancer.PredicateKey;
import com.netflix.loadbalancer.Server;
public class DiscoveryEnabledPredicate extends AbstractServerPredicate {
private DiscoveryEnabledAdapter discoveryEnabledAdapter;
protected PluginAdapter pluginAdapter;
protected DiscoveryEnabledAdapter discoveryEnabledAdapter;
@Override
public boolean apply(PredicateKey input) {
......@@ -22,7 +26,13 @@ public class DiscoveryEnabledPredicate extends AbstractServerPredicate {
}
protected boolean apply(Server server) {
return discoveryEnabledAdapter.apply(server);
Map<String, String> metadata = pluginAdapter.getServerMetadata(server);
return discoveryEnabledAdapter.apply(server, metadata);
}
public void setPluginAdapter(PluginAdapter pluginAdapter) {
this.pluginAdapter = pluginAdapter;
}
public void setDiscoveryEnabledAdapter(DiscoveryEnabledAdapter discoveryEnabledAdapter) {
......
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