Parent

BackgrounDRb::Connection

Attributes

cluster_conn[RW]

(Not documented)

connection_status[RW]

(Not documented)

server_ip[RW]

(Not documented)

server_port[RW]

(Not documented)

Public Class Methods

new(ip,port,cluster_conn) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 5
 5:     def initialize ip,port,cluster_conn
 6:       @mutex = Mutex.new
 7:       @server_ip = ip
 8:       @server_port = port
 9:       @cluster_conn = cluster_conn
10:       @connection_status = true
11:     end

Public Instance Methods

all_worker_info() click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 106
106:     def all_worker_info
107:       p_data = { }
108:       p_data[:type] = :all_worker_info
109:       dump_object(p_data)
110:       bdrb_response = nil
111:       @mutex.synchronize { bdrb_response = read_from_bdrb() }
112:       close_connection
113:       bdrb_response
114:     end
ask_result(p_data) click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 142
142:     def ask_result(p_data)
143:       if BDRB_CONFIG[:backgroundrb][:result_storage] == 'memcache'
144:         return_result_from_memcache(p_data)
145:       else
146:         p_data[:type] = :get_result
147:         dump_object(p_data)
148:         bdrb_response = nil
149:         @mutex.synchronize { bdrb_response = read_from_bdrb() }
150:         close_connection
151:         bdrb_response ? bdrb_response[:data] : nil
152:       end
153:     end
ask_work(p_data) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 84
84:     def ask_work p_data
85:       p_data[:type] = :async_invoke
86:       dump_object(p_data)
87:       close_connection
88:     end
close_connection() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 79
79:     def close_connection
80:       @connection.close
81:       @connection = nil
82:     end
delete_worker(p_data) click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 116
116:     def delete_worker p_data
117:       p_data[:type] = :delete_worker
118:       dump_object(p_data)
119:       close_connection
120:     end
dump_object(data) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 68
68:     def dump_object data
69:       establish_connection
70:       raise BackgrounDRb::BdrbConnError.new("Error while connecting to the backgroundrb server #{server_info}") unless @connection_status
71: 
72:       object_dump = Marshal.dump(data)
73:       dump_length = object_dump.length.to_s
74:       length_str = dump_length.rjust(9,'0')
75:       final_data = length_str + object_dump
76:       @mutex.synchronize { write_data(final_data) }
77:     end
establish_connection() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 14
14:     def establish_connection
15:       begin
16:         timeout(3) do
17:           @connection = TCPSocket.open(server_ip, server_port)
18:           @connection.setsockopt(Socket::IPPROTO_TCP,Socket::TCP_NODELAY,1)
19:         end
20:         @connection_status = true
21:       rescue Timeout::Error
22:         @connection_status = false
23:       rescue Exception => e
24:         @connection_status = false
25:       end
26:     end
flush_in_loop(data) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 56
56:     def flush_in_loop(data)
57:       t_length = data.length
58:       loop do
59:         break if t_length <= 0
60:         written_length = @connection.write(data)
61:         raise "Error writing to socket" if written_length <= 0
62:         result = @connection.flush
63:         data = data[written_length..-1]
64:         t_length = data.length
65:       end
66:     end
gen_key(options) click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 133
133:     def gen_key options
134:       if BDRB_CONFIG[:backgroundrb][:result_storage] == 'memcache'
135:         key = [options[:worker],options[:worker_key],options[:job_key]].compact.join('_')
136:         key
137:       else
138:         options[:job_key]
139:       end
140:     end
new_worker(p_data) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 90
90:     def new_worker p_data
91:       p_data[:type] = :start_worker
92:       dump_object(p_data)
93:       close_connection
94:       # RailsWorkerProxy.worker(p_data[:worker],p_data[:worker_key],self)
95:     end
read_from_bdrb(timeout = 3) click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 155
155:     def read_from_bdrb(timeout = 3)
156:       begin
157:         ret_val = select([@connection],nil,nil,timeout)
158:         return nil unless ret_val
159:         raw_response = read_object()
160:         master_response = Marshal.load(raw_response)
161:         return master_response
162:       rescue
163:         return nil
164:       end
165:     end
read_object() click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 122
122:     def read_object
123:       begin
124:         message_length_str = @connection.read(9)
125:         message_length = message_length_str.to_i
126:         message_data = @connection.read(message_length)
127:         return message_data
128:       rescue
129:         raise BackgrounDRb::BdrbConnError.new("Not able to connect #{server_info}")
130:       end
131:     end
send_request(p_data) click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 167
167:     def send_request(p_data)
168:       p_data[:type] = :sync_invoke
169:       dump_object(p_data)
170:       bdrb_response = nil
171:       @mutex.synchronize { bdrb_response = read_from_bdrb(nil) }
172:       close_connection
173:       bdrb_response ? bdrb_response[:data] : nil
174:     end
server_info() click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 52
52:     def server_info
53:       "#{server_ip}:#{server_port}"
54:     end
worker_info(p_data) click to toggle source

(Not documented)

     # File lib/backgroundrb/bdrb_connection.rb, line 97
 97:     def worker_info(p_data)
 98:       p_data[:type] = :worker_info
 99:       dump_object(p_data)
100:       bdrb_response = nil
101:       @mutex.synchronize { bdrb_response = read_from_bdrb() }
102:       close_connection
103:       bdrb_response
104:     end
write_data(data) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_connection.rb, line 28
28:     def write_data data
29:       begin
30:         flush_in_loop(data)
31:       rescue Errno::EAGAIN
32:         return
33:       rescue Errno::EPIPE
34:         establish_connection
35:         if @connection_status
36:           flush_in_loop(data)
37:         else
38:           @connection_status = false
39:           raise BackgrounDRb::BdrbConnError.new("Error while writing #{server_info}")
40:         end
41:       rescue
42:         establish_connection
43:         if @connection_status
44:           flush_in_loop(data)
45:         else
46:           @connection_status = false
47:           raise BackgrounDRb::BdrbConnError.new("Error while writing #{server_info}")
48:         end
49:       end
50:     end

secsequence

--- SEC00022

seccomment

--- ""

attributes

--- 
- name: cluster_conn
  rw: RW
  a_desc: ""
- name: connection_status
  rw: RW
  a_desc: ""
- name: server_ip
  rw: RW
  a_desc: ""
- name: server_port
  rw: RW
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000083
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 5</span>\n 5:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span> <span class=\"ruby-identifier\">ip</span>,<span class=\"ruby-identifier\">port</span>,<span class=\"ruby-identifier\">cluster_conn</span>\n 6:       <span class=\"ruby-ivar\">@mutex</span> = <span class=\"ruby-constant\">Mutex</span>.<span class=\"ruby-identifier\">new</span>\n 7:       <span class=\"ruby-ivar\">@server_ip</span> = <span class=\"ruby-identifier\">ip</span>\n 8:       <span class=\"ruby-ivar\">@server_port</span> = <span class=\"ruby-identifier\">port</span>\n 9:       <span class=\"ruby-ivar\">@cluster_conn</span> = <span class=\"ruby-identifier\">cluster_conn</span>\n\
      10:       <span class=\"ruby-ivar\">@connection_status</span> = <span class=\"ruby-keyword kw\">true</span>\n\
      11:     <span class=\"ruby-keyword kw\">end</span>"
    params: (ip,port,cluster_conn)
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000093
    name: all_worker_info
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 106</span>\n\
      106:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">all_worker_info</span>\n\
      107:       <span class=\"ruby-identifier\">p_data</span> = { }\n\
      108:       <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:all_worker_info</span>\n\
      109:       <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      110:       <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      111:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-identifier\">read_from_bdrb</span>() }\n\
      112:       <span class=\"ruby-identifier\">close_connection</span>\n\
      113:       <span class=\"ruby-identifier\">bdrb_response</span>\n\
      114:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000097
    name: ask_result
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 142</span>\n\
      142:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">ask_result</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      143:       <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\
      144:         <span class=\"ruby-identifier\">return_result_from_memcache</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      145:       <span class=\"ruby-keyword kw\">else</span>\n\
      146:         <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:get_result</span>\n\
      147:         <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      148:         <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      149:         <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-identifier\">read_from_bdrb</span>() }\n\
      150:         <span class=\"ruby-identifier\">close_connection</span>\n\
      151:         <span class=\"ruby-identifier\">bdrb_response</span> <span class=\"ruby-value\">? </span><span class=\"ruby-identifier\">bdrb_response</span>[<span class=\"ruby-identifier\">:data</span>] <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">nil</span>\n\
      152:       <span class=\"ruby-keyword kw\">end</span>\n\
      153:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_data)
  - visibility: public
    aref: M000090
    name: ask_work
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 84</span>\n\
      84:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">ask_work</span> <span class=\"ruby-identifier\">p_data</span>\n\
      85:       <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:async_invoke</span>\n\
      86:       <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      87:       <span class=\"ruby-identifier\">close_connection</span>\n\
      88:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_data)
  - visibility: public
    aref: M000089
    name: close_connection
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 79</span>\n\
      79:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">close_connection</span>\n\
      80:       <span class=\"ruby-ivar\">@connection</span>.<span class=\"ruby-identifier\">close</span>\n\
      81:       <span class=\"ruby-ivar\">@connection</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      82:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000094
    name: delete_worker
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 116</span>\n\
      116:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">delete_worker</span> <span class=\"ruby-identifier\">p_data</span>\n\
      117:       <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:delete_worker</span>\n\
      118:       <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      119:       <span class=\"ruby-identifier\">close_connection</span>\n\
      120:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_data)
  - visibility: public
    aref: M000088
    name: dump_object
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 68</span>\n\
      68:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">dump_object</span> <span class=\"ruby-identifier\">data</span>\n\
      69:       <span class=\"ruby-identifier\">establish_connection</span>\n\
      70:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BdrbConnError</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-node\">&quot;Error while connecting to the backgroundrb server #{server_info}&quot;</span>) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@connection_status</span>\n\
      71: \n\
      72:       <span class=\"ruby-identifier\">object_dump</span> = <span class=\"ruby-constant\">Marshal</span>.<span class=\"ruby-identifier\">dump</span>(<span class=\"ruby-identifier\">data</span>)\n\
      73:       <span class=\"ruby-identifier\">dump_length</span> = <span class=\"ruby-identifier\">object_dump</span>.<span class=\"ruby-identifier\">length</span>.<span class=\"ruby-identifier\">to_s</span>\n\
      74:       <span class=\"ruby-identifier\">length_str</span> = <span class=\"ruby-identifier\">dump_length</span>.<span class=\"ruby-identifier\">rjust</span>(<span class=\"ruby-value\">9</span>,<span class=\"ruby-value str\">'0'</span>)\n\
      75:       <span class=\"ruby-identifier\">final_data</span> = <span class=\"ruby-identifier\">length_str</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">object_dump</span>\n\
      76:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-identifier\">write_data</span>(<span class=\"ruby-identifier\">final_data</span>) }\n\
      77:     <span class=\"ruby-keyword kw\">end</span>"
    params: (data)
  - visibility: public
    aref: M000084
    name: establish_connection
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 14</span>\n\
      14:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">establish_connection</span>\n\
      15:       <span class=\"ruby-keyword kw\">begin</span>\n\
      16:         <span class=\"ruby-identifier\">timeout</span>(<span class=\"ruby-value\">3</span>) <span class=\"ruby-keyword kw\">do</span>\n\
      17:           <span class=\"ruby-ivar\">@connection</span> = <span class=\"ruby-constant\">TCPSocket</span>.<span class=\"ruby-identifier\">open</span>(<span class=\"ruby-identifier\">server_ip</span>, <span class=\"ruby-identifier\">server_port</span>)\n\
      18:           <span class=\"ruby-ivar\">@connection</span>.<span class=\"ruby-identifier\">setsockopt</span>(<span class=\"ruby-constant\">Socket</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">IPPROTO_TCP</span>,<span class=\"ruby-constant\">Socket</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">TCP_NODELAY</span>,<span class=\"ruby-value\">1</span>)\n\
      19:         <span class=\"ruby-keyword kw\">end</span>\n\
      20:         <span class=\"ruby-ivar\">@connection_status</span> = <span class=\"ruby-keyword kw\">true</span>\n\
      21:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Timeout</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Error</span>\n\
      22:         <span class=\"ruby-ivar\">@connection_status</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      23:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Exception</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">e</span>\n\
      24:         <span class=\"ruby-ivar\">@connection_status</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      25:       <span class=\"ruby-keyword kw\">end</span>\n\
      26:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000087
    name: flush_in_loop
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 56</span>\n\
      56:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">flush_in_loop</span>(<span class=\"ruby-identifier\">data</span>)\n\
      57:       <span class=\"ruby-identifier\">t_length</span> = <span class=\"ruby-identifier\">data</span>.<span class=\"ruby-identifier\">length</span>\n\
      58:       <span class=\"ruby-identifier\">loop</span> <span class=\"ruby-keyword kw\">do</span>\n\
      59:         <span class=\"ruby-keyword kw\">break</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">t_length</span> <span class=\"ruby-operator\">&lt;=</span> <span class=\"ruby-value\">0</span>\n\
      60:         <span class=\"ruby-identifier\">written_length</span> = <span class=\"ruby-ivar\">@connection</span>.<span class=\"ruby-identifier\">write</span>(<span class=\"ruby-identifier\">data</span>)\n\
      61:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-value str\">&quot;Error writing to socket&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">written_length</span> <span class=\"ruby-operator\">&lt;=</span> <span class=\"ruby-value\">0</span>\n\
      62:         <span class=\"ruby-identifier\">result</span> = <span class=\"ruby-ivar\">@connection</span>.<span class=\"ruby-identifier\">flush</span>\n\
      63:         <span class=\"ruby-identifier\">data</span> = <span class=\"ruby-identifier\">data</span>[<span class=\"ruby-identifier\">written_length</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">-1</span>]\n\
      64:         <span class=\"ruby-identifier\">t_length</span> = <span class=\"ruby-identifier\">data</span>.<span class=\"ruby-identifier\">length</span>\n\
      65:       <span class=\"ruby-keyword kw\">end</span>\n\
      66:     <span class=\"ruby-keyword kw\">end</span>"
    params: (data)
  - visibility: public
    aref: M000096
    name: gen_key
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 133</span>\n\
      133:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">gen_key</span> <span class=\"ruby-identifier\">options</span>\n\
      134:       <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\
      135:         <span class=\"ruby-identifier\">key</span> = [<span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:worker</span>],<span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:worker_key</span>],<span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:job_key</span>]].<span class=\"ruby-identifier\">compact</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">'_'</span>)\n\
      136:         <span class=\"ruby-identifier\">key</span>\n\
      137:       <span class=\"ruby-keyword kw\">else</span>\n\
      138:         <span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:job_key</span>]\n\
      139:       <span class=\"ruby-keyword kw\">end</span>\n\
      140:     <span class=\"ruby-keyword kw\">end</span>"
    params: (options)
  - visibility: public
    aref: M000091
    name: new_worker
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 90</span>\n\
      90:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">new_worker</span> <span class=\"ruby-identifier\">p_data</span>\n\
      91:       <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:start_worker</span>\n\
      92:       <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      93:       <span class=\"ruby-identifier\">close_connection</span>\n\
      94:       <span class=\"ruby-comment cmt\"># RailsWorkerProxy.worker(p_data[:worker],p_data[:worker_key],self)</span>\n\
      95:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_data)
  - visibility: public
    aref: M000098
    name: read_from_bdrb
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 155</span>\n\
      155:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">read_from_bdrb</span>(<span class=\"ruby-identifier\">timeout</span> = <span class=\"ruby-value\">3</span>)\n\
      156:       <span class=\"ruby-keyword kw\">begin</span>\n\
      157:         <span class=\"ruby-identifier\">ret_val</span> = <span class=\"ruby-identifier\">select</span>([<span class=\"ruby-ivar\">@connection</span>],<span class=\"ruby-keyword kw\">nil</span>,<span class=\"ruby-keyword kw\">nil</span>,<span class=\"ruby-identifier\">timeout</span>)\n\
      158:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">ret_val</span>\n\
      159:         <span class=\"ruby-identifier\">raw_response</span> = <span class=\"ruby-identifier\">read_object</span>()\n\
      160:         <span class=\"ruby-identifier\">master_response</span> = <span class=\"ruby-constant\">Marshal</span>.<span class=\"ruby-identifier\">load</span>(<span class=\"ruby-identifier\">raw_response</span>)\n\
      161:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">master_response</span>\n\
      162:       <span class=\"ruby-keyword kw\">rescue</span>\n\
      163:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span>\n\
      164:       <span class=\"ruby-keyword kw\">end</span>\n\
      165:     <span class=\"ruby-keyword kw\">end</span>"
    params: (timeout = 3)
  - visibility: public
    aref: M000095
    name: read_object
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 122</span>\n\
      122:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">read_object</span>\n\
      123:       <span class=\"ruby-keyword kw\">begin</span>\n\
      124:         <span class=\"ruby-identifier\">message_length_str</span> = <span class=\"ruby-ivar\">@connection</span>.<span class=\"ruby-identifier\">read</span>(<span class=\"ruby-value\">9</span>)\n\
      125:         <span class=\"ruby-identifier\">message_length</span> = <span class=\"ruby-identifier\">message_length_str</span>.<span class=\"ruby-identifier\">to_i</span>\n\
      126:         <span class=\"ruby-identifier\">message_data</span> = <span class=\"ruby-ivar\">@connection</span>.<span class=\"ruby-identifier\">read</span>(<span class=\"ruby-identifier\">message_length</span>)\n\
      127:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">message_data</span>\n\
      128:       <span class=\"ruby-keyword kw\">rescue</span>\n\
      129:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BdrbConnError</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-node\">&quot;Not able to connect #{server_info}&quot;</span>)\n\
      130:       <span class=\"ruby-keyword kw\">end</span>\n\
      131:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000099
    name: send_request
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 167</span>\n\
      167:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">send_request</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      168:       <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:sync_invoke</span>\n\
      169:       <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      170:       <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      171:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-identifier\">read_from_bdrb</span>(<span class=\"ruby-keyword kw\">nil</span>) }\n\
      172:       <span class=\"ruby-identifier\">close_connection</span>\n\
      173:       <span class=\"ruby-identifier\">bdrb_response</span> <span class=\"ruby-value\">? </span><span class=\"ruby-identifier\">bdrb_response</span>[<span class=\"ruby-identifier\">:data</span>] <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">nil</span>\n\
      174:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_data)
  - visibility: public
    aref: M000086
    name: server_info
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 52</span>\n\
      52:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">server_info</span>\n\
      53:       <span class=\"ruby-node\">&quot;#{server_ip}:#{server_port}&quot;</span>\n\
      54:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000092
    name: worker_info
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 97</span>\n 97:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">worker_info</span>(<span class=\"ruby-identifier\">p_data</span>)\n 98:       <span class=\"ruby-identifier\">p_data</span>[<span class=\"ruby-identifier\">:type</span>] = <span class=\"ruby-identifier\">:worker_info</span>\n 99:       <span class=\"ruby-identifier\">dump_object</span>(<span class=\"ruby-identifier\">p_data</span>)\n\
      100:       <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      101:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-identifier\">bdrb_response</span> = <span class=\"ruby-identifier\">read_from_bdrb</span>() }\n\
      102:       <span class=\"ruby-identifier\">close_connection</span>\n\
      103:       <span class=\"ruby-identifier\">bdrb_response</span>\n\
      104:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_data)
  - visibility: public
    aref: M000085
    name: write_data
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_connection.rb, line 28</span>\n\
      28:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">write_data</span> <span class=\"ruby-identifier\">data</span>\n\
      29:       <span class=\"ruby-keyword kw\">begin</span>\n\
      30:         <span class=\"ruby-identifier\">flush_in_loop</span>(<span class=\"ruby-identifier\">data</span>)\n\
      31:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Errno</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">EAGAIN</span>\n\
      32:         <span class=\"ruby-keyword kw\">return</span>\n\
      33:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Errno</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">EPIPE</span>\n\
      34:         <span class=\"ruby-identifier\">establish_connection</span>\n\
      35:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@connection_status</span>\n\
      36:           <span class=\"ruby-identifier\">flush_in_loop</span>(<span class=\"ruby-identifier\">data</span>)\n\
      37:         <span class=\"ruby-keyword kw\">else</span>\n\
      38:           <span class=\"ruby-ivar\">@connection_status</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      39:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BdrbConnError</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-node\">&quot;Error while writing #{server_info}&quot;</span>)\n\
      40:         <span class=\"ruby-keyword kw\">end</span>\n\
      41:       <span class=\"ruby-keyword kw\">rescue</span>\n\
      42:         <span class=\"ruby-identifier\">establish_connection</span>\n\
      43:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@connection_status</span>\n\
      44:           <span class=\"ruby-identifier\">flush_in_loop</span>(<span class=\"ruby-identifier\">data</span>)\n\
      45:         <span class=\"ruby-keyword kw\">else</span>\n\
      46:           <span class=\"ruby-ivar\">@connection_status</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      47:           <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BdrbConnError</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-node\">&quot;Error while writing #{server_info}&quot;</span>)\n\
      48:         <span class=\"ruby-keyword kw\">end</span>\n\
      49:       <span class=\"ruby-keyword kw\">end</span>\n\
      50:     <span class=\"ruby-keyword kw\">end</span>"
    params: (data)
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.