Class: RedisRing::ProcessManager

Inherits:
Object
  • Object
show all
Includes:
BackgroundThread
Defined in:
lib/redis_ring/process_manager.rb

Instance Method Summary collapse

Methods included from BackgroundThread

#before_run, #continue_running?, #halt, #run

Constructor Details

#initializeProcessManager

Returns a new instance of ProcessManager.



9
10
11
12
13
# File 'lib/redis_ring/process_manager.rb', line 9

def initialize
  @shards = {}
  @shards_to_stop = []
  @mutex = Mutex.new
end

Instance Method Details

#after_haltObject



20
21
22
23
24
25
26
27
# File 'lib/redis_ring/process_manager.rb', line 20

def after_halt
  shards.each do |shard_no, shard|
    if shard.alive?
      puts "Stopping shard #{shard_no}"
      shard.stop
    end
  end
end

#do_workObject



15
16
17
18
# File 'lib/redis_ring/process_manager.rb', line 15

def do_work
  monitor_processes
  sleep(0.5)
end

#start_shard(shard) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/redis_ring/process_manager.rb', line 29

def start_shard(shard)
  @mutex.synchronize do
    if shards.key?(shard.shard_number)
      raise ShardAlreadyStarted.new("Shard: #{shard.shard_number} already started!")
    end

    shards[shard.shard_number] = shard
  end
end

#stop_shard(shard) ⇒ Object



39
40
41
42
43
44
# File 'lib/redis_ring/process_manager.rb', line 39

def stop_shard(shard)
  @mutex.synchronize do
    shards.delete(shard.shard_number)
    shards_to_stop << shard
  end
end