Browse Source

Moves to ApplicationListener away from @EventListener

pull/514/head
Spencer Gibb 6 years ago
parent
commit
2a7df6ef95
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 11
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java
  2. 11
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java

11
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java

@ -21,16 +21,16 @@ import java.util.HashMap; @@ -21,16 +21,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.ApplicationListener;
import reactor.cache.CacheFlux;
import reactor.core.publisher.Flux;
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.context.event.EventListener;
/**
* @author Spencer Gibb
*/
public class CachingRouteDefinitionLocator implements RouteDefinitionLocator {
public class CachingRouteDefinitionLocator implements RouteDefinitionLocator, ApplicationListener<RefreshRoutesEvent> {
private final RouteDefinitionLocator delegate;
private final Flux<RouteDefinition> routeDefinitions;
@ -57,7 +57,12 @@ public class CachingRouteDefinitionLocator implements RouteDefinitionLocator { @@ -57,7 +57,12 @@ public class CachingRouteDefinitionLocator implements RouteDefinitionLocator {
return this.routeDefinitions;
}
@EventListener(RefreshRoutesEvent.class)
@Override
public void onApplicationEvent(RefreshRoutesEvent event) {
refresh();
}
@Deprecated
/* for testing */ void handleRefresh() {
refresh();
}

11
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java

@ -21,17 +21,17 @@ import java.util.HashMap; @@ -21,17 +21,17 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.ApplicationListener;
import reactor.cache.CacheFlux;
import reactor.core.publisher.Flux;
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
/**
* @author Spencer Gibb
*/
public class CachingRouteLocator implements RouteLocator {
public class CachingRouteLocator implements RouteLocator, ApplicationListener<RefreshRoutesEvent> {
private final RouteLocator delegate;
private final Flux<Route> routes;
@ -57,7 +57,12 @@ public class CachingRouteLocator implements RouteLocator { @@ -57,7 +57,12 @@ public class CachingRouteLocator implements RouteLocator {
return this.routes;
}
@EventListener(RefreshRoutesEvent.class)
@Override
public void onApplicationEvent(RefreshRoutesEvent event) {
refresh();
}
@Deprecated
/* for testing */ void handleRefresh() {
refresh();
}

Loading…
Cancel
Save