in folsom/src/main/java/com/spotify/folsom/authenticate/MultiAuthenticator.java [21:44]
public CompletionStage<RawMemcacheClient> authenticate(RawMemcacheClient client) {
final Iterator<? extends Authenticator> iterator = authenticators.iterator();
CompletionStage<RawMemcacheClient> current = iterator.next().authenticate(client);
while (iterator.hasNext()) {
final Authenticator authenticator = iterator.next();
current =
current
.handle(
(ignore, throwable) -> {
if (throwable == null) {
return CompletableFuture.completedFuture(client);
}
if (throwable.getCause() instanceof MemcacheAuthenticationException) {
return authenticator.authenticate(client);
}
CompletableFuture<RawMemcacheClient> result = new CompletableFuture<>();
result.completeExceptionally(throwable);
return result;
})
.thenCompose(stage -> stage);
}
return current;
}