Add RandomUpstreamResolver
This commit is contained in:
parent
74e9b546bc
commit
c7d8712ab5
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user