All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.mklinger.qetcher.client.impl.lookup.DynamicServiceUriSupplier Maven / Gradle / Ivy

There is a newer version: 2.0.42.rc
Show newest version
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