Class: LogStash::Outputs::Swift::FileRepository::PrefixedValue

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/swift/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
# File 'lib/logstash/outputs/swift/file_repository.rb', line 18

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

Instance Method Details

#apply(prefix) ⇒ Object



34
35
36
# File 'lib/logstash/outputs/swift/file_repository.rb', line 34

def apply(prefix)
  return self
end

#delete!Object



38
39
40
# File 'lib/logstash/outputs/swift/file_repository.rb', line 38

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

#stale?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/logstash/outputs/swift/file_repository.rb', line 30

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

#with_lockObject



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

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