module Roma::Command::Definition
Public Class Methods
included(base)
click to toggle source
# File lib/roma/command/command_definition.rb 8 def self.included(base) 9 # include ClassMethods module into an eigen-class of a +base+ 10 base.extend ClassMethods 11 end
Public Instance Methods
forward_and_multi_line_receive(nid, rs, data=nil)
click to toggle source
# File lib/roma/command/command_definition.rb 383 def forward_and_multi_line_receive(nid, rs, data=nil) 384 if rs.last == "forward" 385 return send_data("SERVER_ERROR Routing table is inconsistent.\r\n") 386 end 387 388 @log.warn("forward #{rs} to #{nid}"); 389 390 buf = rs.join(' ') + " forward\r\n" 391 buf << data + "\r\n" if data 392 393 con = get_connection(nid) 394 con.send(buf) 395 396 buf = con.gets 397 if buf == nil 398 @rttable.proc_failed(nid) 399 @log.error("forward get failed:nid=#{nid} rs=#{rs} #{$@}") 400 return send_data("SERVER_ERROR Message forward failed.\r\n") 401 elsif buf.start_with?("ERROR") 402 @rttable.proc_succeed(nid) 403 con.close_connection 404 @log.error("forward get failed:nid=#{nid} rs=#{rs} #{$@}") 405 return send_data("SERVER_ERROR Message forward failed.\r\n") 406 elsif buf.start_with?("VALUE") == false 407 return_connection(nid, con) 408 @rttable.proc_succeed(nid) 409 return send_data(buf) 410 end 411 412 res = '' 413 begin 414 res << buf 415 s = buf.split(/ /) 416 if s[0] != 'VALUE' 417 return_connection(nid, con) 418 @rttable.proc_succeed(nid) 419 return send_data(buf) 420 end 421 res << con.read_bytes(s[3].to_i + 2) 422 end while (buf = con.gets)!="END\r\n" 423 424 res << "END\r\n" 425 426 return_connection(nid, con) 427 @rttable.proc_succeed(nid) 428 429 send_data(res) 430 rescue => e 431 @rttable.proc_failed(nid) if e.message != "no connection" 432 @log.error("forward get failed:nid=#{nid} rs=#{rs} #{e} #{$@}") 433 send_data("SERVER_ERROR Message forward failed.\r\n") 434 end
forward_and_one_line_receive(nid, rs, data = nil)
click to toggle source
# File lib/roma/command/command_definition.rb 366 def forward_and_one_line_receive(nid, rs, data = nil) 367 if rs.last == "forward" 368 return send_data("SERVER_ERROR Routing table is inconsistent.\r\n") 369 end 370 371 @log.warn("forward #{rs} to #{nid}"); 372 373 buf = rs.join(' ') + " forward\r\n" 374 buf << data + "\r\n" if data 375 res = send_cmd(nid, buf) 376 if res == nil || res.start_with?("ERROR") 377 return send_data("SERVER_ERROR Message forward failed.\r\n") 378 end 379 send_data("#{res}\r\n") 380 end