Class: NewRelic::Agent::EventLoop::Timer
- Inherits:
-
Object
- Object
- NewRelic::Agent::EventLoop::Timer
- Defined in:
- lib/new_relic/agent/event_loop.rb
Instance Attribute Summary collapse
- #event ⇒ Object readonly
- #interval ⇒ Object readonly
- #last_fired_at ⇒ Object readonly
- #next_fire_time ⇒ Object readonly
Instance Method Summary collapse
- #advance(amount) ⇒ Object
- #calculate_next_fire_time ⇒ Object
- #due?(now = Process.clock_gettime(Process::CLOCK_REALTIME)) ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(interval, event, repeat = false) ⇒ Timer
constructor
A new instance of Timer.
- #last_interval_start ⇒ Object
- #reschedule ⇒ Object
- #set_fired_time ⇒ Object
Constructor Details
#initialize(interval, event, repeat = false) ⇒ Timer
Returns a new instance of Timer.
13 14 15 16 17 18 19 20 |
# File 'lib/new_relic/agent/event_loop.rb', line 13 def initialize(interval, event, repeat = false) @interval = interval @event = event @repeat = repeat @started_at = Process.clock_gettime(Process::CLOCK_REALTIME) @last_fired_at = nil reschedule end |
Instance Attribute Details
#event ⇒ Object (readonly)
11 12 13 |
# File 'lib/new_relic/agent/event_loop.rb', line 11 def event @event end |
#interval ⇒ Object (readonly)
11 12 13 |
# File 'lib/new_relic/agent/event_loop.rb', line 11 def interval @interval end |
#last_fired_at ⇒ Object (readonly)
11 12 13 |
# File 'lib/new_relic/agent/event_loop.rb', line 11 def last_fired_at @last_fired_at end |
#next_fire_time ⇒ Object (readonly)
11 12 13 |
# File 'lib/new_relic/agent/event_loop.rb', line 11 def next_fire_time @next_fire_time end |
Instance Method Details
#advance(amount) ⇒ Object
26 27 28 |
# File 'lib/new_relic/agent/event_loop.rb', line 26 def advance(amount) @next_fire_time -= amount end |
#calculate_next_fire_time ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/new_relic/agent/event_loop.rb', line 34 def calculate_next_fire_time now = Process.clock_gettime(Process::CLOCK_REALTIME) return now if @interval == 0 fire_time = @last_fired_at || now while fire_time <= now fire_time += @interval end fire_time end |
#due?(now = Process.clock_gettime(Process::CLOCK_REALTIME)) ⇒ Boolean
49 50 51 |
# File 'lib/new_relic/agent/event_loop.rb', line 49 def due?(now = Process.clock_gettime(Process::CLOCK_REALTIME)) now >= @next_fire_time end |
#finished? ⇒ Boolean
53 54 55 |
# File 'lib/new_relic/agent/event_loop.rb', line 53 def finished? !@repeat && @last_fired_at end |
#last_interval_start ⇒ Object
30 31 32 |
# File 'lib/new_relic/agent/event_loop.rb', line 30 def last_interval_start @last_fired_at || @started_at end |
#reschedule ⇒ Object
22 23 24 |
# File 'lib/new_relic/agent/event_loop.rb', line 22 def reschedule @next_fire_time = calculate_next_fire_time end |
#set_fired_time ⇒ Object
45 46 47 |
# File 'lib/new_relic/agent/event_loop.rb', line 45 def set_fired_time @last_fired_at = Process.clock_gettime(Process::CLOCK_REALTIME) end |