public static class Cluster.Builder extends Object implements Cluster.Initializer
Cluster
instances.Constructor and Description |
---|
Cluster.Builder() |
Modifier and Type | Method and Description |
---|---|
Cluster.Builder |
addContactPoint(String address)
Adds a contact point.
|
Cluster.Builder |
addContactPoints(Collection<InetAddress> addresses)
Adds contact points.
|
Cluster.Builder |
addContactPoints(InetAddress... addresses)
Adds contact points.
|
Cluster.Builder |
addContactPoints(String... addresses)
Adds contact points.
|
Cluster |
build()
Builds the cluster with the configured set of initial contact points
and policies.
|
Configuration |
getConfiguration()
The configuration that will be used for the new cluster.
|
List<InetAddress> |
getContactPoints()
Returns the initial Cassandra hosts to connect to.
|
PoolingOptions |
poolingOptions()
Deprecated.
you are now encouraged to use the
withPoolingOptions(com.datastax.driver.core.PoolingOptions)
method. This method is deprecated and will be removed in the next major
version of the driver. |
SocketOptions |
socketOptions()
Deprecated.
you are now encouraged to use the
withPoolingOptions(com.datastax.driver.core.PoolingOptions)
method. This method is deprecated and will be removed in the next major
version of the driver. |
Cluster.Builder |
withCompression(ProtocolOptions.Compression compression)
Sets the compression to use for the transport.
|
Cluster.Builder |
withCredentials(String username,
String password)
Uses the provided credentials when connecting to Cassandra hosts.
|
Cluster.Builder |
withDeferredInitialization()
Defer the initialization of the created cluster.
|
Cluster.Builder |
withLoadBalancingPolicy(LoadBalancingPolicy policy)
Configures the load balancing policy to use for the new cluster.
|
Cluster.Builder |
withoutJMXReporting()
Disables JMX reporting of the metrics.
|
Cluster.Builder |
withoutMetrics()
Disables metrics collection for the created cluster (metrics are
enabled by default otherwise).
|
Cluster.Builder |
withPoolingOptions(PoolingOptions options)
Set the PoolingOptions to use for the newly created Cluster.
|
Cluster.Builder |
withPort(int port)
The port to use to connect to the Cassandra host.
|
Cluster.Builder |
withReconnectionPolicy(ReconnectionPolicy policy)
Configures the reconnection policy to use for the new cluster.
|
Cluster.Builder |
withRetryPolicy(RetryPolicy policy)
Configures the retry policy to use for the new cluster.
|
Cluster.Builder |
withSocketOptions(SocketOptions options)
Set the SocketOptions to use for the newly created Cluster.
|
Cluster.Builder |
withSSL()
Enables the use of SSL for the created
Cluster . |
Cluster.Builder |
withSSL(SSLOptions sslOptions)
Enable the use of SSL for the created
Cluster using the provided options. |
public List<InetAddress> getContactPoints()
Cluster.Initializer
getContactPoints
in interface Cluster.Initializer
addContactPoint(java.lang.String)
for more details on contact points.public Cluster.Builder withPort(int port)
port
- the port to set.public Cluster.Builder addContactPoint(String address)
address
- the address of the node to connect toIllegalArgumentException
- if no IP address for address
could be foundSecurityException
- if a security manager is present and
permission to resolve the host name is denied.public Cluster.Builder addContactPoints(String... addresses)
addContactPoint(java.lang.String)
for more details on contact
points.addresses
- addresses of the nodes to add as contact pointIllegalArgumentException
- if no IP address for at least one
of addresses
could be foundSecurityException
- if a security manager is present and
permission to resolve the host name is denied.addContactPoint(java.lang.String)
public Cluster.Builder addContactPoints(InetAddress... addresses)
addContactPoint(java.lang.String)
for more details on contact
points.addresses
- addresses of the nodes to add as contact pointaddContactPoint(java.lang.String)
public Cluster.Builder addContactPoints(Collection<InetAddress> addresses)
addContactPoint(java.lang.String)
for more details on contact
points.addresses
- addresses of the nodes to add as contact pointaddContactPoint(java.lang.String)
public Cluster.Builder withLoadBalancingPolicy(LoadBalancingPolicy policy)
If no load balancing policy is set through this method,
Policies.defaultLoadBalancingPolicy()
will be used instead.
policy
- the load balancing policy to usepublic Cluster.Builder withReconnectionPolicy(ReconnectionPolicy policy)
If no reconnection policy is set through this method,
Policies.DEFAULT_RECONNECTION_POLICY
will be used instead.
policy
- the reconnection policy to usepublic Cluster.Builder withRetryPolicy(RetryPolicy policy)
If no retry policy is set through this method,
Policies.DEFAULT_RETRY_POLICY
will be used instead.
policy
- the retry policy to usepublic Cluster.Builder withCredentials(String username, String password)
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.
username
- the username to use to login to Cassandra hosts.password
- the password corresponding to username
.public Cluster.Builder withCompression(ProtocolOptions.Compression compression)
compression
- the compression to setProtocolOptions.Compression
public Cluster.Builder withoutMetrics()
public Cluster.Builder withSSL()
Cluster
.
Calling this method will use default SSL options (see SSLOptions.SSLOptions()
).
This is thus a shortcut for withSSL(new SSLOptions())
.
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.
public Cluster.Builder withSSL(SSLOptions sslOptions)
Cluster
using the provided options.sslOptions
- the SSL options to use.public Cluster.Builder withoutJMXReporting()
JMX reporting is enabled by default (see Metrics
) but can be
disabled using this option. If metrics are disabled, this is a
no-op.
@Deprecated public PoolingOptions poolingOptions()
withPoolingOptions(com.datastax.driver.core.PoolingOptions)
method. This method is deprecated and will be removed in the next major
version of the driver.public Cluster.Builder withPoolingOptions(PoolingOptions options)
If no pooling options are set through this method, default pooling options will be used.
options
- the pooling options to use.@Deprecated public SocketOptions socketOptions()
withPoolingOptions(com.datastax.driver.core.PoolingOptions)
method. This method is deprecated and will be removed in the next major
version of the driver.public Cluster.Builder withSocketOptions(SocketOptions options)
If no socket options are set through this method, default socket options will be used.
options
- the socket options to use.public Cluster.Builder withDeferredInitialization()
By default, building the cluster (calling the build()
method of this object)
triggers the creation of a connection to one of the contact points.
That connection is then used to fetch the metadata on the Cassandra
cluster we are connected to (other nodes, schema, ...). If this
method is used, the creation of that connection will be deferred until the first
call to connect()
or getMetadata()
on the resulting Cluster
object.
This method is useful when it is not convenient to deal with connection problems while creating the Cluster object. Note that this method only exists in the 1.X branch of the driver since deferred initialization is the default on the 2.X branch.
public Configuration getConfiguration()
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
public Cluster build()
Cluster.buildFrom(this)
.NoHostAvailableException
- if none of the contact points
provided can be reached.AuthenticationException
- if an authentication error occurs.
while contacting the initial contact pointsCopyright © 2014. All Rights Reserved.