Parent

Included Modules

BackgrounDRb::ClusterConnection

Attributes

backend_connections[RW]

(Not documented)

bdrb_servers[RW]

(Not documented)

cache[RW]

(Not documented)

config[RW]

(Not documented)

disconnected_connections[RW]

(Not documented)

Public Class Methods

new() click to toggle source

initialize cluster connection

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 9
 9:     def initialize
10:       @bdrb_servers = []
11:       @backend_connections = []
12:       @disconnected_connections = {}
13: 
14:       @last_polled_time = Time.now
15:       @request_count = 0
16: 
17:       initialize_memcache if BDRB_CONFIG[:backgroundrb][:result_storage] == 'memcache'
18:       establish_connections
19:       @round_robin = (0...@backend_connections.length).to_a
20:     end

Public Instance Methods

all_worker_info() click to toggle source

Send worker information of all currently running workers from all configured bdrb servers

     # File lib/backgroundrb/bdrb_cluster_connection.rb, line 119
119:     def all_worker_info
120:       update_stats
121:       info_data = {}
122:       @backend_connections.each do |t_connection|
123:         info_data[t_connection.server_info] = t_connection.all_worker_info rescue nil
124:       end
125:       return info_data
126:     end
choose_server() click to toggle source

choose a server in round robin manner.

     # File lib/backgroundrb/bdrb_cluster_connection.rb, line 143
143:     def choose_server
144:       if @round_robin.empty?
145:         @round_robin = (0...@backend_connections.length).to_a
146:       end
147:       if @round_robin.empty? && @backend_connections.empty?
148:         discover_server_periodically
149:         raise NoServerAvailable.new("No BackgrounDRb server is found running") if @round_robin.empty? && @backend_connections.empty?
150:       end
151:       @backend_connections[@round_robin.shift]
152:     end
discover_server_periodically() click to toggle source

every 10 request or 10 seconds it will try to reconnect to bdrb servers which were down

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 56
56:     def discover_server_periodically
57:       @disconnected_connections.each do |key,connection|
58:         connection.establish_connection
59:         if connection.connection_status
60:           @backend_connections << connection
61:           connection.close_connection
62:           @disconnected_connections[key] = nil
63:         end
64:       end
65:       @disconnected_connections.delete_if { |key,value| value.nil? }
66:       @round_robin = (0...@backend_connections.length).to_a
67:     end
establish_connections() click to toggle source

initialize all backend server connections

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 38
38:     def establish_connections
39:       klass = Struct.new(:ip,:port)
40:       if t_servers = BDRB_CONFIG[:client]
41:         connections = t_servers.split(',')
42:         connections.each do |conn_string|
43:           ip = conn_string.split(':')[0]
44:           port = conn_string.split(':')[1].to_i
45:           @bdrb_servers << klass.new(ip,port)
46:         end
47:       end
48:       @bdrb_servers << klass.new(BDRB_CONFIG[:backgroundrb][:ip],BDRB_CONFIG[:backgroundrb][:port].to_i)
49:       @bdrb_servers.each_with_index do |connection_info,index|
50:         next if @backend_connections.detect { |x| x.server_info == "#{connection_info.ip}:#{connection_info.port}" }
51:         @backend_connections << Connection.new(connection_info.ip,connection_info.port,self)
52:       end
53:     end
find_connection(host_info) click to toggle source

Fina a connection by host name and port

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 84
84:     def find_connection host_info
85:       conn = @backend_connections.detect { |x| x.server_info == host_info }
86:       raise NoServerAvailable.new("BackgrounDRb server is not found running on #{host_info}") unless conn
87:       return conn
88:     end
find_local() click to toggle source

find the local configured connection

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 91
91:     def find_local
92:       find_connection("#{BDRB_CONFIG[:backgroundrb][:ip]}:#{BDRB_CONFIG[:backgroundrb][:port]}")
93:     end
find_next_except_these(connections) click to toggle source

Find live connections except those mentioned in array, because they are already dead.

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 71
71:     def find_next_except_these connections
72:       invalid_connections = @backend_connections.select { |x| connections.include?(x.server_info) }
73:       @backend_connections.delete_if { |x| connections.include?(x.server_info) }
74:       @round_robin = (0...@backend_connections.length).to_a
75:       invalid_connections.each do |x|
76:         @disconnected_connections[x.server_info] = x
77:       end
78:       chosen = @backend_connections.detect { |x| !(connections.include?(x.server_info)) }
79:       raise NoServerAvailable.new("No BackgrounDRb server is found running") unless chosen
80:       chosen
81:     end
initialize_memcache() click to toggle source

initialize memache if client is storing results in memcache

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 23
23:     def initialize_memcache
24:       require 'memcache'
25:       memcache_options = {
26:         :c_threshold => 10_000,
27:         :compression => true,
28:         :debug => false,
29:         :namespace => 'backgroundrb_result_hash',
30:         :readonly => false,
31:         :urlencode => false
32:       }
33:       @cache = MemCache.new(memcache_options)
34:       @cache.servers = BDRB_CONFIG[:memcache].split(',')
35:     end
new_worker(options = {}) click to toggle source

one of the backend connections are chosen and worker is started on it

     # File lib/backgroundrb/bdrb_cluster_connection.rb, line 129
129:     def new_worker(options = {})
130:       update_stats
131:       succeeded = false
132:       @backend_connections.each do |connection|
133:         begin
134:           connection.new_worker(options)
135:           succeeded = true
136:         rescue BdrbConnError; end
137:       end
138:       raise NoServerAvailable.new("No BackgrounDRb server is found running") unless succeeded
139:       return options[:worker_key]
140:     end
time_to_discover?() click to toggle source

Check if, we should try to discover new bdrb servers

     # File lib/backgroundrb/bdrb_cluster_connection.rb, line 108
108:     def time_to_discover?
109:       if((@request_count%10 == 0) or (Time.now > (@last_polled_time + 10.seconds)))
110:         @last_polled_time = Time.now
111:         return true
112:       else
113:         return false
114:       end
115:     end
update_stats() click to toggle source

Update the stats and discover new nodes if they came up.

     # File lib/backgroundrb/bdrb_cluster_connection.rb, line 102
102:     def update_stats
103:       @request_count += 1
104:       discover_server_periodically if(time_to_discover? && !@disconnected_connections.empty?)
105:     end
worker(worker_name,worker_key = nil) click to toggle source

return the worker proxy

    # File lib/backgroundrb/bdrb_cluster_connection.rb, line 96
96:     def worker(worker_name,worker_key = nil)
97:       update_stats
98:       RailsWorkerProxy.new(worker_name,worker_key,self)
99:     end

secsequence

--- SEC00006

seccomment

--- ""

attributes

--- 
- name: backend_connections
  rw: RW
  a_desc: ""
- name: bdrb_servers
  rw: RW
  a_desc: ""
- name: cache
  rw: RW
  a_desc: ""
- name: config
  rw: RW
  a_desc: ""
- name: disconnected_connections
  rw: RW
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000051
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 9</span>\n 9:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>\n\
      10:       <span class=\"ruby-ivar\">@bdrb_servers</span> = []\n\
      11:       <span class=\"ruby-ivar\">@backend_connections</span> = []\n\
      12:       <span class=\"ruby-ivar\">@disconnected_connections</span> = {}\n\
      13: \n\
      14:       <span class=\"ruby-ivar\">@last_polled_time</span> = <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>\n\
      15:       <span class=\"ruby-ivar\">@request_count</span> = <span class=\"ruby-value\">0</span>\n\
      16: \n\
      17:       <span class=\"ruby-identifier\">initialize_memcache</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:result_storage</span>] <span class=\"ruby-operator\">==</span> <span class=\"ruby-value str\">'memcache'</span>\n\
      18:       <span class=\"ruby-identifier\">establish_connections</span>\n\
      19:       <span class=\"ruby-ivar\">@round_robin</span> = (<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">...</span><span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">length</span>).<span class=\"ruby-identifier\">to_a</span>\n\
      20:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      initialize cluster connection
      </p>
    params: ()
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000061
    name: all_worker_info
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 119</span>\n\
      119:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">all_worker_info</span>\n\
      120:       <span class=\"ruby-identifier\">update_stats</span>\n\
      121:       <span class=\"ruby-identifier\">info_data</span> = {}\n\
      122:       <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">t_connection</span><span class=\"ruby-operator\">|</span>\n\
      123:         <span class=\"ruby-identifier\">info_data</span>[<span class=\"ruby-identifier\">t_connection</span>.<span class=\"ruby-identifier\">server_info</span>] = <span class=\"ruby-identifier\">t_connection</span>.<span class=\"ruby-identifier\">all_worker_info</span> <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-keyword kw\">nil</span>\n\
      124:       <span class=\"ruby-keyword kw\">end</span>\n\
      125:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">info_data</span>\n\
      126:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Send worker information of all currently running workers from all
      configured bdrb servers
      </p>
    params: ()
  - visibility: public
    aref: M000063
    name: choose_server
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 143</span>\n\
      143:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">choose_server</span>\n\
      144:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@round_robin</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      145:         <span class=\"ruby-ivar\">@round_robin</span> = (<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">...</span><span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">length</span>).<span class=\"ruby-identifier\">to_a</span>\n\
      146:       <span class=\"ruby-keyword kw\">end</span>\n\
      147:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@round_robin</span>.<span class=\"ruby-identifier\">empty?</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      148:         <span class=\"ruby-identifier\">discover_server_periodically</span>\n\
      149:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;No BackgrounDRb server is found running&quot;</span>) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@round_robin</span>.<span class=\"ruby-identifier\">empty?</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      150:       <span class=\"ruby-keyword kw\">end</span>\n\
      151:       <span class=\"ruby-ivar\">@backend_connections</span>[<span class=\"ruby-ivar\">@round_robin</span>.<span class=\"ruby-identifier\">shift</span>]\n\
      152:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      choose a server in round robin manner.
      </p>
    params: ()
  - visibility: public
    aref: M000054
    name: discover_server_periodically
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 56</span>\n\
      56:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">discover_server_periodically</span>\n\
      57:       <span class=\"ruby-ivar\">@disconnected_connections</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">connection</span><span class=\"ruby-operator\">|</span>\n\
      58:         <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">establish_connection</span>\n\
      59:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">connection_status</span>\n\
      60:           <span class=\"ruby-ivar\">@backend_connections</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">connection</span>\n\
      61:           <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">close_connection</span>\n\
      62:           <span class=\"ruby-ivar\">@disconnected_connections</span>[<span class=\"ruby-identifier\">key</span>] = <span class=\"ruby-keyword kw\">nil</span>\n\
      63:         <span class=\"ruby-keyword kw\">end</span>\n\
      64:       <span class=\"ruby-keyword kw\">end</span>\n\
      65:       <span class=\"ruby-ivar\">@disconnected_connections</span>.<span class=\"ruby-identifier\">delete_if</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">value</span>.<span class=\"ruby-identifier\">nil?</span> }\n\
      66:       <span class=\"ruby-ivar\">@round_robin</span> = (<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">...</span><span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">length</span>).<span class=\"ruby-identifier\">to_a</span>\n\
      67:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      every 10 request or 10 seconds it will try to reconnect to bdrb servers
      which were down
      </p>
    params: ()
  - visibility: public
    aref: M000053
    name: establish_connections
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 38</span>\n\
      38:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">establish_connections</span>\n\
      39:       <span class=\"ruby-identifier\">klass</span> = <span class=\"ruby-constant\">Struct</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">:ip</span>,<span class=\"ruby-identifier\">:port</span>)\n\
      40:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">t_servers</span> = <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:client</span>]\n\
      41:         <span class=\"ruby-identifier\">connections</span> = <span class=\"ruby-identifier\">t_servers</span>.<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">','</span>)\n\
      42:         <span class=\"ruby-identifier\">connections</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">conn_string</span><span class=\"ruby-operator\">|</span>\n\
      43:           <span class=\"ruby-identifier\">ip</span> = <span class=\"ruby-identifier\">conn_string</span>.<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">':'</span>)[<span class=\"ruby-value\">0</span>]\n\
      44:           <span class=\"ruby-identifier\">port</span> = <span class=\"ruby-identifier\">conn_string</span>.<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">':'</span>)[<span class=\"ruby-value\">1</span>].<span class=\"ruby-identifier\">to_i</span>\n\
      45:           <span class=\"ruby-ivar\">@bdrb_servers</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">ip</span>,<span class=\"ruby-identifier\">port</span>)\n\
      46:         <span class=\"ruby-keyword kw\">end</span>\n\
      47:       <span class=\"ruby-keyword kw\">end</span>\n\
      48:       <span class=\"ruby-ivar\">@bdrb_servers</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:ip</span>],<span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:port</span>].<span class=\"ruby-identifier\">to_i</span>)\n\
      49:       <span class=\"ruby-ivar\">@bdrb_servers</span>.<span class=\"ruby-identifier\">each_with_index</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">connection_info</span>,<span class=\"ruby-identifier\">index</span><span class=\"ruby-operator\">|</span>\n\
      50:         <span class=\"ruby-keyword kw\">next</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">x</span>.<span class=\"ruby-identifier\">server_info</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-node\">&quot;#{connection_info.ip}:#{connection_info.port}&quot;</span> }\n\
      51:         <span class=\"ruby-ivar\">@backend_connections</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-constant\">Connection</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">connection_info</span>.<span class=\"ruby-identifier\">ip</span>,<span class=\"ruby-identifier\">connection_info</span>.<span class=\"ruby-identifier\">port</span>,<span class=\"ruby-keyword kw\">self</span>)\n\
      52:       <span class=\"ruby-keyword kw\">end</span>\n\
      53:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      initialize all backend server connections
      </p>
    params: ()
  - visibility: public
    aref: M000056
    name: find_connection
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 84</span>\n\
      84:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">find_connection</span> <span class=\"ruby-identifier\">host_info</span>\n\
      85:       <span class=\"ruby-identifier\">conn</span> = <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">x</span>.<span class=\"ruby-identifier\">server_info</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">host_info</span> }\n\
      86:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-node\">&quot;BackgrounDRb server is not found running on #{host_info}&quot;</span>) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">conn</span>\n\
      87:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">conn</span>\n\
      88:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Fina a connection by host name and port
      </p>
    params: (host_info)
  - visibility: public
    aref: M000057
    name: find_local
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 91</span>\n\
      91:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">find_local</span>\n\
      92:       <span class=\"ruby-identifier\">find_connection</span>(<span class=\"ruby-node\">&quot;#{BDRB_CONFIG[:backgroundrb][:ip]}:#{BDRB_CONFIG[:backgroundrb][:port]}&quot;</span>)\n\
      93:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      find the local configured connection
      </p>
    params: ()
  - visibility: public
    aref: M000055
    name: find_next_except_these
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 71</span>\n\
      71:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">find_next_except_these</span> <span class=\"ruby-identifier\">connections</span>\n\
      72:       <span class=\"ruby-identifier\">invalid_connections</span> = <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">select</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">connections</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-identifier\">x</span>.<span class=\"ruby-identifier\">server_info</span>) }\n\
      73:       <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">delete_if</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">connections</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-identifier\">x</span>.<span class=\"ruby-identifier\">server_info</span>) }\n\
      74:       <span class=\"ruby-ivar\">@round_robin</span> = (<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">...</span><span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">length</span>).<span class=\"ruby-identifier\">to_a</span>\n\
      75:       <span class=\"ruby-identifier\">invalid_connections</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span>\n\
      76:         <span class=\"ruby-ivar\">@disconnected_connections</span>[<span class=\"ruby-identifier\">x</span>.<span class=\"ruby-identifier\">server_info</span>] = <span class=\"ruby-identifier\">x</span>\n\
      77:       <span class=\"ruby-keyword kw\">end</span>\n\
      78:       <span class=\"ruby-identifier\">chosen</span> = <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-operator\">!</span>(<span class=\"ruby-identifier\">connections</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-identifier\">x</span>.<span class=\"ruby-identifier\">server_info</span>)) }\n\
      79:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;No BackgrounDRb server is found running&quot;</span>) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">chosen</span>\n\
      80:       <span class=\"ruby-identifier\">chosen</span>\n\
      81:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Find live connections except those mentioned in array, because they are
      already dead.
      </p>
    params: (connections)
  - visibility: public
    aref: M000052
    name: initialize_memcache
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 23</span>\n\
      23:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize_memcache</span>\n\
      24:       <span class=\"ruby-identifier\">require</span> <span class=\"ruby-value str\">'memcache'</span>\n\
      25:       <span class=\"ruby-identifier\">memcache_options</span> = {\n\
      26:         <span class=\"ruby-identifier\">:c_threshold</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-value\">10_000</span>,\n\
      27:         <span class=\"ruby-identifier\">:compression</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">true</span>,\n\
      28:         <span class=\"ruby-identifier\">:debug</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>,\n\
      29:         <span class=\"ruby-identifier\">:namespace</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-value str\">'backgroundrb_result_hash'</span>,\n\
      30:         <span class=\"ruby-identifier\">:readonly</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>,\n\
      31:         <span class=\"ruby-identifier\">:urlencode</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>\n\
      32:       }\n\
      33:       <span class=\"ruby-ivar\">@cache</span> = <span class=\"ruby-constant\">MemCache</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">memcache_options</span>)\n\
      34:       <span class=\"ruby-ivar\">@cache</span>.<span class=\"ruby-identifier\">servers</span> = <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:memcache</span>].<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">','</span>)\n\
      35:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      initialize memache if client is storing results in memcache
      </p>
    params: ()
  - visibility: public
    aref: M000062
    name: new_worker
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 129</span>\n\
      129:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">new_worker</span>(<span class=\"ruby-identifier\">options</span> = {})\n\
      130:       <span class=\"ruby-identifier\">update_stats</span>\n\
      131:       <span class=\"ruby-identifier\">succeeded</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      132:       <span class=\"ruby-ivar\">@backend_connections</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">connection</span><span class=\"ruby-operator\">|</span>\n\
      133:         <span class=\"ruby-keyword kw\">begin</span>\n\
      134:           <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">new_worker</span>(<span class=\"ruby-identifier\">options</span>)\n\
      135:           <span class=\"ruby-identifier\">succeeded</span> = <span class=\"ruby-keyword kw\">true</span>\n\
      136:         <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">BdrbConnError</span>; <span class=\"ruby-keyword kw\">end</span>\n\
      137:       <span class=\"ruby-keyword kw\">end</span>\n\
      138:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;No BackgrounDRb server is found running&quot;</span>) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">succeeded</span>\n\
      139:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:worker_key</span>]\n\
      140:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      one of the backend connections are chosen and worker is started on it
      </p>
    params: (options = {})
  - visibility: public
    aref: M000060
    name: time_to_discover?
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 108</span>\n\
      108:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">time_to_discover?</span>\n\
      109:       <span class=\"ruby-keyword kw\">if</span>((<span class=\"ruby-ivar\">@request_count</span><span class=\"ruby-operator\">%</span><span class=\"ruby-value\">10</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">0</span>) <span class=\"ruby-keyword kw\">or</span> (<span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span> <span class=\"ruby-operator\">&gt;</span> (<span class=\"ruby-ivar\">@last_polled_time</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">10</span>.<span class=\"ruby-identifier\">seconds</span>)))\n\
      110:         <span class=\"ruby-ivar\">@last_polled_time</span> = <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>\n\
      111:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">true</span>\n\
      112:       <span class=\"ruby-keyword kw\">else</span>\n\
      113:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">false</span>\n\
      114:       <span class=\"ruby-keyword kw\">end</span>\n\
      115:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Check if, we should try to discover new bdrb servers
      </p>
    params: ()
  - visibility: public
    aref: M000059
    name: update_stats
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 102</span>\n\
      102:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">update_stats</span>\n\
      103:       <span class=\"ruby-ivar\">@request_count</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-value\">1</span>\n\
      104:       <span class=\"ruby-identifier\">discover_server_periodically</span> <span class=\"ruby-keyword kw\">if</span>(<span class=\"ruby-identifier\">time_to_discover?</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-ivar\">@disconnected_connections</span>.<span class=\"ruby-identifier\">empty?</span>)\n\
      105:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Update the stats and discover new nodes if they came up.
      </p>
    params: ()
  - visibility: public
    aref: M000058
    name: worker
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_cluster_connection.rb, line 96</span>\n\
      96:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">worker</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">worker_key</span> = <span class=\"ruby-keyword kw\">nil</span>)\n\
      97:       <span class=\"ruby-identifier\">update_stats</span>\n\
      98:       <span class=\"ruby-constant\">RailsWorkerProxy</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">worker_key</span>,<span class=\"ruby-keyword kw\">self</span>)\n\
      99:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      return the worker proxy
      </p>
    params: (worker_name,worker_key = nil)
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.