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.



18
19
20
21
22
23
# File 'lib/logstash/outputs/s3/file_repository.rb', line 18

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

Instance Method Details

#apply(prefix) ⇒ Object



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

def apply(prefix)
  return self
end

#delete!Object



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

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

#deleted?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/logstash/outputs/s3/file_repository.rb', line 46

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

#stale?Boolean

Returns:

  • (Boolean)


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

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

#with_lockObject



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

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