Skip to content

Commit

Permalink
Moves to ApplicationListener away from @eventlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Aug 22, 2018
1 parent a31f4ca commit 2a7df6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
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;
Expand All @@ -57,7 +57,12 @@ public Flux<RouteDefinition> refresh() {
return this.routeDefinitions;
}

@EventListener(RefreshRoutesEvent.class)
@Override
public void onApplicationEvent(RefreshRoutesEvent event) {
refresh();
}

@Deprecated
/* for testing */ void handleRefresh() {
refresh();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
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;
Expand All @@ -57,7 +57,12 @@ public Flux<Route> refresh() {
return this.routes;
}

@EventListener(RefreshRoutesEvent.class)
@Override
public void onApplicationEvent(RefreshRoutesEvent event) {
refresh();
}

@Deprecated
/* for testing */ void handleRefresh() {
refresh();
}
Expand Down

0 comments on commit 2a7df6e

Please sign in to comment.