Class: LogStash::Outputs::S3::FileRepository::PrefixedValue

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/s3/file_repository.rb

Overview

Ensure that all access or work done on a factory is threadsafe

Instance Method Summary collapse

Constructor Details

#initialize(file_factory, stale_time) ⇒ PrefixedValue

Returns a new instance of PrefixedValue.



16
17
18
19
20
# File 'lib/logstash/outputs/s3/file_repository.rb', line 16

def initialize(file_factory, stale_time)
  @file_factory = file_factory
  @lock = Mutex.new
  @stale_time = stale_time
end

Instance Method Details

#apply(prefix) ⇒ Object



32
33
34
# File 'lib/logstash/outputs/s3/file_repository.rb', line 32

def apply(prefix)
  return self
end

#delete!Object



36
37
38
# File 'lib/logstash/outputs/s3/file_repository.rb', line 36

def delete!
  with_lock{ |factory| factory.current.delete! }
end

#stale?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/logstash/outputs/s3/file_repository.rb', line 28

def stale?
  with_lock { |factory| factory.current.size == 0 && (Time.now - factory.current.ctime > @stale_time) }
end

#with_lockObject



22
23
24
25
26
# File 'lib/logstash/outputs/s3/file_repository.rb', line 22

def with_lock
  @lock.synchronize {
    yield @file_factory
  }
end