Class: LogStash::Outputs::Gcs::SynchronizedLogFile

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/gcs/temp_log_file.rb

Overview

SynchronizedLogFile wraps another log file and uses reentrant locks around its methods to prevent concurrent modification.

Instance Method Summary collapse

Constructor Details

#initialize(child) ⇒ SynchronizedLogFile

Returns a new instance of SynchronizedLogFile.



89
90
91
92
# File 'lib/logstash/outputs/gcs/temp_log_file.rb', line 89

def initialize(child)
  @child = child
  @lock = Concurrent::ReentrantReadWriteLock.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



102
103
104
105
106
107
# File 'lib/logstash/outputs/gcs/temp_log_file.rb', line 102

def method_missing(method_name, *args, &block)
  # unless otherwise specified, get a write lock
  @lock.with_write_lock do
    @child.send(method_name, *args, &block)
  end
end

Instance Method Details

#pathObject



98
99
100
# File 'lib/logstash/outputs/gcs/temp_log_file.rb', line 98

def path
  @lock.with_read_lock { @child.path }
end

#time_since_syncObject



94
95
96
# File 'lib/logstash/outputs/gcs/temp_log_file.rb', line 94

def time_since_sync
  @lock.with_read_lock { @child.time_since_sync }
end