@Test public void testReload() { AtomicReference<String> rules = new AtomicReference<>("cell1=(app1.*);cell2=(app2.*)"); RoutingRuleSelector selector = new RoutingRuleSelector(cellInfoResolver, rules::get); assertThat(selector.select("app1", cell -> true)).contains(CELL_1); rules.set("cell1=(app2.*);cell2=(app1.*)"); assertThat(selector.select("app1", cell -> true)).contains(CELL_2); }
Optional<Cell> select(String routeKey, Predicate<Cell> filter) { Map<Cell, Pattern> cellRoutingPatterns = compileRoutingPatterns.apply(routingRulesSupplier.get()); return cellRoutingPatterns.entrySet().stream() .filter(entry -> filter.test(entry.getKey())) .filter(entry -> entry.getValue().matcher(routeKey).matches()) .findFirst() .map(Map.Entry::getKey); }
RoutingRuleSelector { Optional<Cell> select(String routeKey, Predicate<Cell> filter) { Map<Cell, Pattern> cellRoutingPatterns = compileRoutingPatterns.apply(routingRulesSupplier.get()); return cellRoutingPatterns.entrySet().stream() .filter(entry -> filter.test(entry.getKey())) .filter(entry -> entry.getValue().matcher(routeKey).matches()) .findFirst() .map(Map.Entry::getKey); } }
RoutingRuleSelector { Optional<Cell> select(String routeKey, Predicate<Cell> filter) { Map<Cell, Pattern> cellRoutingPatterns = compileRoutingPatterns.apply(routingRulesSupplier.get()); return cellRoutingPatterns.entrySet().stream() .filter(entry -> filter.test(entry.getKey())) .filter(entry -> entry.getValue().matcher(routeKey).matches()) .findFirst() .map(Map.Entry::getKey); } RoutingRuleSelector(CellInfoResolver cellInfoResolver, Supplier<String> routingRulesSupplier); }
RoutingRuleSelector { Optional<Cell> select(String routeKey, Predicate<Cell> filter) { Map<Cell, Pattern> cellRoutingPatterns = compileRoutingPatterns.apply(routingRulesSupplier.get()); return cellRoutingPatterns.entrySet().stream() .filter(entry -> filter.test(entry.getKey())) .filter(entry -> entry.getValue().matcher(routeKey).matches()) .findFirst() .map(Map.Entry::getKey); } RoutingRuleSelector(CellInfoResolver cellInfoResolver, Supplier<String> routingRulesSupplier);  }
RoutingRuleSelector { Optional<Cell> select(String routeKey, Predicate<Cell> filter) { Map<Cell, Pattern> cellRoutingPatterns = compileRoutingPatterns.apply(routingRulesSupplier.get()); return cellRoutingPatterns.entrySet().stream() .filter(entry -> filter.test(entry.getKey())) .filter(entry -> entry.getValue().matcher(routeKey).matches()) .findFirst() .map(Map.Entry::getKey); } RoutingRuleSelector(CellInfoResolver cellInfoResolver, Supplier<String> routingRulesSupplier);   }