de.mklinger.qetcher.client.impl.lookup.DynamicServiceUriSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qetcher-client-bundle Show documentation
Show all versions of qetcher-client-bundle Show documentation
Qetcher Java client, OSGi bundle, minimal dependencies
package de.mklinger.qetcher.client.impl.lookup;
import java.net.URI;
import java.util.List;
import de.mklinger.qetcher.client.model.v1.AvailableNode;
import de.mklinger.qetcher.client.model.v1.NodeAddress;
/**
* @author Marc Klinger - mklinger[at]mklinger[dot]de
*/
public class DynamicServiceUriSupplier extends StaticServiceUriSupplier {
private final NodesHolder nodesHolder;
public DynamicServiceUriSupplier(final List initialServiceUris) {
super(initialServiceUris);
this.nodesHolder = new NodesHolder();
}
public NodesHolder getNodesHolder() {
return nodesHolder;
}
@Override
public URI get() {
return nodesHolder.getRandomNode()
.map(AvailableNode::getAddress)
.map(this::toHttpsUriString)
.map(URI::create)
.orElseGet(super::get);
}
private String toHttpsUriString(final NodeAddress nodeAddress) {
return "https://" + nodeAddress.toUriString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy