in folsom/src/main/java/com/spotify/folsom/ketama/ResolvingKetamaClient.java [211:248]
private void setPendingClient(final ImmutableList.Builder<RawMemcacheClient> removedClients) {
shutdownQueue.addAll(removedClients.build());
final List<AddressAndClient> addressAndClients =
clients
.entrySet()
.stream()
.map(e -> new AddressAndClient(e.getKey(), e.getValue()))
.collect(Collectors.toList());
// This may invalidate an existing pendingClient but should be fine since it doesn't have any
// important state of its own.
final KetamaMemcacheClient newClient =
new KetamaMemcacheClient(addressAndClients, nodeLocator.apply(addressAndClients));
this.pendingClient = newClient;
newClient
.connectFuture()
.thenRun(
() -> {
final ImmutableList<RawMemcacheClient> shutdownJob;
synchronized (sync) {
if (pendingClient != newClient) {
// We don't care about this event if it's not the expected client
return;
}
currentClient = newClient;
pendingClient = null;
shutdownJob = ImmutableList.copyOf(shutdownQueue);
shutdownQueue.clear();
}
executor.schedule(
() -> shutdownJob.forEach(RawMemcacheClient::shutdown),
shutdownDelay,
shutdownUnit);
notifyConnectionChange();
});
}