io.tarantool.driver.TarantoolAddressProviderFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartridge-driver Show documentation
Show all versions of cartridge-driver Show documentation
Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework
package io.tarantool.driver;
import io.tarantool.driver.cluster.BinaryClusterDiscoveryEndpoint;
import io.tarantool.driver.cluster.BinaryDiscoveryClusterAddressProvider;
import io.tarantool.driver.cluster.TarantoolClusterDiscoveryConfig;
import io.tarantool.driver.cluster.HTTPDiscoveryClusterAddressProvider;
import io.tarantool.driver.utils.Assert;
import java.util.Collection;
/**
* Factory for Tarantool address provider instances.
*
* @author Sergey Volgin
* @author Alexey Kuzin
*/
public final class TarantoolAddressProviderFactory {
private TarantoolAddressProviderFactory() {
}
public TarantoolClusterAddressProvider createClusterAddressProvider(Collection nodes) {
Assert.notNull(nodes, "Collection of Tarantool server address should not be null");
Assert.notEmpty(nodes, "Collection of Tarantool server address should not be empty");
return () -> nodes;
}
public TarantoolClusterAddressProvider createClusterAddressProviderWithDiscovery(
Collection nodes, TarantoolClusterDiscoveryConfig config) {
TarantoolClusterAddressProvider addressProvider;
if (config != null) {
if (config.getEndpoint() instanceof BinaryClusterDiscoveryEndpoint) {
addressProvider = new BinaryDiscoveryClusterAddressProvider(config);
} else {
addressProvider = new HTTPDiscoveryClusterAddressProvider(config);
}
} else {
addressProvider = createClusterAddressProvider(nodes);
}
return addressProvider;
}
}