Removes Objects.requireNonNull()
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.client.loadbalancer.reactive;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -41,7 +40,7 @@ import org.springframework.web.reactive.function.client.ExchangeFunction;
|
||||
public class ReactorLoadBalancerExchangeFilterFunction implements ExchangeFilterFunction {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(LoadBalancerExchangeFilterFunction.class);
|
||||
.getLog(ReactorLoadBalancerExchangeFilterFunction.class);
|
||||
|
||||
private final ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerFactory;
|
||||
|
||||
@@ -78,7 +77,7 @@ public class ReactorLoadBalancerExchangeFilterFunction implements ExchangeFilter
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format(
|
||||
"Load balancer has retrieved the instance for service %s: %s",
|
||||
serviceId, Objects.requireNonNull(instance).getUri()));
|
||||
serviceId, instance.getUri()));
|
||||
}
|
||||
ClientRequest newRequest = buildClientRequest(request,
|
||||
LoadBalancerUriTools.reconstructURI(instance, originalUrl));
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
package org.springframework.cloud.loadbalancer.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import reactor.cache.CacheFlux;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -38,6 +39,9 @@ import org.springframework.cloud.client.ServiceInstance;
|
||||
*/
|
||||
public class CachingServiceInstanceListSupplier implements ServiceInstanceListSupplier {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(CachingServiceInstanceListSupplier.class);
|
||||
|
||||
/**
|
||||
* Name of the service cache instance.
|
||||
*/
|
||||
@@ -55,8 +59,13 @@ public class CachingServiceInstanceListSupplier implements ServiceInstanceListSu
|
||||
this.serviceInstances = CacheFlux.lookup(key -> {
|
||||
// TODO: configurable cache name
|
||||
Cache cache = cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME);
|
||||
List<ServiceInstance> list = Objects.requireNonNull(cache).get(key,
|
||||
List.class);
|
||||
if (cache == null) {
|
||||
if (log.isErrorEnabled()) {
|
||||
log.error("Unable to find cache: " + SERVICE_INSTANCE_CACHE_NAME);
|
||||
}
|
||||
return Mono.empty();
|
||||
}
|
||||
List<ServiceInstance> list = cache.get(key, List.class);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return Mono.empty();
|
||||
}
|
||||
@@ -66,7 +75,14 @@ public class CachingServiceInstanceListSupplier implements ServiceInstanceListSu
|
||||
.doOnNext(instances -> {
|
||||
Cache cache = cacheManager
|
||||
.getCache(SERVICE_INSTANCE_CACHE_NAME);
|
||||
Objects.requireNonNull(cache).put(key, instances);
|
||||
if (cache == null) {
|
||||
if (log.isErrorEnabled()) {
|
||||
log.error("Unable to find cache for writing: " + SERVICE_INSTANCE_CACHE_NAME);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cache.put(key, instances);
|
||||
}
|
||||
}).then());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user