Class: LaunchDarkly::Impl::BigSegmentStoreManager Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::BigSegmentStoreManager
- Defined in:
- lib/ldclient-rb/impl/big_segments.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- EMPTY_MEMBERSHIP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
use this as a singleton whenever a membership query returns nil; it's safe to reuse it because we will never modify the membership properties after they're queried
{}
Instance Attribute Summary collapse
- #status_provider ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #get_context_membership(context_key) ⇒ Object private
- #get_status ⇒ Object private
-
#initialize(big_segments_config, logger) ⇒ BigSegmentStoreManager
constructor
private
A new instance of BigSegmentStoreManager.
- #poll_store_and_update_status ⇒ Object private
- #stale?(timestamp) ⇒ Boolean private
- #stop ⇒ Object private
Constructor Details
#initialize(big_segments_config, logger) ⇒ BigSegmentStoreManager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of BigSegmentStoreManager.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 18 def initialize(big_segments_config, logger) @store = big_segments_config.store @stale_after_millis = big_segments_config.stale_after * 1000 @status_provider = BigSegmentStoreStatusProviderImpl.new(-> { get_status }) @logger = logger @last_status = nil @poll_lock = Mutex.new unless @store.nil? @cache = ExpiringCache.new(big_segments_config.context_cache_size, big_segments_config.context_cache_time) @poll_worker = RepeatingTask.new(big_segments_config.status_poll_interval, 0, -> { poll_store_and_update_status }, logger, 'LD/BigSegments#status') @poll_worker.start end end |
Instance Attribute Details
#status_provider ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 33 def status_provider @status_provider end |
Class Method Details
.hash_for_context_key(context_key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 104 def self.hash_for_context_key(context_key) Digest::SHA256.base64digest(context_key) end |
Instance Method Details
#get_context_membership(context_key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 40 def get_context_membership(context_key) return nil unless @store membership = @cache[context_key] unless membership begin membership = @store.get_membership(BigSegmentStoreManager.hash_for_context_key(context_key)) membership = EMPTY_MEMBERSHIP if membership.nil? @cache[context_key] = membership rescue => e Impl::Util.log_exception(@logger, "Big Segment store membership query returned error", e) return BigSegmentMembershipResult.new(nil, BigSegmentsStatus::STORE_ERROR) end end status = get_status unless status.available return BigSegmentMembershipResult.new(membership, BigSegmentsStatus::STORE_ERROR) end BigSegmentMembershipResult.new(membership, status.stale ? BigSegmentsStatus::STALE : BigSegmentsStatus::HEALTHY) end |
#get_status ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 60 def get_status status = @last_status return status if status new_status = @poll_lock.synchronize do # Another caller may have finished a poll while we waited for the lock. status = @last_status return status if status query_store_status end @status_provider.update_status(new_status) new_status end |
#poll_store_and_update_status ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 79 80 81 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 76 def poll_store_and_update_status new_status = @poll_lock.synchronize { query_store_status } @status_provider.update_status(new_status) new_status end |
#stale?(timestamp) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
100 101 102 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 100 def stale?() ! || ((Impl::Util.current_time_millis - ) >= @stale_after_millis) end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 |
# File 'lib/ldclient-rb/impl/big_segments.rb', line 35 def stop @poll_worker.stop unless @poll_worker.nil? @store.stop unless @store.nil? end |