public static class DseCluster.Builder extends Cluster.Builder
DseCluster
instances.Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
DseCluster.Builder |
addContactPoint(String address)
Adds a contact point - or many if the given address resolves to multiple
InetAddress
s (A records). |
DseCluster.Builder |
addContactPoints(Collection<InetAddress> addresses)
Adds contact points.
|
DseCluster.Builder |
addContactPoints(InetAddress... addresses)
Adds contact points.
|
DseCluster.Builder |
addContactPoints(String... addresses)
Adds contact points.
|
DseCluster.Builder |
addContactPointsWithPorts(Collection<InetSocketAddress> addresses)
Adds contact points.
|
DseCluster.Builder |
addContactPointsWithPorts(InetSocketAddress... addresses)
Adds contact points.
|
DseCluster.Builder |
allowBetaProtocolVersion()
Create cluster connection using latest development protocol version, which is currently in
beta.
|
DseCluster |
build()
Builds the cluster with the configured set of initial contact points and policies.
|
DseConfiguration |
getConfiguration()
The configuration that will be used for the new cluster.
|
DseCluster.Builder |
withAddressTranslator(AddressTranslator translator)
Configures the address translator to use for the new cluster.
|
DseCluster.Builder |
withApplicationName(String name)
An optional configuration identifying the name of the application using this cluster.
|
DseCluster.Builder |
withApplicationVersion(String version)
An optional configuration identifying the version of the application using this cluster.
|
DseCluster.Builder |
withAuthProvider(AuthProvider authProvider)
Use the specified AuthProvider when connecting to Cassandra hosts.
|
DseCluster.Builder |
withClientId(UUID id)
An optional configuration for providing a unique identifier for the created client instance.
|
DseCluster.Builder |
withCloudSecureConnectBundle(File cloudConfigFile)
Configures this Builder for Cloud deployments by retrieving connection information from the
provided
String . |
DseCluster.Builder |
withCloudSecureConnectBundle(InputStream cloudConfigInputStream)
Configures this Builder for Cloud deployments by retrieving connection information from the
provided
InputStream . |
DseCluster.Builder |
withCloudSecureConnectBundle(URL cloudConfigUrl)
Configures this Builder for Cloud deployments by retrieving connection information from the
provided
URL . |
DseCluster.Builder |
withClusterId(UUID id)
Deprecated.
Use
withClientId(UUID) } instead. This method was intended to give a
client id not cluster id from the beginning. The withClientId name is more appropriate. |
DseCluster.Builder |
withClusterName(String name)
An optional name for the create cluster.
|
DseCluster.Builder |
withCodecRegistry(CodecRegistry codecRegistry)
Configures the
CodecRegistry instance to use for the new cluster. |
DseCluster.Builder |
withCompression(ProtocolOptions.Compression compression)
Sets the compression to use for the transport.
|
DseCluster.Builder |
withCredentials(String username,
String password)
Uses the provided credentials when connecting to Cassandra hosts.
|
DseCluster.Builder |
withEndPointFactory(EndPointFactory endPointFactory)
Configures the endpoint factory to use for the new cluster.
|
DseCluster.Builder |
withGraphOptions(GraphOptions graphOptions)
Sets the default options to use with graph queries.
|
DseCluster.Builder |
withInitialListeners(Collection<Host.StateListener> listeners)
Register the provided listeners in the newly created cluster.
|
DseCluster.Builder |
withLoadBalancingPolicy(LoadBalancingPolicy policy)
Configures the load balancing policy to use for the new DSE cluster.
|
DseCluster.Builder |
withMaxSchemaAgreementWaitSeconds(int maxSchemaAgreementWaitSeconds)
Sets the maximum time to wait for schema agreement before returning from a DDL query.
|
DseCluster.Builder |
withMonitorReporting(boolean enabled)
Determines whether or not events are sent to the connected DSE cluster for insightful
monitoring.
|
DseCluster.Builder |
withNettyOptions(NettyOptions nettyOptions)
Set the
NettyOptions to use for the newly created Cluster. |
DseCluster.Builder |
withNoCompact()
Enables the
NO_COMPACT startup option. |
DseCluster.Builder |
withoutGeospatialCodecs()
Prevents the registration of
geospatial
codecs with the new cluster. |
DseCluster.Builder |
withoutJMXReporting()
Disables JMX reporting of the metrics.
|
DseCluster.Builder |
withoutMetrics()
Disables metrics collection for the created cluster (metrics are enabled by default
otherwise).
|
DseCluster.Builder |
withoutSearchCodecs()
Prevents the registration of search codecs with the new cluster.
|
DseCluster.Builder |
withPoolingOptions(PoolingOptions options)
Sets the PoolingOptions to use for the newly created Cluster.
|
DseCluster.Builder |
withPort(int port)
The port to use to connect to the Cassandra host.
|
DseCluster.Builder |
withProtocolVersion(ProtocolVersion version)
The native protocol version to use.
|
DseCluster.Builder |
withQueryOptions(QueryOptions options)
Sets the QueryOptions to use for the newly created Cluster.
|
DseCluster.Builder |
withReconnectionPolicy(ReconnectionPolicy policy)
Configures the reconnection policy to use for the new cluster.
|
DseCluster.Builder |
withRetryPolicy(RetryPolicy policy)
Configures the retry policy to use for the new cluster.
|
DseCluster.Builder |
withSocketOptions(SocketOptions options)
Sets the SocketOptions to use for the newly created Cluster.
|
DseCluster.Builder |
withSpeculativeExecutionPolicy(SpeculativeExecutionPolicy policy)
Configures the speculative execution policy to use for the new cluster.
|
DseCluster.Builder |
withSSL()
Enables the use of SSL for the created
Cluster . |
DseCluster.Builder |
withSSL(SSLOptions sslOptions)
Enable the use of SSL for the created
Cluster using the provided options. |
DseCluster.Builder |
withThreadingOptions(ThreadingOptions options)
Sets the threading options to use for the newly created Cluster.
|
DseCluster.Builder |
withTimestampGenerator(TimestampGenerator timestampGenerator)
Configures the generator that will produce the client-side timestamp sent with each query.
|
addContactPoint, getClusterName, getContactPoints, getInitialListeners, getResolvedContactPoints
public DseCluster.Builder withGraphOptions(GraphOptions graphOptions)
If you don't provide this, the new cluster will get a GraphOptions
instance with
the default values.
graphOptions
- the graph options.public DseCluster.Builder withoutGeospatialCodecs()
geospatial
codecs
with the new cluster.
If this method is not called, those codecs will be registered by default.
CodecRegistry
,
TypeCodec
public DseCluster.Builder withoutSearchCodecs()
Currently only DateRangeCodec
is affected by this method. If this method is not
called, this codec will be registered by default.
CodecRegistry
,
TypeCodec
public DseCluster.Builder withClusterName(String name)
Cluster.Builder
Note: this is not related to the Cassandra cluster name (though you are free to provide
the same name). See Cluster.getClusterName()
for details.
If you use this method and create more than one Cluster instance in the same JVM (which should be avoided unless you need to connect to multiple Cassandra clusters), you should make sure each Cluster instance get a unique name or you may have a problem with JMX reporting.
withClusterName
in class Cluster.Builder
name
- the cluster name to use for the created Cluster instance.@Deprecated public DseCluster.Builder withClusterId(UUID id)
withClientId(UUID)
} instead. This method was intended to give a
client id not cluster id from the beginning. The withClientId name is more appropriate.If not provided, an id will generated.
This value is passed to DSE and is useful as metadata for describing a client connection.
id
- the id to assign to this client instance.public DseCluster.Builder withClientId(UUID id)
If not provided, an id will generated.
This value is passed to DSE and is useful as metadata for describing a client connection.
id
- the id to assign to this client instance.public DseCluster.Builder withApplicationName(String name)
This value is passed to DSE and is useful as metadata for describing a client connection.
name
- the name of the application using this cluster.public DseCluster.Builder withApplicationVersion(String version)
This value is to passed to DSE and is useful as metadata for describing a client connection.
version
- the version of the application using this cluster.public DseCluster.Builder withPort(int port)
Cluster.Builder
If not set through this method, the default port (9042) will be used instead.
withPort
in class Cluster.Builder
port
- the port to set.public DseCluster.Builder allowBetaProtocolVersion()
Cluster.Builder
This feature is only available starting with version V5
.
Use with caution, refer to the server and protocol documentation for the details on latest protocol version.
allowBetaProtocolVersion
in class Cluster.Builder
public DseCluster.Builder withMaxSchemaAgreementWaitSeconds(int maxSchemaAgreementWaitSeconds)
Cluster.Builder
If not set through this method, the default value (10 seconds) will be used.
withMaxSchemaAgreementWaitSeconds
in class Cluster.Builder
maxSchemaAgreementWaitSeconds
- the new value to set.public DseCluster.Builder withProtocolVersion(ProtocolVersion version)
Cluster.Builder
The driver supports versions 1 to 5 of the native protocol. Higher versions of the protocol have more features and should be preferred, but this also depends on the Cassandra version:
Protocol version | Minimum Cassandra version |
---|---|
1 | 1.2 |
2 | 2.0 |
3 | 2.1 |
4 | 2.2 |
5 | 3.10 |
By default, the driver will "auto-detect" which protocol version it can use when
connecting to the first node. More precisely, it will try first with ProtocolVersion.NEWEST_SUPPORTED
, and if not supported fallback to the highest version
supported by the first node it connects to. Please note that once the version is
"auto-detected", it won't change: if the first node the driver connects to is a Cassandra 1.2
node and auto-detection is used (the default), then the native protocol version 1 will be use
for the lifetime of the Cluster instance.
By using Cluster.Builder.allowBetaProtocolVersion()
, it is possible to force driver to
connect to Cassandra node that supports the latest protocol beta version. Leaving this flag
out will let client to connect with latest released version.
This method allows to force the use of a particular protocol version. Forcing version 1 is
always fine since all Cassandra version (at least all those supporting the native protocol in
the first place) so far support it. However, please note that a number of features of the
driver won't be available if that version of the protocol is in use, including result set
paging, BatchStatement
, executing a non-prepared query with binary values (Session.execute(String, Object...)
), ... (those methods will throw an
UnsupportedFeatureException). Using the protocol version 1 should thus only be considered
when using Cassandra 1.2, until nodes have been upgraded to Cassandra 2.0.
If version 2 of the protocol is used, then Cassandra 1.2 nodes will be ignored (the driver won't connect to them).
The default behavior (auto-detection) is fine in almost all case, but you may want to force a particular version if you have a Cassandra cluster with mixed 1.2/2.0 nodes (i.e. during a Cassandra upgrade).
withProtocolVersion
in class Cluster.Builder
version
- the native protocol version to use. null
is also supported to trigger
auto-detection (see above) but this is the default (so you don't have to call this method
for that behavior).public DseCluster.Builder withMonitorReporting(boolean enabled)
Cluster.Builder
If not set through this method, the default value (true) will be used.
withMonitorReporting
in class Cluster.Builder
enabled
- flag that indicates if events should be sentpublic DseCluster.Builder addContactPoint(String address)
Cluster.Builder
InetAddress
s (A records).
Contact points 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.
Note that by default (that is, unless you use the Cluster.Builder.withLoadBalancingPolicy(com.datastax.driver.core.policies.LoadBalancingPolicy)
) method
of this builder), the first successfully contacted host will be used to define the local
data-center for the client. If follows that if you are running Cassandra in a multiple
data-center setting, it is a good idea to only provide contact points that are in the same
datacenter than the client, or to provide manually the load balancing policy that suits your
need.
If the host name points to a DNS record with multiple a-records, all InetAddresses
returned will be used. Make sure that all resulting InetAddress
s returned point
to the same cluster and datacenter.
addContactPoint
in class Cluster.Builder
address
- the address of the node(s) to connect to.public DseCluster.Builder addContactPoints(String... addresses)
Cluster.Builder
See Cluster.Builder.addContactPoint(java.lang.String)
for more details on contact points.
Note that all contact points must be resolvable; if any of them cannot be resolved, this method will fail.
addContactPoints
in class Cluster.Builder
addresses
- addresses of the nodes to add as contact points.Cluster.Builder.addContactPoint(java.lang.String)
public DseCluster.Builder addContactPoints(InetAddress... addresses)
Cluster.Builder
See Cluster.Builder.addContactPoint(java.lang.String)
for more details on contact points.
Note that all contact points must be resolvable; if any of them cannot be resolved, this method will fail.
addContactPoints
in class Cluster.Builder
addresses
- addresses of the nodes to add as contact points.Cluster.Builder.addContactPoint(java.lang.String)
public DseCluster.Builder addContactPoints(Collection<InetAddress> addresses)
Cluster.Builder
See Cluster.Builder.addContactPoint(java.lang.String)
for more details on contact points.
addContactPoints
in class Cluster.Builder
addresses
- addresses of the nodes to add as contact points.Cluster.Builder.addContactPoint(java.lang.String)
public DseCluster.Builder addContactPointsWithPorts(InetSocketAddress... addresses)
Cluster.Builder
See Cluster.Builder.addContactPoint(java.lang.String)
for more details on contact points. Contrarily to
other addContactPoints
methods, this method allows to provide a different port for
each contact point. Since Cassandra nodes must always all listen on the same port, this is
rarely what you want and most users should prefer other addContactPoints
methods to
this one. However, this can be useful if the Cassandra nodes are behind a router and are not
accessed directly. Note that if you are in this situation (Cassandra nodes are behind a
router, not directly accessible), you almost surely want to provide a specific AddressTranslator
(through Cluster.Builder.withAddressTranslator(com.datastax.driver.core.policies.AddressTranslator)
) to translate actual Cassandra
node addresses to the addresses the driver should use, otherwise the driver will not be able
to auto-detect new nodes (and will generally not function optimally).
addContactPointsWithPorts
in class Cluster.Builder
addresses
- addresses of the nodes to add as contact points.Cluster.Builder.addContactPoint(java.lang.String)
public DseCluster.Builder addContactPointsWithPorts(Collection<InetSocketAddress> addresses)
Cluster.Builder
See Cluster.Builder.addContactPoint(java.lang.String)
for more details on contact points. Contrarily to
other addContactPoints
methods, this method allows to provide a different port for
each contact point. Since Cassandra nodes must always all listen on the same port, this is
rarely what you want and most users should prefer other addContactPoints
methods to
this one. However, this can be useful if the Cassandra nodes are behind a router and are not
accessed directly. Note that if you are in this situation (Cassandra nodes are behind a
router, not directly accessible), you almost surely want to provide a specific AddressTranslator
(through Cluster.Builder.withAddressTranslator(com.datastax.driver.core.policies.AddressTranslator)
) to translate actual Cassandra
node addresses to the addresses the driver should use, otherwise the driver will not be able
to auto-detect new nodes (and will generally not function optimally).
addContactPointsWithPorts
in class Cluster.Builder
addresses
- addresses of the nodes to add as contact points.Cluster.Builder.addContactPoint(java.lang.String)
public DseCluster.Builder withLoadBalancingPolicy(LoadBalancingPolicy policy)
If you use graph analytics queries, it should be wrapped into a DseLoadBalancingPolicy
to ensure that queries are routed optimally.
If no load balancing policy is set through this method, the default is to use a Policies.defaultLoadBalancingPolicy()
wrapped into a TargetingLoadBalancingPolicy
.
withLoadBalancingPolicy
in class Cluster.Builder
policy
- the load balancing policy to use.public DseCluster.Builder withReconnectionPolicy(ReconnectionPolicy policy)
Cluster.Builder
If no reconnection policy is set through this method, Policies.DEFAULT_RECONNECTION_POLICY
will be used instead.
withReconnectionPolicy
in class Cluster.Builder
policy
- the reconnection policy to use.public DseCluster.Builder withRetryPolicy(RetryPolicy policy)
Cluster.Builder
If no retry policy is set through this method, Policies.DEFAULT_RETRY_POLICY
will
be used instead.
withRetryPolicy
in class Cluster.Builder
policy
- the retry policy to use.public DseCluster.Builder withAddressTranslator(AddressTranslator translator)
Cluster.Builder
See AddressTranslator
for more detail on address translation, but the default
translator, IdentityTranslator
, should be correct in most cases. If unsure, stick to
the default.
withAddressTranslator
in class Cluster.Builder
translator
- the translator to use.public DseCluster.Builder withTimestampGenerator(TimestampGenerator timestampGenerator)
Cluster.Builder
This feature is only available with version V3
or above of the
native protocol. With earlier versions, timestamps are always generated server-side, and
setting a generator through this method will have no effect.
If no generator is set through this method, the driver will default to client-side
timestamps by using AtomicMonotonicTimestampGenerator
.
withTimestampGenerator
in class Cluster.Builder
timestampGenerator
- the generator to use.public DseCluster.Builder withSpeculativeExecutionPolicy(SpeculativeExecutionPolicy policy)
Cluster.Builder
If no policy is set through this method, Policies.defaultSpeculativeExecutionPolicy()
will be used instead.
withSpeculativeExecutionPolicy
in class Cluster.Builder
policy
- the policy to use.public DseCluster.Builder withCodecRegistry(CodecRegistry codecRegistry)
Cluster.Builder
CodecRegistry
instance to use for the new cluster.
If no codec registry is set through this method, CodecRegistry.DEFAULT_INSTANCE
will be used instead.
Note that if two or more Cluster
instances are configured to use the default codec
registry, they are going to share the same instance. In this case, care should be taken when
registering new codecs on it as any codec registered by one cluster would be immediately
available to others sharing the same default instance.
withCodecRegistry
in class Cluster.Builder
codecRegistry
- the codec registry to use.public DseCluster.Builder withCredentials(String username, String password)
Cluster.Builder
This should be used if the Cassandra cluster has been configured to use the PasswordAuthenticator
. If the the default AllowAllAuthenticator
is used instead,
using this method has no effect.
withCredentials
in class Cluster.Builder
username
- the username to use to login to Cassandra hosts.password
- the password corresponding to username
.public DseCluster.Builder withAuthProvider(AuthProvider authProvider)
Cluster.Builder
Use this method when a custom authentication scheme is in place. You shouldn't call both
this method and withCredentials
on the same Builder
instance as one will
supersede the other
withAuthProvider
in class Cluster.Builder
authProvider
- the AuthProvider
to use to login to Cassandra hosts.public DseCluster.Builder withCompression(ProtocolOptions.Compression compression)
Cluster.Builder
withCompression
in class Cluster.Builder
compression
- the compression to set.ProtocolOptions.Compression
public DseCluster.Builder withoutMetrics()
Cluster.Builder
withoutMetrics
in class Cluster.Builder
public DseCluster.Builder withSSL()
Cluster.Builder
Cluster
.
Calling this method will use the JDK-based implementation with the default options (see
RemoteEndpointAwareJdkSSLOptions.Builder
). This is thus a shortcut for withSSL(JdkSSLOptions.builder().build())
.
Note that if SSL is enabled, the driver will not connect to any Cassandra nodes that doesn't have SSL enabled and it is strongly advised to enable SSL on every Cassandra node if you plan on using SSL in the driver.
withSSL
in class Cluster.Builder
public DseCluster.Builder withSSL(SSLOptions sslOptions)
Cluster.Builder
Cluster
using the provided options.withSSL
in class Cluster.Builder
sslOptions
- the SSL options to use.public DseCluster.Builder withInitialListeners(Collection<Host.StateListener> listeners)
Cluster.Builder
Note: repeated calls to this method will override the previous ones.
withInitialListeners
in class Cluster.Builder
listeners
- the listeners to register.public DseCluster.Builder withoutJMXReporting()
Cluster.Builder
JMX reporting is enabled by default (see Metrics
) but can be disabled using this
option. If metrics are disabled, this is a no-op.
withoutJMXReporting
in class Cluster.Builder
public DseCluster.Builder withPoolingOptions(PoolingOptions options)
Cluster.Builder
If no pooling options are set through this method, default pooling options will be used.
withPoolingOptions
in class Cluster.Builder
options
- the pooling options to use.public DseCluster.Builder withSocketOptions(SocketOptions options)
Cluster.Builder
If no socket options are set through this method, default socket options will be used.
withSocketOptions
in class Cluster.Builder
options
- the socket options to use.public DseCluster.Builder withQueryOptions(QueryOptions options)
Cluster.Builder
If no query options are set through this method, default query options will be used.
withQueryOptions
in class Cluster.Builder
options
- the query options to use.public DseCluster.Builder withThreadingOptions(ThreadingOptions options)
Cluster.Builder
If no options are set through this method, a new instance of ThreadingOptions
will
be used.
withThreadingOptions
in class Cluster.Builder
options
- the options.public DseCluster.Builder withNettyOptions(NettyOptions nettyOptions)
Cluster.Builder
NettyOptions
to use for the newly created Cluster.
If no Netty options are set through this method, NettyOptions.DEFAULT_INSTANCE
will be used as a default value, which means that no customization will be applied.
withNettyOptions
in class Cluster.Builder
nettyOptions
- the NettyOptions
to use.public DseCluster.Builder withNoCompact()
Cluster.Builder
NO_COMPACT
startup option.
When this option is supplied, SELECT
, UPDATE
, DELETE
and
BATCH
statements on COMPACT STORAGE
tables function in "compatibility" mode which
allows seeing these tables as if they were "regular" CQL tables.
This option only effects interactions with tables using COMPACT STORAGE
and is only supported by
C* 4.0+ and DSE 6.0+.
withNoCompact
in class Cluster.Builder
public DseCluster.Builder withEndPointFactory(EndPointFactory endPointFactory)
Cluster.Builder
This is a low-level component for advanced scenarios where connecting to a node requires more than its socket address. If you're simply using host+port, the default factory is sufficient.
withEndPointFactory
in class Cluster.Builder
public DseCluster.Builder withCloudSecureConnectBundle(File cloudConfigFile)
Cluster.Builder
String
.
To connect to a Cloud database, you must first download the secure database bundle from the DataStax Constellation 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 Constellation documentation.
Note that the provided stream will be consumed and closed when this method will return; attempting to reuse it afterwards will result in an error being thrown.
withCloudSecureConnectBundle
in class Cluster.Builder
cloudConfigFile
- File that contains secure connect bundle zip file.Cluster.Builder.withCloudSecureConnectBundle(URL)
,
Cluster.Builder.withCloudSecureConnectBundle(InputStream)
public DseCluster.Builder withCloudSecureConnectBundle(URL cloudConfigUrl)
Cluster.Builder
URL
.
To connect to a Cloud database, you must first download the secure database bundle from the DataStax Constellation 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 Constellation documentation.
Note that the provided stream will be consumed and closed when this method will return; attempting to reuse it afterwards will result in an error being thrown.
withCloudSecureConnectBundle
in class Cluster.Builder
cloudConfigUrl
- URL to the secure connect bundle zip file.Cluster.Builder.withCloudSecureConnectBundle(File)
,
Cluster.Builder.withCloudSecureConnectBundle(InputStream)
public DseCluster.Builder withCloudSecureConnectBundle(InputStream cloudConfigInputStream)
Cluster.Builder
InputStream
.
To connect to a Cloud database, you must first download the secure database bundle from the DataStax Constellation 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 Constellation documentation.
Note that the provided stream will be consumed and closed when this method will return; attempting to reuse it afterwards will result in an error being thrown.
withCloudSecureConnectBundle
in class Cluster.Builder
cloudConfigInputStream
- A stream containing the secure connect bundle zip file.Cluster.Builder.withCloudSecureConnectBundle(File)
,
Cluster.Builder.withCloudSecureConnectBundle(URL)
public DseCluster build()
Cluster.Builder
This is a convenience method for Cluster.buildFrom(this)
.
build
in class Cluster.Builder
public DseConfiguration getConfiguration()
Cluster.Builder
You should not modify this object directly because changes made to the returned
object may not be used by the cluster build. Instead, you should use the other methods of
this Builder
.
getConfiguration
in interface Cluster.Initializer
getConfiguration
in class Cluster.Builder
Copyright © 2012–2019. All rights reserved.