de.mklinger.qetcher.client.impl.lookup.StaticServiceUriSupplier Maven / Gradle / Ivy
package de.mklinger.qetcher.client.impl.lookup;
import java.net.URI;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author Marc Klinger - mklinger[at]mklinger[dot]de
*/
public class StaticServiceUriSupplier implements ServiceUriSupplier {
private final List serviceUris;
public StaticServiceUriSupplier(final List serviceUris) {
this.serviceUris = requireNonEmpty(serviceUris);
}
private static List requireNonEmpty(final List l) {
if (l == null || l.isEmpty()) {
throw new IllegalArgumentException();
}
return l;
}
@Override
public URI get() {
final int randomIdx = ThreadLocalRandom.current()
.nextInt(serviceUris.size());
return serviceUris.get(randomIdx);
}
}