Browse Source

Removes Objects.requireNonNull()

pull/643/head
Spencer Gibb 5 years ago
parent
commit
3fe7725fca
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 5
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerExchangeFilterFunction.java
  2. 24
      spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/CachingServiceInstanceListSupplier.java

5
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerExchangeFilterFunction.java

@ -17,7 +17,6 @@ @@ -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; @@ -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 @@ -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));

24
spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/CachingServiceInstanceListSupplier.java

@ -17,8 +17,9 @@ @@ -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; @@ -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 @@ -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 @@ -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());
}

Loading…
Cancel
Save