Skip to content

Commit 7aea7af

Browse files
Merge pull request #207 from datastax/RUBY-266
RUBY-266 - expose execution profiles through cluster object
2 parents 924565e + 3aa55f1 commit 7aea7af

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
cassandra-driver (3.0.4.rc.1)
4+
cassandra-driver (3.1.0.rc.1)
55
ione (~> 1.2)
66

77
GEM

lib/cassandra/cluster.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,16 @@ def protocol_version
161161
@connection_options.protocol_version
162162
end
163163

164+
# @param name [String] Name of profile to retrieve
165+
# @return [Cassandra::Execution::Profile] execution profile of the given name
166+
def execution_profile(name)
167+
@profile_manager.profiles[name]
168+
end
169+
164170
# @return [Hash<String, Cassandra::Execution::Profile>] the collection of execution profiles
165171
def execution_profiles
166-
@profile_manager.profiles
172+
# Return a dup of the hash to prevent the user from adding/removing profiles from the profile-manager.
173+
@profile_manager.profiles.dup
167174
end
168175

169176
# @!method refresh_schema_async

lib/cassandra/execution/profile_manager.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ def initialize(default_profile, profiles)
3333

3434
@load_balancing_policies = Set.new
3535
@load_balancing_policies << default_profile.load_balancing_policy if default_profile.load_balancing_policy
36+
@profiles = {DEFAULT_EXECUTION_PROFILE => default_profile}
3637

37-
profiles.each_value do |profile|
38-
@load_balancing_policies << profile.load_balancing_policy if profile.load_balancing_policy
39-
profile.merge_from(default_profile)
38+
profiles.each do |name, profile|
39+
add_profile(name, profile)
4040
end
41-
42-
@profiles = profiles.merge({DEFAULT_EXECUTION_PROFILE => default_profile})
4341
end
4442

4543
def default_profile
@@ -59,6 +57,14 @@ def distance(host)
5957
return :ignore
6058
end
6159

60+
# NOTE: It's only safe to call add_profile when setting up the cluster object. In particular,
61+
# this is only ok before calling Driver#connect.
62+
def add_profile(name, profile)
63+
@profiles[name] = profile
64+
@load_balancing_policies << profile.load_balancing_policy if profile.load_balancing_policy
65+
profile.merge_from(default_profile)
66+
end
67+
6268
# @private
6369
def inspect
6470
"#<#{self.class.name}:0x#{object_id.to_s(16)} " \

lib/cassandra/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
#++
1818

1919
module Cassandra
20-
VERSION = '3.0.4.rc.1'.freeze
20+
VERSION = '3.1.0.rc.1'.freeze
2121
end

spec/support/stub_io_reactor.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#++
1818

1919
class StubIoReactor
20+
include MonitorMixin
21+
2022
class NullObject
2123
def method_missing(method, *args, &block)
2224
self
@@ -385,6 +387,8 @@ def initialize
385387
@connections = ::Array.new
386388
@timers = ::Array.new
387389
@max_conns = ::Hash.new
390+
391+
mon_initialize
388392
end
389393

390394
def enable_nodes(ips)
@@ -465,21 +469,26 @@ def connect(host, port, options)
465469
end
466470

467471
def schedule_timer(seconds)
468-
promise = Ione::Promise.new
469-
@timers << Timer.new(promise, Time.now + seconds)
470-
promise.future
472+
synchronize do
473+
promise = Ione::Promise.new
474+
@timers << Timer.new(promise, Time.now + seconds)
475+
promise.future
476+
end
471477
end
472478

473479
def advance_time(seconds)
474-
@timers.dup.each {|timer| timer.advance(seconds)}
475-
@timers.reject! {|timer| timer.expired?}
476-
480+
synchronize do
481+
@timers.dup.each { |timer| timer.advance(seconds) }
482+
@timers.reject! { |timer| timer.expired? }
483+
end
477484
self
478485
end
479486

480487
def cancel_timer(timer_future)
481-
@timers.reject! do |timer|
482-
timer.resolves?(timer_future)
488+
synchronize do
489+
@timers.reject! do |timer|
490+
timer.resolves?(timer_future)
491+
end
483492
end
484493
end
485494
end

0 commit comments

Comments
 (0)