Class: LogStash::Codecs::AutoFlush

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/codecs/auto_flush.rb

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (Boolean)


29
30
31
# File 'lib/logstash/codecs/auto_flush.rb', line 29

def pending?
  @task && @task.pending?
end

#startObject



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

#stopObject



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

Returns:

  • (Boolean)


33
34
35
# File 'lib/logstash/codecs/auto_flush.rb', line 33

def stopped?
  @stopped.value
end