module BELParser::Resource::EagerReader
Constants
- CACHE_KEYS
- EMPTY_ARRAY
Public Instance Methods
load_threads()
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 18 def load_threads @load_threads ||= Concurrent::Hash.new end
load_values(identifier)
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 22 def load_values(identifier) lock = locks[identifier] ||= Mutex.new if identifier.include?('taxonomy') puts "load_all_values, try lock..." end if lock.try_lock load_threads[identifier] = Thread.new do value_hash = { :name => {}, :identifier => {}, :title => {}, :synonyms => {} } retrieve_values_from_resource(identifier).each do |concept| value_hash[:name][concept.name] = concept value_hash[:identifier][concept.identifier] = concept value_hash[:title][concept.title] = concept concept.synonyms.each do |synonym| value_hash[:synonyms][synonym] = concept end end resources[identifier] = value_hash lock.unlock end end end
locks()
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 14 def locks @locks ||= Concurrent::Hash.new end
resources()
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 10 def resources @resources ||= Concurrent::Hash.new end
retrieve_resource(resource_identifier)
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 49 def retrieve_resource(resource_identifier) if !resources.key?(resource_identifier) load_all_values(resource_identifier) end end
retrieve_value_from_resource(resource_identifier, value)
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 55 def retrieve_value_from_resource(resource_identifier, value) if !resources.key?(resource_identifier) load_all_values(resource_identifier) if load_threads.key?(resource_identifier) load_thread = load_threads[resource_identifier] load_thread.join unless load_thread == Thread.current end end concepts = resources[resource_identifier] return nil unless concepts CACHE_KEYS.each do |key| cached_concept = concepts[key].fetch(value, nil) return cached_concept if cached_concept end nil end
retrieve_values_from_resource(resource_identifier)
click to toggle source
# File lib/bel_parser/resource/eager_reader.rb, line 73 def retrieve_values_from_resource(resource_identifier) if !resources.key?(resource_identifier) load_all_values(resource_identifier) if load_threads.key?(resource_identifier) load_thread = load_threads[resource_identifier] load_thread.join unless load_thread == Thread.current end end concepts = resources[resource_identifier] return nil unless concepts concepts[:name].values end