Class: Fluent::Plugin::SystemdInput::PosWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/systemd/pos_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(pos_file, storage) ⇒ PosWriter

Returns a new instance of PosWriter.



8
9
10
11
12
13
14
15
# File 'lib/fluent/plugin/systemd/pos_writer.rb', line 8

def initialize(pos_file, storage)
  @path = pos_file
  @lock = Mutex.new
  @storage = storage
  @cursor = nil
  @written_cursor = nil
  setup
end

Instance Method Details

#get(key) ⇒ Object



17
18
19
# File 'lib/fluent/plugin/systemd/pos_writer.rb', line 17

def get(key)
  @storage ? @storage.get(key) : @cursor
end

#pathObject



26
27
28
# File 'lib/fluent/plugin/systemd/pos_writer.rb', line 26

def path
  @path || @storage.path
end

#put(key, cursor) ⇒ Object



21
22
23
24
# File 'lib/fluent/plugin/systemd/pos_writer.rb', line 21

def put(key, cursor)
  return @storage.put(key, cursor) if @storage
  @lock.synchronize { @cursor = cursor }
end

#shutdownObject



36
37
38
39
40
41
# File 'lib/fluent/plugin/systemd/pos_writer.rb', line 36

def shutdown
  return unless @path
  @running = false
  @thread.join
  write_pos
end

#startObject



30
31
32
33
34
# File 'lib/fluent/plugin/systemd/pos_writer.rb', line 30

def start
  return unless @path
  @running = true
  @thread = Thread.new(&method(:work))
end