Class: MMTop::PID

Inherits:
Object
  • Object
show all
Defined in:
lib/mmtop/pid.rb

Class Method Summary collapse

Class Method Details

.get(host, real_id) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mmtop/pid.rb', line 13

def self.get(host, real_id)
  key = [host, real_id]

  pid = pid_hash[key]
  if !pid
    pid = pid_array.index(nil) || pid_array.size
  end 

  pid_hash[key] = pid
  pid_array[pid] = @iteration
  pid
end

.pid_arrayObject



5
6
7
# File 'lib/mmtop/pid.rb', line 5

def self.pid_array
  @pid_array ||= []
end

.pid_hashObject



9
10
11
# File 'lib/mmtop/pid.rb', line 9

def self.pid_hash
  @pid_hash ||= {}
end

.resetObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mmtop/pid.rb', line 26

def self.reset
  to_delete = pid_hash.map do |k, v|
    # recycle pid after 2 loops
    if pid_array[v] && pid_array[v] < @iteration - 1
      k
    end
  end.compact

  to_delete.each do |k|
    idx = pid_hash.delete(k)
    pid_array[idx] = nil
  end

  @iteration += 1
end