com.datastax.driver.core
Class Cluster.Builder

java.lang.Object
  extended by com.datastax.driver.core.Cluster.Builder
All Implemented Interfaces:
Cluster.Initializer
Enclosing class:
Cluster

public static class Cluster.Builder
extends Object
implements Cluster.Initializer

Helper class to build Cluster instances.


Constructor Summary
Cluster.Builder()
           
 
Method Summary
 Cluster.Builder addContactPoint(String address)
          Adds a contact point.
 Cluster.Builder addContactPoints(InetAddress... addresses)
          Add contact points.
 Cluster.Builder addContactPoints(String... addresses)
          Add contact points.
 Cluster build()
          Build 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()
          The pooling options used by this builder.
 SocketOptions socketOptions()
          The socket options used by this builder.
 Cluster.Builder withAuthInfoProvider(AuthInfoProvider authInfoProvider)
          Use the provided AuthInfoProvider to connect to Cassandra hosts.
 Cluster.Builder withCompression(ProtocolOptions.Compression compression)
          Sets the compression to use for the transport.
 Cluster.Builder withLoadBalancingPolicy(LoadBalancingPolicy policy)
          Configure the load balancing policy to use for the new cluster.
 Cluster.Builder withoutMetrics()
          Disable metrics collection for the created cluster (metrics are enabled by default otherwise).
 Cluster.Builder withPort(int port)
          The port to use to connect to the Cassandra host.
 Cluster.Builder withReconnectionPolicy(ReconnectionPolicy policy)
          Configure the reconnection policy to use for the new cluster.
 Cluster.Builder withRetryPolicy(RetryPolicy policy)
          Configure the retry policy to use for the new cluster.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cluster.Builder

public Cluster.Builder()
Method Detail

getContactPoints

public List<InetAddress> getContactPoints()
Description copied from interface: Cluster.Initializer
Returns the initial Cassandra hosts to connect to.

Specified by:
getContactPoints in interface Cluster.Initializer
Returns:
the initial Cassandra contact points. See addContactPoint(java.lang.String) for more details on contact points.

withPort

public Cluster.Builder withPort(int port)
The port to use to connect to the Cassandra host. If not set through this method, the default port (9042) will be used instead.

Parameters:
port - the port to set.
Returns:
this Builder

addContactPoint

public Cluster.Builder addContactPoint(String address)
Adds a contact point. 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, as if that unique contact point is not available, the driver won't be able to initialize itself correctly.

Parameters:
address - the address of the node to connect to
Returns:
this Builder
Throws:
IllegalArgumentException - if no IP address for address could be found
SecurityException - if a security manager is present and permission to resolve the host name is denied.

addContactPoints

public Cluster.Builder addContactPoints(String... addresses)
Add contact points. See addContactPoint(java.lang.String) for more details on contact points.

Parameters:
addresses - addresses of the nodes to add as contact point
Returns:
this Builder
Throws:
IllegalArgumentException - if no IP address for at least one of addresses could be found
SecurityException - if a security manager is present and permission to resolve the host name is denied.
See Also:
addContactPoint(java.lang.String)

addContactPoints

public Cluster.Builder addContactPoints(InetAddress... addresses)
Add contact points. See addContactPoint(java.lang.String) for more details on contact points.

Parameters:
addresses - addresses of the nodes to add as contact point
Returns:
this Builder
See Also:
addContactPoint(java.lang.String)

withLoadBalancingPolicy

public Cluster.Builder withLoadBalancingPolicy(LoadBalancingPolicy policy)
Configure the load balancing policy to use for the new cluster.

If no load balancing policy is set through this method, Policies.DEFAULT_LOAD_BALANCING_POLICY will be used instead.

Parameters:
policy - the load balancing policy to use
Returns:
this Builder

withReconnectionPolicy

public Cluster.Builder withReconnectionPolicy(ReconnectionPolicy policy)
Configure the reconnection policy to use for the new cluster.

If no reconnection policy is set through this method, Policies.DEFAULT_RECONNECTION_POLICY will be used instead.

Parameters:
policy - the reconnection policy to use
Returns:
this Builder

withRetryPolicy

public Cluster.Builder withRetryPolicy(RetryPolicy policy)
Configure the retry policy to use for the new cluster.

If no retry policy is set through this method, Policies.DEFAULT_RETRY_POLICY will be used instead.

Parameters:
policy - the retry policy to use
Returns:
this Builder

withAuthInfoProvider

public Cluster.Builder withAuthInfoProvider(AuthInfoProvider authInfoProvider)
Use the provided AuthInfoProvider to connect to Cassandra hosts.

This is optional if the Cassandra cluster has been configured to not require authentication (the default).

Parameters:
authInfoProvider - the authentication info provider to use
Returns:
this Builder

withCompression

public Cluster.Builder withCompression(ProtocolOptions.Compression compression)
Sets the compression to use for the transport.

Parameters:
compression - the compression to set
Returns:
this Builder
See Also:
ProtocolOptions.Compression

withoutMetrics

public Cluster.Builder withoutMetrics()
Disable metrics collection for the created cluster (metrics are enabled by default otherwise).

Returns:
this builder

poolingOptions

public PoolingOptions poolingOptions()
The pooling options used by this builder.

Returns:
the pooling options that will be used by this builder. You can use the returned object to define the initial pooling options for the built cluster.

socketOptions

public SocketOptions socketOptions()
The socket options used by this builder.

Returns:
the socket options that will be used by this builder. You can use the returned object to define the initial socket options for the built cluster.

getConfiguration

public Configuration getConfiguration()
The configuration that will be used for the new cluster.

You should not modify this object directly as change made to the returned object may not be used by the cluster build. Instead, you should use the other methods of this Builder.

Specified by:
getConfiguration in interface Cluster.Initializer
Returns:
the configuration to use for the new cluster.

build

public Cluster build()
Build the cluster with the configured set of initial contact points and policies. This is a shorthand for Cluster.buildFrom(this).

Returns:
the newly build Cluster instance.
Throws:
NoHostAvailableException - if none of the contact points provided can be reached.
AuthenticationException - if while contacting the initial contact points an authencation error occurs.


Copyright © 2013. All Rights Reserved.