@Test public void createsClients() { StyxBackendServiceClientFactory factory = new StyxBackendServiceClientFactory(environment); OriginsInventory originsInventory = newOriginsInventoryBuilder(backendService.id()) .connectionPoolFactory(simplePoolFactory()) .initialOrigins(backendService.origins()) .build(); OriginStatsFactory originStatsFactory = mock(OriginStatsFactory.class); BackendServiceClient client = factory.createClient(backendService, originsInventory, originStatsFactory); assertThat(client, is(instanceOf(StyxBackendServiceClient.class))); }
@Override public BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory) { Configuration styxConfig = environment.configuration(); String originRestrictionCookie = styxConfig.get("originRestrictionCookie").orElse(null); boolean stickySessionEnabled = backendService.stickySessionConfig().stickySessionEnabled(); RetryPolicy retryPolicy = loadRetryPolicy(styxConfig, environment, "retrypolicy.policy.factory", RetryPolicy.class) .orElseGet(() -> defaultRetryPolicy(environment)); LoadBalancer configuredLbStrategy = loadLoadBalancer( styxConfig, environment, "loadBalancing.strategy.factory", LoadBalancer.class, originsInventory) .orElseGet(() -> new BusyConnectionsStrategy(originsInventory)); originsInventory.addOriginsChangeListener(configuredLbStrategy); LoadBalancer loadBalancingStrategy = decorateLoadBalancer( configuredLbStrategy, stickySessionEnabled, originsInventory, originRestrictionCookie ); return new StyxBackendServiceClient.Builder(backendService.id()) .loadBalancer(loadBalancingStrategy) .stickySessionConfig(backendService.stickySessionConfig()) .metricsRegistry(environment.metricRegistry()) .retryPolicy(retryPolicy) .rewriteRules(backendService.rewrites()) .originStatsFactory(originStatsFactory) .originsRestrictionCookieName(originRestrictionCookie) .originIdHeader(environment.styxConfig().styxHeaderConfig().originIdHeaderName()) .build(); }
StyxBackendServiceClientFactory implements BackendServiceClientFactory { @Override public BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory) { Configuration styxConfig = environment.configuration(); String originRestrictionCookie = styxConfig.get("originRestrictionCookie").orElse(null); boolean stickySessionEnabled = backendService.stickySessionConfig().stickySessionEnabled(); RetryPolicy retryPolicy = loadRetryPolicy(styxConfig, environment, "retrypolicy.policy.factory", RetryPolicy.class) .orElseGet(() -> defaultRetryPolicy(environment)); LoadBalancer configuredLbStrategy = loadLoadBalancer( styxConfig, environment, "loadBalancing.strategy.factory", LoadBalancer.class, originsInventory) .orElseGet(() -> new BusyConnectionsStrategy(originsInventory)); originsInventory.addOriginsChangeListener(configuredLbStrategy); LoadBalancer loadBalancingStrategy = decorateLoadBalancer( configuredLbStrategy, stickySessionEnabled, originsInventory, originRestrictionCookie ); return new StyxBackendServiceClient.Builder(backendService.id()) .loadBalancer(loadBalancingStrategy) .stickySessionConfig(backendService.stickySessionConfig()) .metricsRegistry(environment.metricRegistry()) .retryPolicy(retryPolicy) .rewriteRules(backendService.rewrites()) .originStatsFactory(originStatsFactory) .originsRestrictionCookieName(originRestrictionCookie) .originIdHeader(environment.styxConfig().styxHeaderConfig().originIdHeaderName()) .build(); } }
StyxBackendServiceClientFactory implements BackendServiceClientFactory { @Override public BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory) { Configuration styxConfig = environment.configuration(); String originRestrictionCookie = styxConfig.get("originRestrictionCookie").orElse(null); boolean stickySessionEnabled = backendService.stickySessionConfig().stickySessionEnabled(); RetryPolicy retryPolicy = loadRetryPolicy(styxConfig, environment, "retrypolicy.policy.factory", RetryPolicy.class) .orElseGet(() -> defaultRetryPolicy(environment)); LoadBalancer configuredLbStrategy = loadLoadBalancer( styxConfig, environment, "loadBalancing.strategy.factory", LoadBalancer.class, originsInventory) .orElseGet(() -> new BusyConnectionsStrategy(originsInventory)); originsInventory.addOriginsChangeListener(configuredLbStrategy); LoadBalancer loadBalancingStrategy = decorateLoadBalancer( configuredLbStrategy, stickySessionEnabled, originsInventory, originRestrictionCookie ); return new StyxBackendServiceClient.Builder(backendService.id()) .loadBalancer(loadBalancingStrategy) .stickySessionConfig(backendService.stickySessionConfig()) .metricsRegistry(environment.metricRegistry()) .retryPolicy(retryPolicy) .rewriteRules(backendService.rewrites()) .originStatsFactory(originStatsFactory) .originsRestrictionCookieName(originRestrictionCookie) .originIdHeader(environment.styxConfig().styxHeaderConfig().originIdHeaderName()) .build(); } StyxBackendServiceClientFactory(Environment environment); }
StyxBackendServiceClientFactory implements BackendServiceClientFactory { @Override public BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory) { Configuration styxConfig = environment.configuration(); String originRestrictionCookie = styxConfig.get("originRestrictionCookie").orElse(null); boolean stickySessionEnabled = backendService.stickySessionConfig().stickySessionEnabled(); RetryPolicy retryPolicy = loadRetryPolicy(styxConfig, environment, "retrypolicy.policy.factory", RetryPolicy.class) .orElseGet(() -> defaultRetryPolicy(environment)); LoadBalancer configuredLbStrategy = loadLoadBalancer( styxConfig, environment, "loadBalancing.strategy.factory", LoadBalancer.class, originsInventory) .orElseGet(() -> new BusyConnectionsStrategy(originsInventory)); originsInventory.addOriginsChangeListener(configuredLbStrategy); LoadBalancer loadBalancingStrategy = decorateLoadBalancer( configuredLbStrategy, stickySessionEnabled, originsInventory, originRestrictionCookie ); return new StyxBackendServiceClient.Builder(backendService.id()) .loadBalancer(loadBalancingStrategy) .stickySessionConfig(backendService.stickySessionConfig()) .metricsRegistry(environment.metricRegistry()) .retryPolicy(retryPolicy) .rewriteRules(backendService.rewrites()) .originStatsFactory(originStatsFactory) .originsRestrictionCookieName(originRestrictionCookie) .originIdHeader(environment.styxConfig().styxHeaderConfig().originIdHeaderName()) .build(); } StyxBackendServiceClientFactory(Environment environment); @Override BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory); }
StyxBackendServiceClientFactory implements BackendServiceClientFactory { @Override public BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory) { Configuration styxConfig = environment.configuration(); String originRestrictionCookie = styxConfig.get("originRestrictionCookie").orElse(null); boolean stickySessionEnabled = backendService.stickySessionConfig().stickySessionEnabled(); RetryPolicy retryPolicy = loadRetryPolicy(styxConfig, environment, "retrypolicy.policy.factory", RetryPolicy.class) .orElseGet(() -> defaultRetryPolicy(environment)); LoadBalancer configuredLbStrategy = loadLoadBalancer( styxConfig, environment, "loadBalancing.strategy.factory", LoadBalancer.class, originsInventory) .orElseGet(() -> new BusyConnectionsStrategy(originsInventory)); originsInventory.addOriginsChangeListener(configuredLbStrategy); LoadBalancer loadBalancingStrategy = decorateLoadBalancer( configuredLbStrategy, stickySessionEnabled, originsInventory, originRestrictionCookie ); return new StyxBackendServiceClient.Builder(backendService.id()) .loadBalancer(loadBalancingStrategy) .stickySessionConfig(backendService.stickySessionConfig()) .metricsRegistry(environment.metricRegistry()) .retryPolicy(retryPolicy) .rewriteRules(backendService.rewrites()) .originStatsFactory(originStatsFactory) .originsRestrictionCookieName(originRestrictionCookie) .originIdHeader(environment.styxConfig().styxHeaderConfig().originIdHeaderName()) .build(); } StyxBackendServiceClientFactory(Environment environment); @Override BackendServiceClient createClient(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory);  }