Methods
Included Modules
Public Class methods
init()
    # File lib/backgroundrb.rb, line 13
13:   def self.init
14:     # @@config = YAML.load(File.open("#{BACKGROUNDRB_ROOT}/config/backgroundrb.yml"))
15:     @@config = YAML.load(ERB.new(IO.read("#{BACKGROUNDRB_ROOT}/config/backgroundrb.yml")).result)
16:     @@server_ip = @@config[:backgroundrb][:ip]
17:     @@server_port = @@config[:backgroundrb][:port]
18:     new
19:   end
Public Instance methods
ask_status(p_data)
     # File lib/backgroundrb.rb, line 103
103:   def ask_status(p_data)
104:     p_data[:type] = :get_status
105:     establish_connection()
106: 
107:     raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status
108:     dump_object(p_data,@connection)
109:     begin
110:       ret_val = select([@connection],nil,nil,3)
111:       unless ret_val
112:         # @connection.close
113:         return nil
114:       end
115:       raw_response = read_object()
116:       master_response = Marshal.load(raw_response)
117:       # @connection.close
118:       return master_response
119:     rescue
120:       puts $!
121:       puts $!.backtrace
122:       # @connection.close
123:       return nil
124:     end
125:   end
ask_work(p_data)
    # File lib/backgroundrb.rb, line 36
36:   def ask_work p_data
37:     p_data[:type] = :do_work
38:     establish_connection()
39:     raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status
40:     dump_object(p_data,@connection)
41:     # @connection.close
42:   end
delete_worker(p_data)
    # File lib/backgroundrb.rb, line 52
52:   def delete_worker p_data
53:     p_data[:type] = :delete_worker
54:     establish_connection
55:     raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status
56:     dump_object(p_data,@connection)
57:     # @connection.close
58:   end
establish_connection()
    # File lib/backgroundrb.rb, line 21
21:   def establish_connection
22:     @tokenizer = BinParser.new
23:     begin
24:       timeout(3) do
25:         @connection = TCPSocket.open(@@server_ip, @@server_port)
26:         @connection.setsockopt(Socket::IPPROTO_TCP,Socket::TCP_NODELAY,1)
27:       end
28:       @connection_status = true
29:     rescue Timeout::Error
30:       @connection_status = false
31:     rescue Exception => e
32:       @connection_status = false
33:     end
34:   end
new_worker(p_data)
    # File lib/backgroundrb.rb, line 44
44:   def new_worker p_data
45:     p_data[:type] = :start_worker
46:     establish_connection
47:     raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status
48:     dump_object(p_data,@connection)
49:     # @connection.close
50:   end
query_all_workers()
     # File lib/backgroundrb.rb, line 79
 79:   def query_all_workers
 80:     p_data = { }
 81:     p_data[:type] = :all_worker_status
 82:     establish_connection
 83:     raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status
 84:     dump_object(p_data,@connection)
 85:     begin
 86:       ret_val = select([@connection],nil,nil,3)
 87:       unless ret_val
 88:         # @connection.close
 89:         return nil
 90:       end
 91:       raw_response = read_object()
 92:       master_response = Marshal.load(raw_response)
 93:       # @connection.close
 94:       return master_response
 95:     rescue
 96:       puts $!
 97:       puts $!.backtrace
 98:       # @connection.close
 99:       return nil
100:     end
101:   end
read_object()
    # File lib/backgroundrb.rb, line 68
68:   def read_object
69:     sock_data = ""
70:     begin
71:       while(sock_data << @connection.read_nonblock(1023)); end
72:     rescue Errno::EAGAIN
73:       @tokenizer.extract(sock_data) { |b_data| return b_data }
74:     rescue
75:       raise BackgrounDRb::BdrbConnError.new("Not able to connect")
76:     end
77:   end
send_data(p_data)
    # File lib/backgroundrb.rb, line 60
60:   def send_data p_data
61:     begin
62:       @connection.write_nonblock(p_data)
63:     rescue Errno::EAGAIN
64:       return
65:     end
66:   end
send_request(p_data)
     # File lib/backgroundrb.rb, line 127
127:   def send_request(p_data)
128:     p_data[:type] = :get_result
129:     establish_connection()
130: 
131:     raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status
132:     dump_object(p_data,@connection)
133:     begin
134:       ret_val = select([@connection],nil,nil,nil)
135:       unless ret_val
136:         # @connection.close
137:         return nil
138:       end
139:       raw_response = read_object()
140:       master_response = Marshal.load(raw_response)
141:       # @connection.close
142:       return master_response[:data]
143:     rescue
144:       # @connection.close
145:       return nil
146:     end
147:   end