Class: Droonga::Supervisor

Inherits:
Object
  • Object
show all
Includes:
Deferrable, Loggable
Defined in:
lib/droonga/supervisor.rb

Defined Under Namespace

Classes: WorkerConfiguration, WorkerRunner

Instance Method Summary collapse

Methods included from Deferrable

#wait_until_ready

Constructor Details

#initialize(loop, n_workers, config) ⇒ Supervisor

Returns a new instance of Supervisor.



25
26
27
28
29
# File 'lib/droonga/supervisor.rb', line 25

def initialize(loop, n_workers, config)
  @loop = loop
  @n_workers = n_workers
  @config = config
end

Instance Method Details

#refresh_node_referenceObject



68
69
70
71
72
# File 'lib/droonga/supervisor.rb', line 68

def refresh_node_reference
  @worker_runners.each do |worker_runner|
    worker_runner.refresh_node_reference
  end
end

#startObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/droonga/supervisor.rb', line 31

def start
  n_ready_workers = 0
  @worker_runners = @n_workers.times.collect do |i|
    worker_runner = WorkerRunner.new(@loop, i, @config)
    worker_runner.on_ready = lambda do
      n_ready_workers += 1
      if n_ready_workers == @n_workers
        on_ready
      end
    end
    worker_runner.start
    # TODO: support auto re-run
    worker_runner
  end
end

#stop_gracefullyObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/droonga/supervisor.rb', line 47

def stop_gracefully
  logger.trace("stop_gracefully: start")
  n_worker_runners = @worker_runners.size
  n_done_worker_runners = 0
  @worker_runners.each do |worker_runner|
    worker_runner.stop_gracefully do
      n_done_worker_runners += 1
      if n_done_worker_runners == n_worker_runners
        yield if block_given?
        logger.trace("stop_gracefully: done")
      end
    end
  end
end

#stop_immediatelyObject



62
63
64
65
66
# File 'lib/droonga/supervisor.rb', line 62

def stop_immediately
  @worker_runners.each do |worker_runner|
    worker_runner.stop_immediately
  end
end