Class: Rapel::REPLServer
- Inherits:
-
Object
- Object
- Rapel::REPLServer
- Defined in:
- lib/rapel/replserver.rb
Defined Under Namespace
Classes: Input
Instance Attribute Summary collapse
-
#runtimes ⇒ Object
readonly
Returns the value of attribute runtimes.
Instance Method Summary collapse
- #async_listen_for_runtimes(callback_server) ⇒ Object
- #async_new_repl_connections ⇒ Object
-
#initialize ⇒ REPLServer
constructor
A new instance of REPLServer.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ REPLServer
Returns a new instance of REPLServer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rapel/replserver.rb', line 7 def initialize @runtimes = {} server_port = 8091 $stdout.puts "Starting Rapel server on port #{server_port}" @server = TCPServer.new(server_port) callback_server_port = 8092 callback_server = TCPServer.new(callback_server_port) session_id = SecureRandom.uuid runtime = Runtime.new(callback_server_port, session_id) @runtimes[session_id] = runtime async_listen_for_runtimes(callback_server) end |
Instance Attribute Details
#runtimes ⇒ Object (readonly)
Returns the value of attribute runtimes.
5 6 7 |
# File 'lib/rapel/replserver.rb', line 5 def runtimes @runtimes end |
Instance Method Details
#async_listen_for_runtimes(callback_server) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rapel/replserver.rb', line 30 def async_listen_for_runtimes(callback_server) Thread.new do Thread.new(callback_server.accept) do |callback_conn| = JSON.parse(callback_conn.gets, symbolize_names: true) runtime = @runtimes[[:session_id]] runtime.start([:pid]) $stdout.puts "Runtime ready at port #{runtime.port.to_s}" callback_conn.close end end end |
#async_new_repl_connections ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rapel/replserver.rb', line 23 def async_new_repl_connections Thread.new(@server.accept) do |conn| $stdout.puts("Client connected on port: #{conn.addr[1]}") conn.repl end end |
#shutdown ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rapel/replserver.rb', line 46 def shutdown @runtimes.each do |id, runtime| $stdout.puts runtime.inspect $stdout.puts ("shutdown"+runtime.port.to_s).inspect runtime.shutdown end end |
#start ⇒ Object
42 43 44 |
# File 'lib/rapel/replserver.rb', line 42 def start loop { async_new_repl_connections } end |