Class: Roma::Client::Sender
- Inherits:
-
Object
- Object
- Roma::Client::Sender
- Defined in:
- lib/roma/client/sender.rb
Instance Method Summary collapse
-
#initialize ⇒ Sender
constructor
A new instance of Sender.
- #send_command(nid, cmd, value = nil, receiver = :oneline_receiver) ⇒ Object
- #send_route_mklhash_command(node_id) ⇒ Object
- #send_routedump_command(node_id) ⇒ Object
- #send_routedump_yaml_command(node_id) ⇒ Object
- #send_stats_command ⇒ Object
- #send_verbosity_command(ap) ⇒ Object
- #send_version_command(ap) ⇒ Object
Constructor Details
#initialize ⇒ Sender
Returns a new instance of Sender.
10 11 |
# File 'lib/roma/client/sender.rb', line 10 def initialize end |
Instance Method Details
#send_command(nid, cmd, value = nil, receiver = :oneline_receiver) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/roma/client/sender.rb', line 89 def send_command(nid, cmd, value = nil, receiver = :oneline_receiver) con = ConPool.instance.get_connection(nid) raise unless con if value con.write "#{cmd}\r\n#{value}\r\n" else con.write "#{cmd}\r\n" end ret = send(receiver, con) ConPool.instance.return_connection(nid, con) if ret && ret.instance_of?(String) && (ret =~ /^SERVER_ERROR/ || ret =~ /^CLIENT_ERROR/) raise ret end ret end |
#send_route_mklhash_command(node_id) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/roma/client/sender.rb', line 13 def send_route_mklhash_command(node_id) timeout(1){ conn = ConPool.instance.get_connection(node_id) conn.write "mklhash 0\r\n" ret = conn.gets ConPool.instance.return_connection(node_id, conn) return ret.chomp if ret } rescue =>e STDERR.puts "#{node_id} #{e.inspect}" return nil end |
#send_routedump_command(node_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/roma/client/sender.rb', line 26 def send_routedump_command(node_id) timeout(1){ buf = RUBY_VERSION.split('.') if buf[0].to_i == 1 && buf[1].to_i == 8 return send_routedump_yaml_command(node_id) end conn = ConPool.instance.get_connection(node_id) conn.write "routingdump\r\n" routes_length = conn.gets.to_i if (routes_length <= 0) conn.close return :error if routes_length < 0 return nil end routes = '' while (routes.length != routes_length) routes = routes + conn.read(routes_length - routes.length) end conn.read(2) # "\r\n" conn.gets rd = Marshal.load(routes) ConPool.instance.return_connection(node_id, conn) return rd } rescue =>e STDERR.puts "#{node_id} #{e.inspect}" nil end |
#send_routedump_yaml_command(node_id) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/roma/client/sender.rb', line 56 def send_routedump_yaml_command(node_id) conn = ConPool.instance.get_connection(node_id) conn.write "routingdump yaml\r\n" yaml = '' while( (line = conn.gets) != "END\r\n" ) yaml << line end rd = YAML.load(yaml) ConPool.instance.return_connection(node_id, conn) return rd end |
#send_stats_command ⇒ Object
70 71 72 |
# File 'lib/roma/client/sender.rb', line 70 def send_stats_command # TODO end |