class Rapel::REPLServer

Attributes

runtimes[R]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

async_listen_for_runtimes(callback_server) click to toggle source
# 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|
      message = JSON.parse(callback_conn.gets, symbolize_names: true)
      runtime = @runtimes[message[:session_id]]
      runtime.start(message[:pid])
      $stdout.puts "Runtime ready at port #{runtime.port.to_s}"
      callback_conn.close
    end
  end
end
async_new_repl_connections() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rapel/replserver.rb, line 42
def start
  loop { async_new_repl_connections }
end