Cluster represents a cassandra cluster. It serves as a Session factory and a collection of metadata.

See Also:

Inherits

Object

Extends

  • Forwardable

Methods

host

(address)

Find a host by its address

Parameters:
Name Type Details
address (IPAddr or String) ip address
Returns:
Type Details
(Host or nil) host or nil

has_host?

(address)

Determine if a host by a given address exists

Parameters:
Name Type Details
address (IPAddr or String) ip address
Returns:
Type Details
Boolean true or false

keyspace

(name)

Find a keyspace by name

Parameters:
Name Type Details
name String keyspace name
Returns:
Type Details
(Keyspace or nil) keyspace or nil

has_keyspace?

(name)

Determine if a keyspace by a given name exists

Parameters:
Name Type Details
name String keyspace name
Returns:
Type Details
Boolean true or false

name

Return cluster’s name

Returns:
Type Details
String cluster’s name

find_replicas

(keyspace, statement)

Return replicas for a given statement and keyspace

Note
an empty list is returned when statement/keyspace information is not enough to determine replica list.
Parameters:
Name Type Details
keyspace String keyspace name
statement Statement statement for which to find replicas
Returns:
Type Details
Array<Host> a list of replicas

register

(listener)

Register a cluster state listener. State listener will start receiving notifications about topology and schema changes

Parameters:
Name Type Details
listener Listener cluster state listener
Returns:
Type Details
self

unregister

(listener)

Unregister a cluster state listener. State listener will stop receiving notifications about topology and schema changes

Parameters:
Name Type Details
listener Listener cluster state listener
Returns:
Type Details
self

each_host

(&block) aliased as: hosts

Yield or enumerate each member of this cluster

Overloads:
each_host {|host| … }

Returns self

Yield Parameters:
Name Type Details
host Host current host
Returns:
Type Details
Cluster self
each_host

Returns a list of hosts

Returns:
Type Details
Array<Host> a list of hosts

each_keyspace

(&block) aliased as: keyspaces

Yield or enumerate each keyspace defined in this cluster

Overloads:
each_keyspace {|keyspace| … }

Returns self

Yield Parameters:
Name Type Details
keyspace Keyspace current keyspace
Returns:
Type Details
Cluster self
each_keyspace

Returns a list of keyspaces

Returns:
Type Details
Array<Keyspace> a list of keyspaces

connect_async

(keyspace = nil)

Asynchronously create a new session, optionally scoped to a keyspace

Parameters:
Name Type Details
keyspace String (defaults to: nil) optional keyspace to scope session to
Returns:
Type Details
Future<Session> a future new session that can prepare and execute statements
See Also:
Specifications:
Cluster#connect_async creates a new session
cluster.connect_async.get
expect(cluster_registry).to have(1).listeners
Cluster#connect_async removes client on close
cluster.connect_async
cluster_registry.listeners.first.close
expect(cluster_registry).to have(0).listeners
Cluster#connect_async uses given keyspace
future = Future::Value.new(nil)
Session.stub(:new) { session }
expect(session).to receive(:execute_async).once.with('USE foo').and_return(future)
cluster.connect_async('foo').get
Cluster#connect_async quotes keyspace name
future = Future::Value.new(nil)
Session.stub(:new) { session }
expect(session).to receive(:execute_async).once.with('USE "FooBar"').and_return(future)
cluster.connect_async('FooBar').get

connect

(keyspace = nil)

Synchronously create a new session, optionally scoped to a keyspace

Parameters:
Name Type Details
keyspace String (defaults to: nil) optional keyspace to scope the session to
Returns:
Type Details
Session a new session that can prepare and execute statements
Raises:
Type Details
ArgumentError if keyspace is not a String
Errors::NoHostsAvailable when all hosts failed
Errors::AuthenticationError when authentication fails
Errors::ProtocolError when protocol negotiation fails
Error other unexpected errors
See Also:

close_async

Asynchronously closes all sessions managed by this cluster

Returns:
Type Details
Future<Cluster> a future that resolves to self once closed
Specifications:
Cluster#close_async closes control connection
expect(control_connection).to receive(:close_async).once.and_return(Ione::Future.resolved)
expect(cluster.close_async).to eq(promise)
expect(promise).to have_received(:fulfill).once.with(cluster)

close

Synchronously closes all sessions managed by this cluster

Returns:
Type Details
self this cluster
See Also:

inspect

Returns a CLI-friendly cluster representation

Returns:
Type Details
String a CLI-friendly cluster representation