class Rails::Sharding::ShardThreadRegistry

Public Class Methods

connect_back_to_master!() click to toggle source

Clears the connection stack and goes back to connecting to master

# File lib/rails/sharding/shard_thread_registry.rb, line 30
def self.connect_back_to_master!
  shard_group_stack.clear
  shard_name_stack.clear
  shard_connection_used_stack.clear
end
connecting_to_master?() click to toggle source
# File lib/rails/sharding/shard_thread_registry.rb, line 21
def self.connecting_to_master?
  current_shard_group.nil? || current_shard_name.nil?
end
connecting_to_shard?() click to toggle source
# File lib/rails/sharding/shard_thread_registry.rb, line 25
def self.connecting_to_shard?
  !connecting_to_master?
end
current_connection_used?() click to toggle source
# File lib/rails/sharding/shard_thread_registry.rb, line 46
def self.current_connection_used?
  shard_connection_used_stack.last
end
current_shard_group() click to toggle source

Returns the current shard group (for the current Thread)

# File lib/rails/sharding/shard_thread_registry.rb, line 37
def self.current_shard_group
  shard_group_stack.last
end
current_shard_group_and_name() click to toggle source
# File lib/rails/sharding/shard_thread_registry.rb, line 73
def self.current_shard_group_and_name
  [current_shard_group, current_shard_name]
end
current_shard_name() click to toggle source

Returns the current shard name (for the current Thread)

# File lib/rails/sharding/shard_thread_registry.rb, line 42
def self.current_shard_name
  shard_name_stack.last
end
notify_connection_retrieved() click to toggle source

notifies the current connection was used (wee keep track of this to warn the user in case the connection is not used)

# File lib/rails/sharding/shard_thread_registry.rb, line 64
def self.notify_connection_retrieved
  shard_connection_used_stack[-1] = true if shard_connection_used_stack.present?
end
pop_current_shard() click to toggle source

removes shard connection to the stack

# File lib/rails/sharding/shard_thread_registry.rb, line 69
def self.pop_current_shard
  [shard_group_stack.pop, shard_name_stack.pop, shard_connection_used_stack.pop]
end
push_current_shard(group, name) click to toggle source

adds shard connection to the stack

# File lib/rails/sharding/shard_thread_registry.rb, line 51
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() click to toggle source
# File lib/rails/sharding/shard_thread_registry.rb, line 19
def self.shard_connection_used_stack; self._shard_connection_used_stack ||= [] end
shard_group_stack() click to toggle source

accessors that initialize stacks if necessary

# File lib/rails/sharding/shard_thread_registry.rb, line 17
def self.shard_group_stack; self._shard_group_stack ||= [] end
shard_name_stack() click to toggle source
# File lib/rails/sharding/shard_thread_registry.rb, line 18
def self.shard_name_stack; self._shard_name_stack ||= [] end