Add RandomUpstreamResolver

This commit is contained in:
Travis Burtrum 2019-04-13 17:08:56 -04:00
parent 74e9b546bc
commit c7d8712ab5

View File

@ -0,0 +1,31 @@
package com.moparisthebest.dns.resolve;
import com.moparisthebest.dns.dto.Packet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadLocalRandom;
public class RandomUpstreamResolver implements Resolver {
private final Resolver[] delegates;
public RandomUpstreamResolver(final Resolver... delegates) {
this.delegates = delegates;
}
public Resolver random() {
return delegates[ThreadLocalRandom.current().nextInt(delegates.length)];
}
@Override
public <E extends RequestResponse> CompletableFuture<E> resolveAsync(final E requestResponse, final Executor executor) {
return random().resolveAsync(requestResponse, executor);
}
@Override
public Packet resolve(final Packet request) throws Exception {
return random().resolve(request);
}
}