Class: DeepConnect::Cron

Inherits:
Object show all
Defined in:
lib/deep-connect/cron.rb

Constant Summary collapse

TAB =
[
  [10, proc{|org, cron, t| cron.mon_10sec}],
  [60, proc{|org, cron, t| cron.mon_min}],
  [3060, proc{|org, cron, t| cron.mon_hour}],
  [Conf.KEEP_ALIVE_INTERVAL, proc{|org, cron, t| org.keep_alive}],
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organizer) ⇒ Cron

Returns a new instance of Cron.



21
22
23
24
25
26
27
28
29
30
# File 'lib/deep-connect/cron.rb', line 21

def initialize(organizer)
  @organizer = organizer

  @timer = 0
  @last_exec_times = {}

  @mon_mutex = Mutex.new

  @prev_message10s = nil
end

Instance Attribute Details

#timerObject (readonly) Also known as: tick

Returns the value of attribute timer.



32
33
34
# File 'lib/deep-connect/cron.rb', line 32

def timer
  @timer
end

Instance Method Details

#mon_10secObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/deep-connect/cron.rb', line 57

def mon_10sec
  return if @organizer.deep_spaces.size == 0

  if Conf.DISPLAY_MONITOR_MESSAGE
	str = ""
	str.concat "Connect DeepSpaces: BEGIN\n"
	for peer_id, ds in @organizer.deep_spaces.dup
	  str.concat "#{peer_id.inspect} => \n"
	  str.concat "\t#{ds}\n"
	end
	str.concat "Connect DeepSpaces: END\n"

	if @prev_message10s != str
	  @prev_message10s = str
	  puts "MON 10SEC: #{@timer}\n", str
	end
  end
end

#mon_hourObject



82
83
84
85
86
# File 'lib/deep-connect/cron.rb', line 82

def mon_hour
  if Conf.DISPLAY_MONITOR_MESSAGE
	puts "MON HOUR: #{@timer}"
  end
end

#mon_minObject



76
77
78
79
80
# File 'lib/deep-connect/cron.rb', line 76

def mon_min
  if Conf.DISPLAY_MONITOR_MESSAGE
	puts "MON MIN: #{@timer}"
  end
end

#startObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/deep-connect/cron.rb', line 35

def start
  Thread.start do 
	loop do
	  sleep Conf.MON_INTERVAL
	  @timer += Conf.MON_INTERVAL
	  
	  Thread.start do
 @mon_mutex.synchronize do
   for tab in TAB
		last_time = @last_exec_times[tab]
		last_time = 0 unless last_time
		if @timer >= last_time + tab[0] 
@last_exec_times[tab] = @timer
tab[1].call @organizer, self, @timer
		end
   end
 end
	  end
	end
  end
end