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(filter, node_id) ⇒ Object
- #send_verbosity_command(ap) ⇒ Object
- #send_version_command(ap) ⇒ Object
Constructor Details
#initialize ⇒ Sender
Returns a new instance of Sender.
9 10 |
# File 'lib/roma/client/sender.rb', line 9 def initialize end |
Instance Method Details
#send_command(nid, cmd, value = nil, receiver = :oneline_receiver) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/roma/client/sender.rb', line 100 def send_command(nid, cmd, value = nil, receiver = :oneline_receiver) con = ConPool.instance.get_connection(nid) fail 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/) fail ret end ret end |
#send_route_mklhash_command(node_id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/roma/client/sender.rb', line 12 def send_route_mklhash_command(node_id) Timeout.timeout(1) do 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 end rescue => e STDERR.puts "#{node_id} #{e.inspect}" return nil end |
#send_routedump_command(node_id) ⇒ Object
25 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 |
# File 'lib/roma/client/sender.rb', line 25 def send_routedump_command(node_id) Timeout.timeout(1) do 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 end rescue => e STDERR.puts "#{node_id} #{e.inspect}" nil end |
#send_routedump_yaml_command(node_id) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/roma/client/sender.rb', line 55 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) rd end |
#send_stats_command(filter, node_id) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/roma/client/sender.rb', line 69 def send_stats_command(filter, node_id) conn = ConPool.instance.get_connection(node_id) cmd = 'stats' cmd += " #{filter}" if filter conn.write "#{cmd}\r\n" stats_str = '' while ((line = conn.gets) != "END\r\n") stats_str << line end stats = Roma::Client::Stats.new(stats_str) ConPool.instance.return_connection(node_id, conn) stats end |