Class: Rapel::Runtime

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_port, session_id) ⇒ Runtime

Returns a new instance of Runtime.



8
9
10
11
12
13
# File 'lib/rapel/runtime.rb', line 8

def initialize(callback_port, session_id)
  runtime_port = 9220
  @port = runtime_port
  @session_id = session_id
  system(ruby_runtime_string(callback_port))
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/rapel/runtime.rb', line 5

def port
  @port
end

#session_idObject (readonly)

Returns the value of attribute session_id.



5
6
7
# File 'lib/rapel/runtime.rb', line 5

def session_id
  @session_id
end

#socketObject

Returns the value of attribute socket.



6
7
8
# File 'lib/rapel/runtime.rb', line 6

def socket
  @socket
end

Instance Method Details

#inspectObject



37
38
39
# File 'lib/rapel/runtime.rb', line 37

def inspect
  "\#<Runtime @session=\"#@session_id\" @ready=#@ready>"
end

#ruby_runtime_string(callback_port) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rapel/runtime.rb', line 15

def ruby_runtime_string(callback_port)
  ["ruby #{File.dirname(__FILE__)}/../../bin/runtime.rb",
  "--port=#{port}", 
  "--callback-port=#{callback_port}", 
  "--uuid=#{session_id}",
  "&"].join(" ")
end

#shutdownObject



23
24
25
26
27
28
29
# File 'lib/rapel/runtime.rb', line 23

def shutdown
  puts "killing at port #{port}"
  socket.puts("shutdown"+port.to_s)
rescue
  puts "killing pid #{@pid}"
  `kill -9 #{@pid}`
end

#start(pid) ⇒ Object



31
32
33
34
35
# File 'lib/rapel/runtime.rb', line 31

def start(pid)
  @pid = pid
  @ready = true
  @socket = TCPSocket.new('localhost', port)
end