Class: Dse::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/dse/cluster.rb

Overview

Cluster represents a DSE cluster. It serves as a session factory and a collection of metadata. It wraps a Cassandra::Cluster and exposes all of its functionality.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (protected)



88
89
90
91
92
93
94
# File 'lib/dse/cluster.rb', line 88

def method_missing(method_name, *args, &block)
  # If we get here, we don't have a method of our own. Forward the request to the delegate_cluster.
  # If it returns itself, we will coerce the result to return our *self* instead.

  result = @delegate_cluster.send(method_name, *args, &block)
  (result == @delegate_cluster) ? self : result
end

Instance Method Details

#connect(keyspace = nil) ⇒ Dse::Session

Synchronous variant of #connect_async.

Parameters:

  • keyspace (String) (defaults to: nil)

    optional keyspace to scope the session to

Returns:



74
75
76
# File 'lib/dse/cluster.rb', line 74

def connect(keyspace = nil)
  connect_async(keyspace).get
end

#connect_async(keyspace = nil) ⇒ Cassandra::Future<Dse::Session>

Delegates to Cassandra::Cluster#connect_async to connect asynchronously to a cluster, but returns a future that will resolve to a DSE session rather than Cassandra session.

Parameters:

  • keyspace (String) (defaults to: nil)

    optional keyspace to scope session to

Returns:



61
62
63
64
65
66
67
# File 'lib/dse/cluster.rb', line 61

def connect_async(keyspace = nil)
  future = @delegate_cluster.connect_async(keyspace)
  # We want to actually return a DSE session upon successful connection.
  future.then do |cassandra_session|
    Dse::Session.new(cassandra_session, @profile_manager, @futures)
  end
end