From c9f90675348e20225343c197d2d01339a2fc15ca Mon Sep 17 00:00:00 2001 From: Braden Schaeffer Date: Tue, 5 Sep 2017 17:26:27 -0400 Subject: [PATCH] Replace concurrent-ruby with MonitorMixin --- lib/stoplight/data_store/memory.rb | 41 ++++++++++++------------------ stoplight.gemspec | 6 ----- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/lib/stoplight/data_store/memory.rb b/lib/stoplight/data_store/memory.rb index 992ed8e..3caefad 100644 --- a/lib/stoplight/data_store/memory.rb +++ b/lib/stoplight/data_store/memory.rb @@ -1,62 +1,53 @@ # coding: utf-8 -require 'concurrent' +require 'monitor' module Stoplight module DataStore # @see Base class Memory < Base + include MonitorMixin + def initialize - @failures = Concurrent::Map.new { [] } - @states = Concurrent::Map.new { State::UNLOCKED } - @lock = Monitor.new + @failures = Hash.new { |h, k| h[k] = [] } + @states = Hash.new { |h, k| h[k] = State::UNLOCKED } + super() # MonitorMixin end def names - (all_failures.keys + all_states.keys).uniq + synchronize { @failures.keys | @states.keys } end def get_all(light) - [get_failures(light), get_state(light)] + synchronize { [@failures[light.name], @states[light.name]] } end def get_failures(light) - all_failures[light.name] + synchronize { @failures[light.name] } end def record_failure(light, failure) - @lock.synchronize do + synchronize do n = light.threshold - 1 - failures = get_failures(light).first(n).unshift(failure) - all_failures[light.name] = failures - failures.size + @failures[light.name] = @failures[light.name].first(n) + @failures[light.name].unshift(failure).size end end def clear_failures(light) - all_failures.delete(light.name) + synchronize { @failures.delete(light.name) } end def get_state(light) - all_states[light.name] + synchronize { @states[light.name] } end def set_state(light, state) - all_states[light.name] = state + synchronize { @states[light.name] = state } end def clear_state(light) - all_states.delete(light.name) - end - - private - - def all_failures - @failures - end - - def all_states - @states + synchronize { @states.delete(light.name) } end end end diff --git a/stoplight.gemspec b/stoplight.gemspec index cbe28c1..b9bf14b 100644 --- a/stoplight.gemspec +++ b/stoplight.gemspec @@ -31,12 +31,6 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 2.1' - { - 'concurrent-ruby' => '1.0' - }.each do |name, version| - gem.add_dependency(name, "~> #{version}") - end - { 'benchmark-ips' => '2.3', 'bugsnag' => '4.0',