Class: Elrpc::Service
- Inherits:
-
Object
- Object
- Elrpc::Service
- Defined in:
- lib/elrpc.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #_start_logger ⇒ Object
- #call_method(name, *args) ⇒ Object
- #call_method_async(name, *args, &block) ⇒ Object
- #def_method(name, argdoc = nil, docstring = nil, &block) ⇒ Object
-
#initialize(cmd) ⇒ Service
constructor
cmd = [“ruby”, “_call.rb”].
- #query_methods ⇒ Object
- #query_methods_async(&block) ⇒ Object
- #register_method(method) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(cmd) ⇒ Service
cmd = [“ruby”, “_call.rb”]
70 71 72 |
# File 'lib/elrpc.rb', line 70 def initialize(cmd) @cmd = cmd end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
66 67 68 |
# File 'lib/elrpc.rb', line 66 def client @client end |
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
66 67 68 |
# File 'lib/elrpc.rb', line 66 def cmd @cmd end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
67 68 69 |
# File 'lib/elrpc.rb', line 67 def output @output end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
66 67 68 |
# File 'lib/elrpc.rb', line 66 def port @port end |
Instance Method Details
#_start_logger ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/elrpc.rb', line 74 def _start_logger return Thread.start do stdout = @io3[1] stderr = @io3[2] loop do IO.select([stdout, stderr]).flatten.compact.each do |io| io.each do |line| next if line.nil? || line.empty? @logger.puts(line) if @logger end end break if stdout.eof? && stderr.eof? end end end |
#call_method(name, *args) ⇒ Object
112 113 114 |
# File 'lib/elrpc.rb', line 112 def call_method(name, *args) @client.call_method(name, *args) end |
#call_method_async(name, *args, &block) ⇒ Object
108 109 110 |
# File 'lib/elrpc.rb', line 108 def call_method_async(name, *args, &block) @client.call_method_async(name, *args, &block) end |
#def_method(name, argdoc = nil, docstring = nil, &block) ⇒ Object
104 105 106 |
# File 'lib/elrpc.rb', line 104 def def_method(name, argdoc=nil, docstring=nil, &block) @client.def_method(name, argdoc, docstring, &block) end |
#query_methods ⇒ Object
120 121 122 |
# File 'lib/elrpc.rb', line 120 def query_methods @client.query_methods end |
#query_methods_async(&block) ⇒ Object
116 117 118 |
# File 'lib/elrpc.rb', line 116 def query_methods_async(&block) @client.query_methods(&block) end |
#register_method(method) ⇒ Object
100 101 102 |
# File 'lib/elrpc.rb', line 100 def register_method(method) @client.register_method(method) end |
#start ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/elrpc.rb', line 90 def start @io3 = Open3.popen3(@cmd) # stdin, stdout, stderr, wait_thr @port = @io3[2].readline.to_i @io3[0].close @output = nil @thread = _start_logger @client = Elrpc.start_client(@port) return self end |
#stop ⇒ Object
124 125 126 127 128 |
# File 'lib/elrpc.rb', line 124 def stop @client.stop @io3[1].close @io3[2].close end |