Class: Mooro::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(max_connections, host = "127.0.0.1", port = 10001, stdlog = $stderr) ⇒ Server

Returns a new instance of Server.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mooro/server.rb', line 9

def initialize(max_connections,
  host = "127.0.0.1",
  port = 10001,
  stdlog = $stderr)

  @host = host
  @port = port
  @max_connections = max_connections
  @stdlog = stdlog
  @shutdown = true
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/mooro/server.rb', line 43

def running?
  !@shutdown
end

#startObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/mooro/server.rb', line 21

def start
  raise "server is already running" unless @shutdown

  @logger = make_logger
  @workers = @max_connections.times.map do |i|
    make_worker(Ractor.current, @logger, ractor_name: "worker-#{i}")
  end
  @supervisor = make_supervisor(@logger, @workers)
  @shutdown = false
end

#stopObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/mooro/server.rb', line 32

def stop
  raise "server is not yet running" if @shutdown

  @supervisor.raise(Mooro::TerminateServer.new) if @supervisor.alive?
  @supervisor.join

  raise "orphaned ractor" unless Ractor.count == 1

  @shutdown = true
end