public RouteStates( Stream<ProxyRouteConfig> proxyRouteConfigs, ApplicationState applicationState, ProxyClientFactory clientFactory) { List<ProxyRouteState> proxyRouteStates = proxyRouteConfigs .map( (ProxyRouteConfig config) -> ProxyRouteState.create( applicationState, config, new PersistentProxyHandler( clientFactory, config, new SocketAddressHelper()))) .collect(Collectors.toList()); LinkedHashMap<String, ProxyRouteState> routeMap = new LinkedHashMap<>(); proxyRouteStates.forEach((ProxyRouteState state) -> routeMap.put(state.path(), state)); this.routeMap = new AtomicReference<>(ImmutableMap.copyOf(routeMap)); }
public static ProxyRouteState create( ApplicationState state, ProxyRouteConfig config, ProxyHandler handler) { List<ClientConfig> configs = config.clientConfigs(); List<ClientState> clientStates = configs .stream() .map(clientConfig -> new ClientState(clientConfig, state.workerGroup())) .collect(Collectors.toList()); return new ProxyRouteState(config, handler, clientStates); }
@Override public ChannelHandler getApplicationRouter() { return new PipelineRouter( ImmutableMap.of( "none", ProxyRouteState.create( appState, proxyConfig, new ProxyHandler( factory, proxyConfig, new SocketAddressHelper())))); } });
EdgeProxyState(EdgeProxyConfig config) { super(config); clientFactory = new ProxyClientFactory(this); routeStates = new RouteStates<ProxyRouteState>( // create an ImmutableMap from ... ImmutableMap.copyOf( config .routeConfigs // iterate over a stream of ProxyRouteConfig .stream() // for each ProxyRouteConfig create a ProxyRouteState .map( (ProxyRouteConfig prConfig) -> ProxyRouteState.create( this, prConfig, new ProxyHandler( clientFactory, prConfig, new SocketAddressHelper()))) // collect the stream of ProxyRouteState into // LinkedHashMap<String, ProxyRouteState> where the // route path is the key and // ProxyRouteState is the value .collect(toLinkedMap(RouteState::path, state -> state)))); }