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
21
# File 'lib/logstash/outputs/s3/file_repository.rb', line 16

def initialize(file_factory, stale_time)
  @file_factory = file_factory
  @lock = Monitor.new
  @stale_time = stale_time
  @is_deleted = false
end

Instance Method Details

#apply(prefix) ⇒ Object



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

def apply(prefix)
  return self
end

#delete!Object



37
38
39
40
41
42
# File 'lib/logstash/outputs/s3/file_repository.rb', line 37

def delete!
  with_lock do |factory|
    factory.current.delete!
    @is_deleted = true
  end
end

#deleted?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/logstash/outputs/s3/file_repository.rb', line 44

def deleted?
  with_lock { |_| @is_deleted }
end

#stale?Boolean

Returns:

  • (Boolean)


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

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

#with_lockObject



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

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