Class: Nonnative::Pool

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

Overview

Orchestrates lifecycle for configured processes, servers and services.

A pool is created when start is called and is accessible via pool.

Lifecycle order is important:

  • On start: services first, then servers/processes (in parallel port-check threads)

  • On stop: processes/servers first, then services

Readiness and shutdown are determined via TCP port checks (Nonnative::Port#open? / Nonnative::Port#closed?).

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Pool

Returns a new instance of Pool.

Parameters:



19
20
21
# File 'lib/nonnative/pool.rb', line 19

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#process_by_name(name) ⇒ Nonnative::Process

Finds a running process runner by configured name.

Parameters:

  • name (String)

Returns:

Raises:



54
55
56
# File 'lib/nonnative/pool.rb', line 54

def process_by_name(name)
  processes[runner_index(configuration.processes, name)].first
end

#resetvoid

This method returns an undefined value.

Resets proxies for all runners in this pool.

This is used by the Cucumber ‘@reset` hook and is safe to call any time after the pool is created.



81
82
83
84
85
# File 'lib/nonnative/pool.rb', line 81

def reset
  services.each { |s| s.proxy.reset }
  servers.each { |s| s.first.proxy.reset }
  processes.each { |p| p.first.proxy.reset }
end

#server_by_name(name) ⇒ Nonnative::Server

Finds a running server runner by configured name.

Parameters:

  • name (String)

Returns:

Raises:



63
64
65
# File 'lib/nonnative/pool.rb', line 63

def server_by_name(name)
  servers[runner_index(configuration.servers, name)].first
end

#service_by_name(name) ⇒ Nonnative::Service

Finds a running service runner by configured name.

Parameters:

  • name (String)

Returns:

Raises:



72
73
74
# File 'lib/nonnative/pool.rb', line 72

def service_by_name(name)
  services[runner_index(configuration.services, name)]
end

#start {|name, values, result| ... } ⇒ void

This method returns an undefined value.

Starts all configured runners and yields results for each process/server.

Services are started first (proxy-only), then servers and processes are started and checked for readiness.

Yield Parameters:

  • name (String, nil)

    runner name

  • values (Object)

    runner-specific return value from start (e.g. ‘[pid, running]` for processes)

  • result (Boolean)

    result of the port readiness check (true if ready in time)



31
32
33
34
# File 'lib/nonnative/pool.rb', line 31

def start(&)
  services.each(&:start)
  [servers, processes].each { |t| process(t, :start, :open?, &) }
end

#stop {|name, id, result| ... } ⇒ void

This method returns an undefined value.

Stops all configured runners and yields results for each process/server.

Processes and servers are stopped first and checked for shutdown, then services are stopped (proxy-only).

Yield Parameters:

  • name (String, nil)

    runner name

  • id (Object)

    runner-specific identifier returned by stop (e.g. pid or object_id)

  • result (Boolean)

    result of the port shutdown check (true if closed in time)



44
45
46
47
# File 'lib/nonnative/pool.rb', line 44

def stop(&)
  [processes, servers].each { |t| process(t, :stop, :closed?, &) }
  services.each(&:stop)
end