Class: Elrpc::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/elrpc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, port) ⇒ Service

cmd = [“ruby”, “_call.rb”]



70
71
72
73
# File 'lib/elrpc.rb', line 70

def initialize(cmd, port)
  @cmd = cmd
  @port = port
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



66
67
68
# File 'lib/elrpc.rb', line 66

def client
  @client
end

#cmdObject (readonly)

Returns the value of attribute cmd.



66
67
68
# File 'lib/elrpc.rb', line 66

def cmd
  @cmd
end

#outputObject (readonly)

Returns the value of attribute output.



67
68
69
# File 'lib/elrpc.rb', line 67

def output
  @output
end

#portObject (readonly)

Returns the value of attribute port.



66
67
68
# File 'lib/elrpc.rb', line 66

def port
  @port
end

Instance Method Details

#_start_loggerObject



75
76
77
78
79
80
81
82
83
# File 'lib/elrpc.rb', line 75

def _start_logger
  return Thread.start do
    loop do
      ret = @io.readline
      break if ret.nil?
      @logger.puts(ret) if @logger
    end
  end
end

#alive?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/elrpc.rb', line 110

def alive?
  @client.alive?
end

#call_method(name, *args) ⇒ Object



126
127
128
# File 'lib/elrpc.rb', line 126

def call_method(name, *args)
  @client.call_method(name, *args)
end

#call_method_async(name, *args, &block) ⇒ Object



122
123
124
# File 'lib/elrpc.rb', line 122

def call_method_async(name, *args, &block)
  @client.call_method_async(name, *args, &block)
end

#def_method(name, argdoc = nil, docstring = nil, &block) ⇒ Object



118
119
120
# File 'lib/elrpc.rb', line 118

def def_method(name, argdoc=nil, docstring=nil, &block)
  @client.def_method(name, argdoc, docstring, &block)
end

#query_methodsObject



134
135
136
# File 'lib/elrpc.rb', line 134

def query_methods
  @client.query_methods
end

#query_methods_async(&block) ⇒ Object



130
131
132
# File 'lib/elrpc.rb', line 130

def query_methods_async(&block)
  @client.query_methods(&block)
end

#register_method(method) ⇒ Object



114
115
116
# File 'lib/elrpc.rb', line 114

def register_method(method)
  @client.register_method(method)
end

#startObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/elrpc.rb', line 85

def start
  @io = IO.popen(@cmd)
  if port.nil?
    @port = @io.readline.to_i
  end
  @output = nil
  @thread = _start_logger
  # wait for port
  timeout(4) do
    loop do
      begin
        socket = TCPSocket.open("127.0.0.1", @port)
        socket.close
        #puts("Peer port is OK.")
        break
      rescue => e
        #puts("Peer port is not opened. Try next time...")
        sleep(0.2)
      end
    end
  end
  @client = Elrpc.start_client(@port)
  return self
end

#stopObject



138
139
140
# File 'lib/elrpc.rb', line 138

def stop
  @client.stop
end