Class: LogStash::Outputs::Application_insights::Timer
- Inherits:
-
Object
- Object
- LogStash::Outputs::Application_insights::Timer
- Defined in:
- lib/logstash/outputs/application_insights/timer.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #set(expiration, object, &callback) ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
63 64 65 66 67 68 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 63 def initialize @@timers_mutex.synchronize { @@timers << self } @state = :off end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
29 30 31 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 29 def callback @callback end |
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
27 28 29 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 27 def expiration @expiration end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
28 29 30 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 28 def object @object end |
#state ⇒ Object
Returns the value of attribute state.
26 27 28 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 26 def state @state end |
Class Method Details
.config(configuration) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 31 def self.config ( configuration ) @@configuration = configuration @@logger = configuration[:logger] @@timers = [] @@timers_modified = false @@timers_mutex = Mutex.new Thread.new do loop do sleep( 1 ) curr_time = Time.now.utc timers_triggerd = [ ] @@timers_mutex.synchronize { @@timers.each do |timer| if :on == timer.state && curr_time >= timer.expiration timer.state = :trigger timers_triggerd << [ timer.object, timer.callback ] end end } timers_triggerd.each do |pair| (object, callback) = pair callback.call( object ) end end end end |
Instance Method Details
#cancel ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 80 def cancel @@timers_mutex.synchronize { state = @state @state = :off @@timers_modified = true if :on == state state != :trigger } end |
#set(expiration, object, &callback) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/logstash/outputs/application_insights/timer.rb', line 70 def set ( expiration, object, &callback ) @@timers_mutex.synchronize { @@timers_modified= true @state = :on @object = object @expiration = expiration @callback = callback } end |