Class SystemTimer::ConcurrentTimerPool
In: lib/system_timer/concurrent_timer_pool.rb
Parent: Object

Methods

Public Instance methods

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 17
17:     def add_timer(interval_in_seconds, exception_class=nil)
18:       new_timer = register_timer(Time.now.to_f + interval_in_seconds, Thread.current, exception_class)
19:       log_registered_timers if SystemTimer.debug_enabled?
20:       new_timer
21:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 23
23:     def cancel(registered_timer)
24:       registered_timers.delete registered_timer
25:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 27
27:     def first_timer?
28:       registered_timers.size == 1
29:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 45
45:     def next_expired_timer(now_in_seconds_since_epoch)
46:       candidate_timer = next_timer
47:       if SystemTimer.debug_enabled?
48:         puts "Candidate timer at #{now_in_seconds_since_epoch} : " +
49:              candidate_timer.inspect
50:       end
51:       return nil if candidate_timer.nil? || 
52:                     candidate_timer.trigger_time > now_in_seconds_since_epoch
53:       candidate_timer
54:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 31
31:     def next_timer
32:       registered_timers.sort {|x,y| x.trigger_time <=> y.trigger_time}.first
33:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 40
40:     def next_trigger_interval_in_seconds
41:       timer = next_timer
42:       [0, (timer.trigger_time - Time.now.to_f)].max unless timer.nil?
43:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 35
35:     def next_trigger_time
36:       timer = next_timer
37:       timer.trigger_time unless timer.nil?
38:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 11
11:     def register_timer(trigger_time, thread, exception_class=nil)
12:       new_timer = ThreadTimer.new(trigger_time, thread, exception_class)
13:       registered_timers << new_timer
14:       new_timer
15:     end

[Source]

   # File lib/system_timer/concurrent_timer_pool.rb, line 7
7:     def registered_timers
8:       @timers ||= []
9:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 66
66:     def trigger_next_expired_timer
67:       puts "Trigger next expired timer" if SystemTimer.debug_enabled?
68:       trigger_next_expired_timer_at Time.now.to_f
69:     end

[Source]

    # File lib/system_timer/concurrent_timer_pool.rb, line 56
56:     def trigger_next_expired_timer_at(now_in_seconds_since_epoch)
57:       timer = next_expired_timer(now_in_seconds_since_epoch)
58:       puts "Next expired timer : #{timer.inspect}" if SystemTimer.debug_enabled?
59:       return if timer.nil?
60: 
61:       cancel timer
62:       log_timeout_received(timer) if SystemTimer.debug_enabled?
63:       timer.thread.raise timer.exception_class.new("time's up!")
64:     end

[Validate]