Class: LogStash::Codecs::AutoFlush
- Inherits:
-
Object
- Object
- LogStash::Codecs::AutoFlush
- Defined in:
- lib/logstash/codecs/auto_flush.rb
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(mc, interval) ⇒ AutoFlush
constructor
A new instance of AutoFlush.
- #pending? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(mc, interval) ⇒ AutoFlush
Returns a new instance of AutoFlush.
5 6 7 8 |
# File 'lib/logstash/codecs/auto_flush.rb', line 5 def initialize(mc, interval) @mc, @interval = mc, interval @stopped = Concurrent::AtomicBoolean.new # false by default end |
Instance Method Details
#finished? ⇒ Boolean
24 25 26 27 |
# File 'lib/logstash/codecs/auto_flush.rb', line 24 def finished? return true if @task.nil? @task.fulfilled? end |
#pending? ⇒ Boolean
29 30 31 |
# File 'lib/logstash/codecs/auto_flush.rb', line 29 def pending? @task && @task.pending? end |
#start ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/logstash/codecs/auto_flush.rb', line 10 def start # can't start if pipeline is stopping return self if stopped? if pending? @task.reset elsif finished? @task = Concurrent::ScheduledTask.execute(@interval) do @mc.auto_flush() end # else the task is executing end self end |
#stop ⇒ Object
37 38 39 40 |
# File 'lib/logstash/codecs/auto_flush.rb', line 37 def stop @stopped.make_true @task.cancel if pending? end |
#stopped? ⇒ Boolean
33 34 35 |
# File 'lib/logstash/codecs/auto_flush.rb', line 33 def stopped? @stopped.value end |