io.tarantool.driver.api.TarantoolClientFactory 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.api;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.core.TarantoolClientBuilderImpl;
import io.tarantool.driver.core.TarantoolClientConfiguratorImpl;
/**
* Tarantool client factory interface.
*
* It provides a builder interface helping to create the basic Tarantool client types while hiding the internal client
* implementation details from the user.
*
*
* Here are some examples of using this client factory:
*
*
*
* // Create a client instance with default settings. This client can connect to a local Tarantool process listening the
* default port 3301 (do not forget enabling it by executing this command in console: `box.cfg{ listen = 3301 }`).
* TarantoolClientFactory.createClient().build();
*
* // Create a client instance for a single server with custom credentials
* TarantoolClientFactory.createClient()
* .withAddress(new TarantoolServerAddress("123.123.123.123", 3333))
* .withCredentials(new SimpleTarantoolCredentials("root", "passwd"))
* .build();
*
* // Create a client instance with custom proxy operations mapping
* TarantoolClientFactory.createClient()
* .withAddress(new TarantoolServerAddress("123.123.123.123", 3333))
* .withCredentials(new SimpleTarantoolCredentials("root", "passwd"))
* .withProxyMethodMapping(builder -> builder.withDeleteFunctionName("custom_delete"))
* .build();
*
* // Create a client instance with request retry policy
* TarantoolClientFactory.createClient()
* .withAddress(new TarantoolServerAddress("123.123.123.123", 3333))
* .withCredentials(new SimpleTarantoolCredentials("root", "passwd"))
* .withRetryingByNumberOfAttempts(5, throwable -> throwable.getMessage().equals("Some error"),
* policy -> policy.withDelay(500)
* .withRequestTimeout(1000)
* .withConnectionSelectionStrategy(PARALLEL_ROUND_ROBIN)
* .build();
*
* // Create a client instance with proxy operations mapping and request retry policy
* TarantoolClientFactory.createClient()
* .withAddress(new TarantoolServerAddress("123.123.123.123", 3333))
* .withCredentials(new SimpleTarantoolCredentials("root", "passwd"))
* .withConnectionSelectionStrategy(PARALLEL_ROUND_ROBIN)
* .withProxyMethodMapping(builder -> builder.withReplaceFunctionName("custom_replace")
* .withTruncateFunctionName("create"))
* .withRetryingByNumberOfAttempts(5, throwable -> throwable.getMessage().equals("Some error"),
* policy -> policy.withDelay(500)
* .withRequestTimeout(1000)
* ).build();
*
* // Create a client instance with request retry policy from an existing configured client
* TarantoolClientFactory.configureClient(client)
* .withRetryingByNumberOfAttempts(5, throwable -> throwable.getMessage().equals("Some error"),
* policy -> policy.withDelay(500)
* .withRequestTimeout(1000)
* ).build();
*
* // Create a client instance with proxy operations mapping from an existing configured client
* TarantoolClientFactory.configureClient(client)
* .withProxyMethodMapping(mapping -> mapping.withDeleteFunctionName("custom_delete"))
* .build();
*
*
*
*
* @author Oleg Kuznetsov
*/
public interface TarantoolClientFactory {
/**
* Create a new client instance. Provides a builder interface.
*
* @return Tarantool client builder {@link TarantoolClientBuilder}
*/
static TarantoolClientBuilder createClient() {
return new TarantoolClientBuilderImpl();
}
/**
* Configure an existing client instance and return a copy of it. Provides a builder interface.
*
* @param client client instance
* @param configurator builder type
* @return Tarantool client configurator {@link TarantoolClientConfigurator}
*/
@SuppressWarnings("unchecked")
static > T configureClient(
TarantoolClient> client) {
return (T) new TarantoolClientConfiguratorImpl<>(client);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy