Skip to content

Commit

Permalink
loadbalancer-experimental: remove the generic load balancer factory m…
Browse files Browse the repository at this point in the history
…ethods (#2865)

Motivation:

The LoadBalancerFactory has methods that are generic in type T extends
LoadBalancedConnection which are deprecated. The generic type is infectious
and doesn't serve a concrete purpose, thus why the methods are deprecated.

Modifications:

- drop support for the deprecated factory methods
- drop the generics that were required in the LoadBalancerPolicy interface

Result:

Cleaner code.
  • Loading branch information
bryce-anderson authored Mar 8, 2024
1 parent dabaabc commit 7c0815c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,23 @@ private static final class DefaultLoadBalancerFactory<ResolvedAddress, C extends
public <T extends C> LoadBalancer<T> newLoadBalancer(String targetResource,
Publisher<? extends Collection<? extends ServiceDiscovererEvent<ResolvedAddress>>> eventPublisher,
ConnectionFactory<ResolvedAddress, T> connectionFactory) {
return new DefaultLoadBalancer<ResolvedAddress, T>(id, targetResource, eventPublisher,
throw new UnsupportedOperationException("Generic constructor not supported by " +
DefaultLoadBalancer.class.getSimpleName());
}

@Override
public <T extends C> LoadBalancer<T> newLoadBalancer(
Publisher<? extends ServiceDiscovererEvent<ResolvedAddress>> eventPublisher,
ConnectionFactory<ResolvedAddress, T> connectionFactory) {
throw new UnsupportedOperationException("Generic constructor not supported by " +
DefaultLoadBalancer.class.getSimpleName());
}

@Override
public LoadBalancer<C> newLoadBalancer(
Publisher<? extends Collection<? extends ServiceDiscovererEvent<ResolvedAddress>>> eventPublisher,
ConnectionFactory<ResolvedAddress, C> connectionFactory, String targetResource) {
return new DefaultLoadBalancer<>(id, targetResource, eventPublisher,
loadBalancingPolicy.buildSelector(Collections.emptyList(), targetResource), connectionFactory,
linearSearchSpace, loadBalancerObserver, healthCheckConfig, healthCheckerFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public interface LoadBalancingPolicy<ResolvedAddress, C extends LoadBalancedConn
* @param hosts the set of {@link Host}s to select from.
* @param targetResource the name of the target resource, useful for debugging purposes.
* @return a {@link HostSelector}
* @param <T> the refined type of the connections over which to load balance
*/
<T extends C> HostSelector<ResolvedAddress, T> buildSelector(
List<Host<ResolvedAddress, T>> hosts, String targetResource);
HostSelector<ResolvedAddress, C> buildSelector(
List<Host<ResolvedAddress, C>> hosts, String targetResource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private P2CLoadBalancingPolicy(final int maxEffort, final boolean failOpen, @Nul
}

@Override
public <T extends C> HostSelector<ResolvedAddress, T> buildSelector(
List<Host<ResolvedAddress, T>> hosts, String targetResource) {
public HostSelector<ResolvedAddress, C> buildSelector(
List<Host<ResolvedAddress, C>> hosts, String targetResource) {
return new P2CSelector<>(hosts, targetResource, maxEffort, failOpen, random);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ private RoundRobinLoadBalancingPolicy(final boolean failOpen) {
}

@Override
public <T extends C> HostSelector<ResolvedAddress, T>
buildSelector(final List<Host<ResolvedAddress, T>> hosts, final String targetResource) {
public HostSelector<ResolvedAddress, C>
buildSelector(final List<Host<ResolvedAddress, C>> hosts, final String targetResource) {
return new RoundRobinSelector<>(hosts, targetResource, failOpen);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public String name() {
}

@Override
public <T extends TestLoadBalancedConnection> HostSelector<String, T> buildSelector(
List<Host<String, T>> hosts, String targetResource) {
public HostSelector<String, TestLoadBalancedConnection> buildSelector(
List<Host<String, TestLoadBalancedConnection>> hosts, String targetResource) {
return new TestSelector(hosts);
}

Expand Down

0 comments on commit 7c0815c

Please sign in to comment.