Class: Stoplight::DataStore::Memory

Inherits:
Base
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/stoplight/data_store/memory.rb

Overview

See Also:

Instance Method Summary collapse

Constructor Details

#initializeMemory


11
12
13
14
15
# File 'lib/stoplight/data_store/memory.rb', line 11

def initialize
  @failures = Hash.new { |h, k| h[k] = [] }
  @states = Hash.new { |h, k| h[k] = State::UNLOCKED }
  super() # MonitorMixin
end

Instance Method Details

#clear_failures(light) ⇒ Object


37
38
39
# File 'lib/stoplight/data_store/memory.rb', line 37

def clear_failures(light)
  synchronize { @failures.delete(light.name) }
end

#clear_state(light) ⇒ Object


49
50
51
# File 'lib/stoplight/data_store/memory.rb', line 49

def clear_state(light)
  synchronize { @states.delete(light.name) }
end

#get_all(light) ⇒ Object


21
22
23
# File 'lib/stoplight/data_store/memory.rb', line 21

def get_all(light)
  synchronize { [@failures[light.name], @states[light.name]] }
end

#get_failures(light) ⇒ Object


25
26
27
# File 'lib/stoplight/data_store/memory.rb', line 25

def get_failures(light)
  synchronize { @failures[light.name] }
end

#get_state(light) ⇒ Object


41
42
43
# File 'lib/stoplight/data_store/memory.rb', line 41

def get_state(light)
  synchronize { @states[light.name] }
end

#namesObject


17
18
19
# File 'lib/stoplight/data_store/memory.rb', line 17

def names
  synchronize { @failures.keys | @states.keys }
end

#record_failure(light, failure) ⇒ Object


29
30
31
32
33
34
35
# File 'lib/stoplight/data_store/memory.rb', line 29

def record_failure(light, failure)
  synchronize do
    n = light.threshold - 1
    @failures[light.name] = @failures[light.name].first(n)
    @failures[light.name].unshift(failure).size
  end
end

#set_state(light, state) ⇒ Object


45
46
47
# File 'lib/stoplight/data_store/memory.rb', line 45

def set_state(light, state)
  synchronize { @states[light.name] = state }
end