Class: KingKong::Pinger
- Inherits:
-
Object
- Object
- KingKong::Pinger
- Includes:
- EventMachine::Deferrable, Logging
- Defined in:
- lib/kingkong/pinger.rb
Overview
Executes pings within a specificed duration.
Instance Attribute Summary collapse
-
#wait ⇒ Object
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
-
#initialize(wait = 5, &block) ⇒ Pinger
constructor
A new instance of Pinger.
-
#on_ping(&block) ⇒ Object
Fire this if when a ping completes.
-
#start ⇒ Object
Starts the pinger.
-
#stop ⇒ Object
Stop the pinger from executing.
Methods included from Logging
Constructor Details
#initialize(wait = 5, &block) ⇒ Pinger
Returns a new instance of Pinger.
14 15 16 17 18 |
# File 'lib/kingkong/pinger.rb', line 14 def initialize(wait=5,&block) @wait = wait @block = block if block_given? self end |
Instance Attribute Details
#wait ⇒ Object (readonly)
Returns the value of attribute wait.
12 13 14 |
# File 'lib/kingkong/pinger.rb', line 12 def wait @wait end |
Instance Method Details
#on_ping(&block) ⇒ Object
Fire this if when a ping completes
34 35 36 |
# File 'lib/kingkong/pinger.rb', line 34 def on_ping(&block) @on_ping = block end |
#start ⇒ Object
Starts the pinger
21 22 23 24 25 |
# File 'lib/kingkong/pinger.rb', line 21 def start logger.debug "Starting pinger #{self}" @timer = EventMachine::PeriodicTimer.new(wait){ ping } ping # Start a ping right away, the timer above will fire later. end |
#stop ⇒ Object
Stop the pinger from executing
28 29 30 31 |
# File 'lib/kingkong/pinger.rb', line 28 def stop logger.debug "Stopping pinger #{self}" @timer.cancel if @timer end |