Class: LogStash::Outputs::File::Interval
- Inherits:
-
Object
- Object
- LogStash::Outputs::File::Interval
- Defined in:
- lib/logstash/outputs/file.rb
Overview
Bare-bones utility for running a block of code at an interval.
Class Method Summary collapse
-
.start(interval, procsy) ⇒ Interval
Initializes a new Interval with the given arguments and starts it before returning it.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(interval, procsy) ⇒ Interval
constructor
A new instance of Interval.
-
#start ⇒ void
Starts the interval, or returns if it has already been started.
-
#stop ⇒ Object
Stop the interval.
Constructor Details
#initialize(interval, procsy) ⇒ Interval
Returns a new instance of Interval.
304 305 306 307 308 309 310 311 |
# File 'lib/logstash/outputs/file.rb', line 304 def initialize(interval, procsy) @interval = interval @procsy = procsy require 'thread' # Mutex, ConditionVariable, etc. @mutex = Mutex.new @sleeper = ConditionVariable.new end |
Class Method Details
.start(interval, procsy) ⇒ Interval
Initializes a new Interval with the given arguments and starts it before returning it.
297 298 299 |
# File 'lib/logstash/outputs/file.rb', line 297 def self.start(interval, procsy) self.new(interval, procsy).tap(&:start) end |
Instance Method Details
#alive? ⇒ Boolean
338 339 340 |
# File 'lib/logstash/outputs/file.rb', line 338 def alive? @thread && @thread.alive? end |
#start ⇒ void
This method returns an undefined value.
Starts the interval, or returns if it has already been started.
317 318 319 320 321 322 323 |
# File 'lib/logstash/outputs/file.rb', line 317 def start @mutex.synchronize do return if @thread && @thread.alive? @thread = Thread.new { run } end end |
#stop ⇒ Object
Stop the interval. Does not interrupt if execution is in-progress.
328 329 330 331 332 333 334 |
# File 'lib/logstash/outputs/file.rb', line 328 def stop @mutex.synchronize do @stopped = true end @thread && @thread.join end |