Class: Rails::Sharding::ShardThreadRegistry
- Inherits:
-
Object
- Object
- Rails::Sharding::ShardThreadRegistry
- Defined in:
- lib/rails/sharding/shard_thread_registry.rb
Class Method Summary collapse
-
.connect_back_to_master! ⇒ Object
Clears the connection stack and goes back to connecting to master.
- .connecting_to_master? ⇒ Boolean
- .connecting_to_shard? ⇒ Boolean
- .current_connection_used? ⇒ Boolean
-
.current_shard_group ⇒ Object
Returns the current shard group (for the current Thread).
- .current_shard_group_and_name ⇒ Object
-
.current_shard_name ⇒ Object
Returns the current shard name (for the current Thread).
-
.notify_connection_retrieved ⇒ Object
notifies the current connection was used (wee keep track of this to warn the user in case the connection is not used).
-
.pop_current_shard ⇒ Object
removes shard connection to the stack.
-
.push_current_shard(group, name) ⇒ Object
adds shard connection to the stack.
- .shard_connection_used_stack ⇒ Object
-
.shard_group_stack ⇒ Object
accessors that initialize stacks if necessary.
- .shard_name_stack ⇒ Object
Class Method Details
.connect_back_to_master! ⇒ Object
Clears the connection stack and goes back to connecting to master
29 30 31 32 33 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 29 def self.connect_back_to_master! shard_group_stack.clear shard_name_stack.clear shard_connection_used_stack.clear end |
.connecting_to_master? ⇒ Boolean
20 21 22 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 20 def self.connecting_to_master? current_shard_group.nil? || current_shard_name.nil? end |
.connecting_to_shard? ⇒ Boolean
24 25 26 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 24 def self.connecting_to_shard? !connecting_to_master? end |
.current_connection_used? ⇒ Boolean
45 46 47 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 45 def self.current_connection_used? shard_connection_used_stack.last end |
.current_shard_group ⇒ Object
Returns the current shard group (for the current Thread)
36 37 38 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 36 def self.current_shard_group shard_group_stack.last end |
.current_shard_group_and_name ⇒ Object
72 73 74 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 72 def self.current_shard_group_and_name [current_shard_group, current_shard_name] end |
.current_shard_name ⇒ Object
Returns the current shard name (for the current Thread)
41 42 43 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 41 def self.current_shard_name shard_name_stack.last end |
.notify_connection_retrieved ⇒ Object
notifies the current connection was used (wee keep track of this to warn the user in case the connection is not used)
63 64 65 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 63 def self.notify_connection_retrieved shard_connection_used_stack[-1] = true if shard_connection_used_stack.present? end |
.pop_current_shard ⇒ Object
removes shard connection to the stack
68 69 70 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 68 def self.pop_current_shard [shard_group_stack.pop, shard_name_stack.pop, shard_connection_used_stack.pop] end |
.push_current_shard(group, name) ⇒ Object
adds shard connection to the stack
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 50 def self.push_current_shard(group, name) # this line supresses the unused connection warning when there are nested # using_shard blocks. We suppress the warning because we view nested using_shard # blocks as a override notify_connection_retrieved shard_group_stack.push(group.blank? ? nil : group.to_sym) shard_name_stack.push(name.blank? ? nil : name.to_sym) shard_connection_used_stack.push(false) end |
.shard_connection_used_stack ⇒ Object
18 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 18 def self.shard_connection_used_stack; self._shard_connection_used_stack ||= [] end |
.shard_group_stack ⇒ Object
accessors that initialize stacks if necessary
16 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 16 def self.shard_group_stack; self._shard_group_stack ||= [] end |
.shard_name_stack ⇒ Object
17 |
# File 'lib/rails/sharding/shard_thread_registry.rb', line 17 def self.shard_name_stack; self._shard_name_stack ||= [] end |