io.tarantool.driver.core.connection.TarantoolClusterConnectionManager 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.core.connection;
import io.tarantool.driver.api.TarantoolClientConfig;
import io.tarantool.driver.api.TarantoolClusterAddressProvider;
import io.tarantool.driver.api.TarantoolServerAddress;
import io.tarantool.driver.api.connection.TarantoolConnectionListeners;
import java.util.Collection;
/**
* Implementation of {@link AbstractTarantoolConnectionManager}, aware of connecting to the Tarantool cluster
*
* @author Alexey Kuzin
*/
public class TarantoolClusterConnectionManager extends AbstractTarantoolConnectionManager {
private final TarantoolClusterAddressProvider addressProvider;
/**
* Basic constructor.
*
* @param config client configuration
* @param connectionFactory manages instantiation of Tarantool server connections
* @param listeners are invoked after connection is established
* @param addressProvider provides Tarantool server nodes addresses
*/
public TarantoolClusterConnectionManager(
TarantoolClientConfig config,
TarantoolConnectionFactory connectionFactory,
TarantoolConnectionListeners listeners,
TarantoolClusterAddressProvider addressProvider) {
super(config, connectionFactory, listeners);
this.addressProvider = addressProvider;
this.addressProvider.setRefreshCallback(this::refreshIfConditionsChanged);
}
private void refreshIfConditionsChanged() {
if (areAddressesChanged() || !areConnectionsAlive()) {
super.refresh();
}
}
@Override
protected Collection getAddresses() {
return addressProvider.getAddresses();
}
@Override
public void close() {
addressProvider.setRefreshCallback(() -> {
});
super.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy