Class SessionBuilder<SelfT extends SessionBuilder,SessionT>
- java.lang.Object
-
- com.datastax.oss.driver.api.core.session.SessionBuilder<SelfT,SessionT>
-
- Direct Known Subclasses:
CqlSessionBuilder,DseSessionBuilder
@NotThreadSafe public abstract class SessionBuilder<SelfT extends SessionBuilder,SessionT> extends Object
Base implementation to build session instances.You only need to deal with this directly if you use custom driver extensions. For the default session implementation, see
CqlSession.builder().This class is mutable and not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static StringASTRA_PAYLOAD_KEYprotected Callable<InputStream>cloudConfigInputStreamprotected DriverConfigLoaderconfigLoaderprotected CqlIdentifierkeyspaceprotected ProgrammaticArguments.BuilderprogrammaticArgumentsBuilderprotected Set<EndPoint>programmaticContactPointsprotected SelfTself
-
Constructor Summary
Constructors Constructor Description SessionBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description SelfTaddContactEndPoint(EndPoint contactPoint)Adds a contact point to use for the initial connection to the cluster.SelfTaddContactEndPoints(Collection<EndPoint> contactPoints)Adds contact points to use for the initial connection to the cluster.SelfTaddContactPoint(InetSocketAddress contactPoint)Adds a contact point to use for the initial connection to the cluster.SelfTaddContactPoints(Collection<InetSocketAddress> contactPoints)Adds contact points to use for the initial connection to the cluster.SelfTaddNodeStateListener(NodeStateListener nodeStateListener)Registers a node state listener to use with the session, without removing previously-registered listeners.SelfTaddRequestTracker(RequestTracker requestTracker)Registers a request tracker to use with the session, without removing previously-registered trackers.SelfTaddSchemaChangeListener(SchemaChangeListener schemaChangeListener)Registers a schema change listener to use with the session, without removing previously-registered listeners.SelfTaddTypeCodecs(TypeCodec<?>... typeCodecs)Registers additional codecs for custom type mappings.SessionTbuild()Convenience method to callbuildAsync()and block on the result.CompletionStage<SessionT>buildAsync()Creates the session with the options set by this builder.protected DriverContextbuildContext(DriverConfigLoader configLoader, ProgrammaticArguments programmaticArguments)This must return an instance ofInternalDriverContext(it's not expressed directly in the signature to avoid leaking that type through the protected API).protected DriverContextbuildContext(DriverConfigLoader configLoader, List<TypeCodec<?>> typeCodecs, NodeStateListener nodeStateListener, SchemaChangeListener schemaChangeListener, RequestTracker requestTracker, Map<String,String> localDatacenters, Map<String,Predicate<Node>> nodeFilters, ClassLoader classLoader)Deprecated.this method only exists for backward compatibility (if a subclass written for driver 4.1.0 returns a non-null result, that value will be used).protected CompletionStage<CqlSession>buildDefaultSessionAsync()protected DriverConfigLoaderdefaultConfigLoader()Deprecated.protected DriverConfigLoaderdefaultConfigLoader(ClassLoader classLoader)SelfTwithApplicationName(String applicationName)The name of the application using the created session.SelfTwithApplicationVersion(String applicationVersion)The version of the application using the created session.SelfTwithAuthCredentials(String username, String password)Configures the session to use plaintext authentication with the given username and password.SelfTwithAuthCredentials(String username, String password, String authorizationId)Configures the session to use DSE plaintext authentication with the given username and password, and perform proxy authentication with the given authorization id.SelfTwithAuthProvider(AuthProvider authProvider)Registers an authentication provider to use with the session.SelfTwithClassLoader(ClassLoader classLoader)TheClassLoaderto use to reflectively load class names defined in configuration.SelfTwithClientId(UUID clientId)A unique identifier for the created session.SelfTwithClientRoutesConfig(ClientRoutesConfig clientRoutesConfig)Configures this session to use client routes for cloud private-endpoint deployments.SelfTwithCloudProxyAddress(InetSocketAddress cloudProxyAddress)Configures this SessionBuilder to use the provided Cloud proxy endpoint.SelfTwithCloudSecureConnectBundle(InputStream cloudConfigInputStream)Configures this SessionBuilder for Cloud deployments by retrieving connection information from the providedInputStream.SelfTwithCloudSecureConnectBundle(URL cloudConfigUrl)Configures this SessionBuilder for Cloud deployments by retrieving connection information from the providedURL.SelfTwithCloudSecureConnectBundle(Path cloudConfigPath)Configures this SessionBuilder for Cloud deployments by retrieving connection information from the providedPath.SelfTwithCodecRegistry(MutableCodecRegistry codecRegistry)Registers a CodecRegistry to use for the session.SelfTwithConfigLoader(DriverConfigLoader configLoader)Sets the configuration loader to use.SelfTwithCredentials(String username, String password)Deprecated.this method only exists to ease the transition from driver 3, it is an alias forwithAuthCredentials(String, String).SelfTwithCredentials(String username, String password, String authorizationId)Deprecated.this method only exists to ease the transition from driver 3, it is an alias forwithAuthCredentials(String, String,String).SelfTwithKeyspace(CqlIdentifier keyspace)Sets the keyspace to connect the session to.SelfTwithKeyspace(String keyspaceName)Shortcut forsetKeyspace(CqlIdentifier.fromCql(keyspaceName))SelfTwithLocalDatacenter(String localDatacenter)Alias towithLocalDatacenter(String, String)for the default profile.SelfTwithLocalDatacenter(String profileName, String localDatacenter)Specifies the datacenter that is considered "local" by the load balancing policy.SelfTwithMetricRegistry(Object metricRegistry)The metric registry object for storing driver metrics.SelfTwithNodeDistanceEvaluator(NodeDistanceEvaluator nodeDistanceEvaluator)Alias towithNodeDistanceEvaluator(String, NodeDistanceEvaluator)for the default profile.SelfTwithNodeDistanceEvaluator(String profileName, NodeDistanceEvaluator nodeDistanceEvaluator)Adds a customNodeDistanceEvaluatorfor a particular execution profile.SelfTwithNodeFilter(String profileName, Predicate<Node> nodeFilter)Deprecated.SelfTwithNodeFilter(Predicate<Node> nodeFilter)Deprecated.UsewithNodeDistanceEvaluator(NodeDistanceEvaluator)instead.SelfTwithNodeStateListener(NodeStateListener nodeStateListener)Registers a node state listener to use with the session.SelfTwithRequestIdGenerator(RequestIdGenerator requestIdGenerator)Registers a request ID generator.SelfTwithRequestTracker(RequestTracker requestTracker)Registers a request tracker to use with the session.SelfTwithSchemaChangeListener(SchemaChangeListener schemaChangeListener)Registers a schema change listener to use with the session.SelfTwithSslContext(SSLContext sslContext)Configures the session to use SSL with the given context.SelfTwithSslEngineFactory(SslEngineFactory sslEngineFactory)Registers an SSL engine factory for the session.protected abstract SessionTwrap(CqlSession defaultSession)
-
-
-
Field Detail
-
ASTRA_PAYLOAD_KEY
public static final String ASTRA_PAYLOAD_KEY
- See Also:
- Constant Field Values
-
self
protected final SelfT extends SessionBuilder self
-
configLoader
protected DriverConfigLoader configLoader
-
keyspace
protected CqlIdentifier keyspace
-
cloudConfigInputStream
protected Callable<InputStream> cloudConfigInputStream
-
programmaticArgumentsBuilder
protected ProgrammaticArguments.Builder programmaticArgumentsBuilder
-
-
Method Detail
-
withConfigLoader
@NonNull public SelfT withConfigLoader(@Nullable DriverConfigLoader configLoader)
Sets the configuration loader to use.If you don't call this method, the builder will use the default implementation, based on the Typesafe config library. More precisely, configuration properties are loaded and merged from the following (first-listed are higher priority):
- system properties
application.conf(all resources on classpath with this name)application.json(all resources on classpath with this name)application.properties(all resources on classpath with this name)reference.conf(all resources on classpath with this name). In particular, this will load thereference.confincluded in the core driver JAR, that defines default options for all mandatory options.
datastax-java-driversection.This default loader will honor the reload interval defined by the option
basic.config-reload-interval.
-
defaultConfigLoader
@NonNull @Deprecated protected DriverConfigLoader defaultConfigLoader()
Deprecated.
-
defaultConfigLoader
@NonNull protected DriverConfigLoader defaultConfigLoader(@Nullable ClassLoader classLoader)
-
addContactPoints
@NonNull public SelfT addContactPoints(@NonNull Collection<InetSocketAddress> contactPoints)
Adds contact points to use for the initial connection to the cluster.These are addresses of Cassandra nodes that the driver uses to discover the cluster topology. Only one contact point is required (the driver will retrieve the address of the other nodes automatically), but it is usually a good idea to provide more than one contact point, because if that single contact point is unavailable, the driver cannot initialize itself correctly.
Contact points can also be provided statically in the configuration. If both are specified, they will be merged. If both are absent, the driver will default to 127.0.0.1:9042.
Contrary to the configuration, DNS names with multiple A-records will not be handled here. If you need that, extract them manually with
InetAddress.getAllByName(String)before calling this method. Similarly, if you need connect addresses to stay unresolved, make sure you pass unresolved instances here (seeadvanced.resolve-contact-pointsin the configuration for more explanations).
-
addContactPoint
@NonNull public SelfT addContactPoint(@NonNull InetSocketAddress contactPoint)
Adds a contact point to use for the initial connection to the cluster.- See Also:
addContactPoints(Collection)
-
addContactEndPoints
@NonNull public SelfT addContactEndPoints(@NonNull Collection<EndPoint> contactPoints)
Adds contact points to use for the initial connection to the cluster.You only need this method if you use a custom
EndPointimplementation. Otherwise, useaddContactPoints(Collection).
-
addContactEndPoint
@NonNull public SelfT addContactEndPoint(@NonNull EndPoint contactPoint)
Adds a contact point to use for the initial connection to the cluster.You only need this method if you use a custom
EndPointimplementation. Otherwise, useaddContactPoint(InetSocketAddress).
-
addTypeCodecs
@NonNull public SelfT addTypeCodecs(@NonNull TypeCodec<?>... typeCodecs)
Registers additional codecs for custom type mappings.- Parameters:
typeCodecs- neither the individual codecs, nor the vararg array itself, can benull.
-
withNodeStateListener
@NonNull public SelfT withNodeStateListener(@Nullable NodeStateListener nodeStateListener)
Registers a node state listener to use with the session.Listeners can be registered in two ways: either programmatically with this method, or via the configuration using the
advanced.metadata.node-state-listener.classesoption.This method unregisters any previously-registered listener. If you intend to register more than one listener, use
addNodeStateListener(NodeStateListener)instead.
-
addNodeStateListener
@NonNull public SelfT addNodeStateListener(@NonNull NodeStateListener nodeStateListener)
Registers a node state listener to use with the session, without removing previously-registered listeners.Listeners can be registered in two ways: either programmatically with this method, or via the configuration using the
advanced.metadata.node-state-listener.classesoption.Unlike
withNodeStateListener(NodeStateListener), this method adds the new listener to the list of already-registered listeners, thus allowing applications to register multiple listeners. When multiple listeners are registered, they are notified in sequence every time a new listener event is triggered.
-
withSchemaChangeListener
@NonNull public SelfT withSchemaChangeListener(@Nullable SchemaChangeListener schemaChangeListener)
Registers a schema change listener to use with the session.Listeners can be registered in two ways: either programmatically with this method, or via the configuration using the
advanced.metadata.schema-change-listener.classesoption.This method unregisters any previously-registered listener. If you intend to register more than one listener, use
addSchemaChangeListener(SchemaChangeListener)instead.
-
addSchemaChangeListener
@NonNull public SelfT addSchemaChangeListener(@NonNull SchemaChangeListener schemaChangeListener)
Registers a schema change listener to use with the session, without removing previously-registered listeners.Listeners can be registered in two ways: either programmatically with this method, or via the configuration using the
advanced.metadata.schema-change-listener.classesoption.Unlike
withSchemaChangeListener(SchemaChangeListener), this method adds the new listener to the list of already-registered listeners, thus allowing applications to register multiple listeners. When multiple listeners are registered, they are notified in sequence every time a new listener event is triggered.
-
withRequestTracker
@NonNull public SelfT withRequestTracker(@Nullable RequestTracker requestTracker)
Registers a request tracker to use with the session.Trackers can be registered in two ways: either programmatically with this method, or via the configuration using the
advanced.request-tracker.classesoption.This method unregisters any previously-registered tracker. If you intend to register more than one tracker, use
addRequestTracker(RequestTracker)instead.
-
addRequestTracker
@NonNull public SelfT addRequestTracker(@NonNull RequestTracker requestTracker)
Registers a request tracker to use with the session, without removing previously-registered trackers.Trackers can be registered in two ways: either programmatically with this method, or via the configuration using the
advanced.request-tracker.classesoption.Unlike
withRequestTracker(RequestTracker), this method adds the new tracker to the list of already-registered trackers, thus allowing applications to register multiple trackers. When multiple trackers are registered, they are notified in sequence every time a new tracker event is triggered.
-
withRequestIdGenerator
@NonNull public SelfT withRequestIdGenerator(@NonNull RequestIdGenerator requestIdGenerator)
Registers a request ID generator. The driver will use the generated ID in the logs and optionally add to the custom payload so that users can correlate logs about the same request from the Cassandra side.
-
withAuthProvider
@NonNull public SelfT withAuthProvider(@Nullable AuthProvider authProvider)
Registers an authentication provider to use with the session.If the provider is specified programmatically with this method, it overrides the configuration (that is, the
advanced.auth-provider.classoption will be ignored).
-
withAuthCredentials
@NonNull public SelfT withAuthCredentials(@NonNull String username, @NonNull String password)
Configures the session to use plaintext authentication with the given username and password.This methods calls
withAuthProvider(AuthProvider)to register a special provider implementation. Therefore calling it overrides the configuration (that is, theadvanced.auth-provider.classoption will be ignored).Note that this approach holds the credentials in clear text in memory, which makes them vulnerable to an attacker who is able to perform memory dumps. If this is not acceptable for you, consider writing your own
AuthProviderimplementation (PlainTextAuthProviderBaseis a good starting point), and providing it either withwithAuthProvider(AuthProvider)or via the configuration (advanced.auth-provider.class).
-
withAuthCredentials
@NonNull public SelfT withAuthCredentials(@NonNull String username, @NonNull String password, @NonNull String authorizationId)
Configures the session to use DSE plaintext authentication with the given username and password, and perform proxy authentication with the given authorization id.This feature is only available in DataStax Enterprise. If connecting to Apache Cassandra, the authorization id will be ignored; it is recommended to use
withAuthCredentials(String, String)instead.This methods calls
withAuthProvider(AuthProvider)to register a special provider implementation. Therefore calling it overrides the configuration (that is, theadvanced.auth-provider.classoption will be ignored).Note that this approach holds the credentials in clear text in memory, which makes them vulnerable to an attacker who is able to perform memory dumps. If this is not acceptable for you, consider writing your own
AuthProviderimplementation (the internal classPlainTextAuthProviderBaseis a good starting point), and providing it either withwithAuthProvider(AuthProvider)or via the configuration (advanced.auth-provider.class).
-
withCredentials
@Deprecated @NonNull public SelfT withCredentials(@NonNull String username, @NonNull String password)
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forwithAuthCredentials(String, String).
-
withCredentials
@Deprecated @NonNull public SelfT withCredentials(@NonNull String username, @NonNull String password, @NonNull String authorizationId)
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forwithAuthCredentials(String, String,String).
-
withSslEngineFactory
@NonNull public SelfT withSslEngineFactory(@Nullable SslEngineFactory sslEngineFactory)
Registers an SSL engine factory for the session.If the factory is provided programmatically with this method, it overrides the configuration (that is, the
advanced.ssl-engine-factoryoption will be ignored).- See Also:
ProgrammaticSslEngineFactory
-
withSslContext
@NonNull public SelfT withSslContext(@Nullable SSLContext sslContext)
Configures the session to use SSL with the given context.This is a convenience method for clients that already have an
SSLContextinstance. It wraps its argument into aProgrammaticSslEngineFactory, and passes it towithSslEngineFactory(SslEngineFactory).If you use this method, there is no way to customize cipher suites, or turn on host name validation. If you need finer control, use
withSslEngineFactory(SslEngineFactory)directly and pass either your own implementation ofSslEngineFactory, or aProgrammaticSslEngineFactorycreated with custom cipher suites and/or host name validation.Also, note that SSL engines will be created with advisory peer information (
SSLContext.createSSLEngine(String, int)) whenever possible.
-
withLocalDatacenter
public SelfT withLocalDatacenter(@NonNull String profileName, @NonNull String localDatacenter)
Specifies the datacenter that is considered "local" by the load balancing policy.This is a programmatic alternative to the configuration option
basic.load-balancing-policy.local-datacenter. If this method is used, it takes precedence and overrides the configuration.Note that this setting may or may not be relevant depending on the load balancing policy implementation in use. The driver's built-in
DefaultLoadBalancingPolicyrelies on it; if you use a third-party implementation, refer to their documentation.
-
withLocalDatacenter
public SelfT withLocalDatacenter(@NonNull String localDatacenter)
Alias towithLocalDatacenter(String, String)for the default profile.
-
withNodeDistanceEvaluator
@NonNull public SelfT withNodeDistanceEvaluator(@NonNull String profileName, @NonNull NodeDistanceEvaluator nodeDistanceEvaluator)
Adds a customNodeDistanceEvaluatorfor a particular execution profile. This assumes that you're also using a dedicated load balancing policy for that profile.Node distance evaluators are honored by all the driver built-in load balancing policies. If you use a custom policy implementation however, you'll need to explicitly invoke the evaluator whenever appropriate.
If an evaluator is specified programmatically with this method, it overrides the configuration (that is, the
load-balancing-policy.evaluator.classoption will be ignored).
-
withNodeDistanceEvaluator
@NonNull public SelfT withNodeDistanceEvaluator(@NonNull NodeDistanceEvaluator nodeDistanceEvaluator)
Alias towithNodeDistanceEvaluator(String, NodeDistanceEvaluator)for the default profile.
-
withNodeFilter
@Deprecated @NonNull public SelfT withNodeFilter(@NonNull String profileName, @NonNull Predicate<Node> nodeFilter)
Deprecated.Adds a custom filter to include/exclude nodes for a particular execution profile. This assumes that you're also using a dedicated load balancing policy for that profile.The predicate's
test()method will be invoked each time theLoadBalancingPolicyprocesses a topology or state change: if it returns false, the policy will suggest distance IGNORED (meaning the driver won't ever connect to it if all policies agree), and never included in any query plan.Note that this behavior is implemented in the driver built-in load balancing policies. If you use a custom policy implementation, you'll need to explicitly invoke the filter.
If the filter is specified programmatically with this method, it overrides the configuration (that is, the
load-balancing-policy.filter.classoption will be ignored).This method has been deprecated in favor of
withNodeDistanceEvaluator(String, NodeDistanceEvaluator). If you were using node filters, you can easily replace your filters with the following implementation ofNodeDistanceEvaluator:
The same can be achieved using a lambda + closure:public class NodeFilterToDistanceEvaluatorAdapter implements NodeDistanceEvaluator { private final Predicate<Node> nodeFilter; public NodeFilterToDistanceEvaluatorAdapter(Predicate<Node> nodeFilter) { this.nodeFilter = nodeFilter; } public NodeDistance evaluateDistance(Node node, String localDc) { return nodeFilter.test(node) ? null : NodeDistance.IGNORED; } }Predicate<Node> nodeFilter = ... NodeDistanceEvaluator evaluator = (node, localDc) -> nodeFilter.test(node) ? null : NodeDistance.IGNORED;- See Also:
withNodeFilter(Predicate)
-
withNodeFilter
@Deprecated @NonNull public SelfT withNodeFilter(@NonNull Predicate<Node> nodeFilter)
Deprecated.UsewithNodeDistanceEvaluator(NodeDistanceEvaluator)instead.Alias towithNodeFilter(String, Predicate)for the default profile.This method has been deprecated in favor of
withNodeDistanceEvaluator(NodeDistanceEvaluator). See the javadocs ofwithNodeFilter(String, Predicate)to understand how to migrate your legacy node filters.
-
withKeyspace
@NonNull public SelfT withKeyspace(@Nullable CqlIdentifier keyspace)
Sets the keyspace to connect the session to.Note that this can also be provided by the configuration; if both are defined, this method takes precedence.
-
withKeyspace
@NonNull public SelfT withKeyspace(@Nullable String keyspaceName)
Shortcut forsetKeyspace(CqlIdentifier.fromCql(keyspaceName))
-
withClassLoader
@NonNull public SelfT withClassLoader(@Nullable ClassLoader classLoader)
TheClassLoaderto use to reflectively load class names defined in configuration.Unless you define a custom
configLoader, this class loader will also be used to locate application-specific configuration resources.If you do not provide any custom class loader, the driver will attempt to use the following ones:
- When reflectively loading class names defined in configuration: same class loader that loaded the core driver classes.
- When locating application-specific configuration resources: the current thread's context class loader.
Defining a different class loader is typically only needed in web or OSGi environments where there are complex class loading requirements.
For example, if the driver jar is loaded by the web server's system class loader (that is, the driver jar was placed in the "/lib" folder of the web server), but the application tries to load a custom load balancing policy declared in the web app's "WEB-INF/lib" folder, the system class loader will not be able to load such class. Instead, you must use the web app's class loader, that you can obtain by calling
Thread.getContextClassLoader():
Indeed, in most web environments,CqlSession.builder() .addContactEndPoint(...) .withClassLoader(Thread.currentThread().getContextClassLoader()) .build();Thread.currentThread().getContextClassLoader()will return the web app's class loader, which is a child of the web server's system class loader. This class loader is thus capable of loading both the implemented interface and the implementing class, in spite of them being declared in different places.For OSGi deployments, it is usually not necessary to use this method. Even if the implemented interface and the implementing class are located in different bundles, the right class loader to use should be the default one (the driver bundle's class loader). In particular, it is not advised to rely on
Thread.currentThread().getContextClassLoader()in OSGi environments, so you should never pass that class loader to this method. See Using a custom ClassLoader in our OSGi online docs for more information.
-
withCloudSecureConnectBundle
@NonNull public SelfT withCloudSecureConnectBundle(@NonNull Path cloudConfigPath)
Configures this SessionBuilder for Cloud deployments by retrieving connection information from the providedPath.To connect to a Cloud database, you must first download the secure database bundle from the DataStax Astra console that contains the connection information, then instruct the driver to read its contents using either this method or one if its variants.
For more information, please refer to the DataStax Astra documentation.
- Parameters:
cloudConfigPath- Path to the secure connect bundle zip file.- See Also:
withCloudSecureConnectBundle(URL),withCloudSecureConnectBundle(InputStream)
-
withCodecRegistry
@NonNull public SelfT withCodecRegistry(@Nullable MutableCodecRegistry codecRegistry)
Registers a CodecRegistry to use for the session.When both this and
addTypeCodecs(TypeCodec[])are called, the added type codecs will be registered on the provided CodecRegistry.
-
withCloudSecureConnectBundle
@NonNull public SelfT withCloudSecureConnectBundle(@NonNull URL cloudConfigUrl)
Configures this SessionBuilder for Cloud deployments by retrieving connection information from the providedURL.To connect to a Cloud database, you must first download the secure database bundle from the DataStax Astra console that contains the connection information, then instruct the driver to read its contents using either this method or one if its variants.
For more information, please refer to the DataStax Astra documentation.
- Parameters:
cloudConfigUrl- URL to the secure connect bundle zip file.- See Also:
withCloudSecureConnectBundle(Path),withCloudSecureConnectBundle(InputStream)
-
withCloudSecureConnectBundle
@NonNull public SelfT withCloudSecureConnectBundle(@NonNull InputStream cloudConfigInputStream)
Configures this SessionBuilder for Cloud deployments by retrieving connection information from the providedInputStream.To connect to a Cloud database, you must first download the secure database bundle from the DataStax Astra console that contains the connection information, then instruct the driver to read its contents using either this method or one if its variants.
For more information, please refer to the DataStax Astra documentation.
Note that the provided stream will be consumed and closed when either
build()orbuildAsync()are called; attempting to reuse it afterwards will result in an error being thrown.- Parameters:
cloudConfigInputStream- A stream containing the secure connect bundle zip file.- See Also:
withCloudSecureConnectBundle(Path),withCloudSecureConnectBundle(URL)
-
withCloudProxyAddress
@NonNull public SelfT withCloudProxyAddress(@Nullable InetSocketAddress cloudProxyAddress)
Configures this SessionBuilder to use the provided Cloud proxy endpoint.Normally, this method should not be called directly; the normal and easiest way to configure the driver for Cloud deployments is through a secure connect bundle.
Setting this option to any non-null address will make the driver use a special topology monitor tailored for Cloud deployments. This topology monitor assumes that the target cluster should be contacted through the proxy specified here, using SNI routing.
For more information, please refer to the DataStax Astra documentation.
- Parameters:
cloudProxyAddress- The address of the Cloud proxy to use.- See Also:
- Server Name Indication
-
withClientRoutesConfig
@NonNull public SelfT withClientRoutesConfig(@Nullable ClientRoutesConfig clientRoutesConfig)
Configures this session to use client routes for cloud private-endpoint deployments.Client routes enable the driver to discover and connect to nodes through a load balancer (such as AWS PrivateLink, Azure Private Link, or GCP Private Service Connect) by reading endpoint mappings from the
system.client_routestable. Each endpoint is identified by a connection ID and maps to specific node addresses.This configuration is mutually exclusive with a user-provided
AddressTranslator. If both are specified, anIllegalStateExceptionis thrown when the session is built.Example usage:
ClientRoutesConfig config = ClientRoutesConfig.builder() .addEndpoint(new ClientRouteProxy( "12345678-1234-1234-1234-123456789012", "my-cluster-endpoint.example.com")) .build(); CqlSession session = CqlSession.builder() .withClientRoutesConfig(config) .build();- Parameters:
clientRoutesConfig- the client routes configuration to use, ornullto disable client routes.- See Also:
ClientRoutesConfig
-
withClientId
@NonNull public SelfT withClientId(@Nullable UUID clientId)
A unique identifier for the created session.It will be sent in the
STARTUPprotocol message, under the keyCLIENT_ID, for each new connection established by the driver. Currently, this information is used by Insights monitoring (if the target cluster does not support Insights, the entry will be ignored by the server).If you don't call this method, the driver will generate an identifier with
Uuids.random().
-
withApplicationName
@NonNull public SelfT withApplicationName(@Nullable String applicationName)
The name of the application using the created session.It will be sent in the
STARTUPprotocol message, under the keyAPPLICATION_NAME, for each new connection established by the driver. Currently, this information is used by Insights monitoring (if the target cluster does not support Insights, the entry will be ignored by the server).This can also be defined in the driver configuration with the option
basic.application.name; if you specify both, this method takes precedence and the configuration option will be ignored. If neither is specified, the entry is not included in the message.
-
withApplicationVersion
@NonNull public SelfT withApplicationVersion(@Nullable String applicationVersion)
The version of the application using the created session.It will be sent in the
STARTUPprotocol message, under the keyAPPLICATION_VERSION, for each new connection established by the driver. Currently, this information is used by Insights monitoring (if the target cluster does not support Insights, the entry will be ignored by the server).This can also be defined in the driver configuration with the option
basic.application.version; if you specify both, this method takes precedence and the configuration option will be ignored. If neither is specified, the entry is not included in the message.
-
withMetricRegistry
@NonNull public SelfT withMetricRegistry(@Nullable Object metricRegistry)
The metric registry object for storing driver metrics.The argument should be an instance of the base registry type for the metrics framework you are using (see
advanced.metrics.factory.classin the configuration):- Dropwizard (the default):
com.codahale.metrics.MetricRegistry - Micrometer:
io.micrometer.core.instrument.MeterRegistry - MicroProfile:
org.eclipse.microprofile.metrics.MetricRegistry
globalRegistrywill be used. For Dropwizard, if no Registry object is provided, an instance ofMetricRegistrywill be created and used. - Dropwizard (the default):
-
buildAsync
@NonNull public CompletionStage<SessionT> buildAsync()
Creates the session with the options set by this builder.The session initialization will happen asynchronously in a driver internal thread pool.
- Returns:
- a completion stage that completes with the session when it is fully initialized.
-
build
@NonNull public SessionT build()
Convenience method to callbuildAsync()and block on the result.Usage in non-blocking applications: beware that session initialization is a costly operation. It should only be triggered from a thread that is allowed to block. If that is not the case, consider using
buildAsync()instead.This must not be called on a driver thread.
-
wrap
protected abstract SessionT wrap(@NonNull CqlSession defaultSession)
-
buildDefaultSessionAsync
@NonNull protected final CompletionStage<CqlSession> buildDefaultSessionAsync()
-
buildContext
protected DriverContext buildContext(DriverConfigLoader configLoader, ProgrammaticArguments programmaticArguments)
This must return an instance ofInternalDriverContext(it's not expressed directly in the signature to avoid leaking that type through the protected API).
-
buildContext
@Deprecated protected DriverContext buildContext(DriverConfigLoader configLoader, List<TypeCodec<?>> typeCodecs, NodeStateListener nodeStateListener, SchemaChangeListener schemaChangeListener, RequestTracker requestTracker, Map<String,String> localDatacenters, Map<String,Predicate<Node>> nodeFilters, ClassLoader classLoader)
Deprecated.this method only exists for backward compatibility (if a subclass written for driver 4.1.0 returns a non-null result, that value will be used). Please overridebuildContext(DriverConfigLoader, ProgrammaticArguments)instead.
-
-