Skip to content

Commit

Permalink
loadbalancer-experimental: adjust LoadBalancerObserver API (#3140)
Browse files Browse the repository at this point in the history
Modifications:

- Remove default implementation for `onHostSetChanged(Collection)`;
- Change `onNoHostsAvailable()` to
`onNoAvailableHostException(NoAvailableHostException)`;
- Rename `onNoActiveHostsAvailable` to `onNoActiveHostException`;
  • Loading branch information
idelpivnitskiy authored Dec 17, 2024
1 parent 85fd41b commit 4ec119a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.loadbalancer.experimental;

import io.servicetalk.client.api.NoActiveHostException;
import io.servicetalk.client.api.NoAvailableHostException;
import io.servicetalk.client.api.ServiceDiscovererEvent;
import io.servicetalk.loadbalancer.LoadBalancerObserver;

Expand All @@ -42,23 +43,13 @@ public HostObserver hostObserver(Object resolvedAddress) {
return new HostObserverImpl(resolvedAddress);
}

@Override
public void onNoHostsAvailable() {
LOGGER.debug("{}- onNoHostsAvailable()", lbDescription);
}

@Override
public void onServiceDiscoveryEvent(Collection<? extends ServiceDiscovererEvent<?>> events, int oldHostSetSize,
int newHostSetSize) {
LOGGER.debug("{}- onServiceDiscoveryEvent(events: {}, oldHostSetSize: {}, newHostSetSize: {})",
lbDescription, events, oldHostSetSize, newHostSetSize);
}

@Override
public void onNoActiveHostsAvailable(int hostSetSize, NoActiveHostException exception) {
LOGGER.debug("{}- No active hosts available. Host set size: {}.", lbDescription, hostSetSize, exception);
}

@Override
public void onHostSetChanged(Collection<? extends Host> newHosts) {
if (LOGGER.isDebugEnabled()) {
Expand All @@ -73,6 +64,16 @@ public void onHostSetChanged(Collection<? extends Host> newHosts) {
}
}

@Override
public void onNoAvailableHostException(final NoAvailableHostException exception) {
LOGGER.debug("{}- onNoAvailableHostException()", lbDescription, exception);
}

@Override
public void onNoActiveHostException(int hostSetSize, NoActiveHostException exception) {
LOGGER.debug("{}- onNoActiveHostException(hostSetSize: {})", lbDescription, hostSetSize, exception);
}

private final class HostObserverImpl implements HostObserver {

private final Object resolvedAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,10 @@ private Single<C> selectConnection0(final Predicate<C> selector, @Nullable final
subscribeToEvents(true);
}
}
loadBalancerObserver.onNoActiveHostsAvailable(
loadBalancerObserver.onNoActiveHostException(
currentHostSelector.hostSetSize(), (NoActiveHostException) exn);
} else if (exn instanceof NoAvailableHostException) {
loadBalancerObserver.onNoHostsAvailable();
loadBalancerObserver.onNoAvailableHostException((NoAvailableHostException) exn);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.loadbalancer;

import io.servicetalk.client.api.NoActiveHostException;
import io.servicetalk.client.api.NoAvailableHostException;
import io.servicetalk.client.api.ServiceDiscovererEvent;

import java.util.Collection;
Expand Down Expand Up @@ -49,20 +50,20 @@ void onServiceDiscoveryEvent(Collection<? extends ServiceDiscovererEvent<?>> eve
* algorithm may use.
* @param newHosts the new set of hosts used by the selection algorithm.
*/
default void onHostSetChanged(Collection<? extends Host> newHosts) {
}
void onHostSetChanged(Collection<? extends Host> newHosts);

/**
* Callback for when connection selection fails due to no hosts being available.
* @param exception an exception with more details about the failure.
*/
void onNoHostsAvailable();
void onNoAvailableHostException(NoAvailableHostException exception);

/**
* Callback for when connection selection fails due to all hosts being inactive.
* @param hostSetSize the size of the current host set.
* @param hostSetSize the size of the current host set where all hosts are inactive.
* @param exception an exception with more details about the failure.
*/
void onNoActiveHostsAvailable(int hostSetSize, NoActiveHostException exception);
void onNoActiveHostException(int hostSetSize, NoActiveHostException exception);

/**
* An observer for {@link io.servicetalk.loadbalancer.Host} events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.loadbalancer;

import io.servicetalk.client.api.NoActiveHostException;
import io.servicetalk.client.api.NoAvailableHostException;
import io.servicetalk.client.api.ServiceDiscovererEvent;

import java.util.Collection;
Expand All @@ -36,23 +37,23 @@ public HostObserver hostObserver(Object resolvedAddress) {
}

@Override
public void onNoHostsAvailable() {
public void onServiceDiscoveryEvent(Collection<? extends ServiceDiscovererEvent<?>> events,
int oldHostSetSize, int newHostSetSize) {
// noop
}

@Override
public void onNoActiveHostsAvailable(int hostSetSize, NoActiveHostException exn) {
public void onHostSetChanged(Collection<? extends Host> newHosts) {
// noop
}

@Override
public void onServiceDiscoveryEvent(Collection<? extends ServiceDiscovererEvent<?>> events,
int oldHostSetSize, int newHostSetSize) {
public void onNoAvailableHostException(NoAvailableHostException exception) {
// noop
}

@Override
public void onHostSetChanged(Collection<? extends Host> newHosts) {
public void onNoActiveHostException(int hostSetSize, NoActiveHostException exn) {
// noop
}

Expand Down

0 comments on commit 4ec119a

Please sign in to comment.