Class: Nonnative::Server

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

Overview

Runtime runner that manages an in-process Ruby server.

A server runner:

  • starts the configured proxy (if any),

  • starts a Ruby thread that runs #perform_start,

  • waits briefly (via the runner wait), and

  • participates in readiness/shutdown via TCP port checks orchestrated by Pool.

Concrete server implementations are expected to subclass Server and implement:

  • #perform_start (to bind/listen and begin serving), and

  • #perform_stop (to gracefully shut down).

The underlying configuration is a ConfigurationServer.

Direct Known Subclasses

GRPCServer, HTTPServer

Instance Attribute Summary

Attributes inherited from Runner

#proxy

Instance Method Summary collapse

Methods inherited from Runner

#name

Constructor Details

#initialize(service) ⇒ Server

Returns a new instance of Server.

Parameters:



22
23
24
25
26
# File 'lib/nonnative/server.rb', line 22

def initialize(service)
  super

  @timeout = Nonnative::Timeout.new(service.timeout)
end

Instance Method Details

#startArray<(Integer, TrueClass)>

Starts the proxy (if any) and starts the server thread if not already started.

Returns:

  • (Array<(Integer, TrueClass)>)

    a tuple of:

    • a stable identifier for this server instance (object_id)

    • true (thread creation itself is considered started; readiness is checked separately)



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nonnative/server.rb', line 34

def start
  unless thread
    proxy.start
    @thread = Thread.new { perform_start }

    wait_start

    Nonnative.logger.info "started server '#{service.name}'"
  end

  [object_id, true]
end

#stopInteger

Stops the server if it is running.

Calls #perform_stop, terminates the server thread, stops the proxy (if any), and waits briefly.

Returns:

  • (Integer)

    the server identifier (object_id)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nonnative/server.rb', line 52

def stop
  if thread
    perform_stop
    thread.terminate
    proxy.stop

    @thread = nil
    wait_stop

    Nonnative.logger.info "stopped server '#{service.name}'"
  end

  object_id
end