code optimization & correct comment (#723)

* code optimization & correct comment

* update changelog
pull/726/head
DerekYRC 2 years ago committed by GitHub
parent 5b60db990b
commit 660c225db2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,3 +9,4 @@
- [Test:support environment variable metadata test](https://github.com/Tencent/spring-cloud-tencent/pull/710)
- [upgrade protobuf-java.version to 3.21.7](https://github.com/Tencent/spring-cloud-tencent/pull/716)
- [docs:update README.](https://github.com/Tencent/spring-cloud-tencent/pull/719)
- [Code optimization & correct comment](https://github.com/Tencent/spring-cloud-tencent/pull/723)

@ -59,7 +59,7 @@ public class PolarisCircuitBreakerAutoConfiguration {
// Turn on circuitbreaker configuration
configuration.getConsumer().getCircuitBreaker().setEnable(true);
// Set excludeCircuitBreakInstances to false
// Set excludeCircuitBreakInstances to true
RecoverRouterConfig recoverRouterConfig = configuration.getConsumer().getServiceRouter()
.getPluginConfig(ServiceRouterConfig.DEFAULT_ROUTER_RECOVER, RecoverRouterConfig.class);

@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -33,6 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.DisposableBean;
/**
* Spring value auto registry.
@ -43,13 +45,14 @@ import org.springframework.beans.factory.BeanFactory;
*
* @author weihubeats 2022-7-10
*/
public class SpringValueRegistry {
public class SpringValueRegistry implements DisposableBean {
private static final Logger logger = LoggerFactory.getLogger(SpringValueRegistry.class);
private static final long CLEAN_INTERVAL_IN_SECONDS = 5;
private final Map<BeanFactory, Multimap<String, SpringValue>> registry = Maps.newConcurrentMap();
private final AtomicBoolean initialized = new AtomicBoolean(false);
private final Object LOCK = new Object();
private ScheduledExecutorService executor;
public void register(BeanFactory beanFactory, String key, SpringValue springValue) {
if (!registry.containsKey(beanFactory)) {
@ -77,8 +80,9 @@ public class SpringValueRegistry {
}
private void initialize() {
Executors.newSingleThreadScheduledExecutor(
new NamedThreadFactory("polaris-spring-value-registry")).scheduleAtFixedRate(
executor = Executors.newSingleThreadScheduledExecutor(
new NamedThreadFactory("polaris-spring-value-registry"));
executor.scheduleAtFixedRate(
() -> {
try {
scanAndClean();
@ -97,4 +101,9 @@ public class SpringValueRegistry {
springValues.entries().removeIf(springValue -> !springValue.getValue().isTargetBeanValid());
}
}
@Override
public void destroy() throws Exception {
executor.shutdown();
}
}

@ -184,6 +184,7 @@ public class PolarisReactiveLoadBalancerClientFilter extends ReactiveLoadBalance
new ResponseData(exchange.getResponse(), new RequestData(exchange.getRequest()))))));
}
@Override
protected URI reconstructURI(ServiceInstance serviceInstance, URI original) {
return LoadBalancerUriTools.reconstructURI(serviceInstance, original);
}

Loading…
Cancel
Save