Class: LaunchDarkly::Impl::DataSource::UpdateSink Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::DataSource::UpdateSink
- Defined in:
- lib/ldclient-rb/impl/data_source.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.
Instance Attribute Summary collapse
- #current_status ⇒ LaunchDarkly::Interfaces::DataSource::Status readonly private
Instance Method Summary collapse
- #delete(kind, key, version) ⇒ Object private
- #init(all_data) ⇒ Object private
-
#initialize(data_store, status_broadcaster, flag_change_broadcaster) ⇒ UpdateSink
constructor
private
A new instance of UpdateSink.
- #update_status(new_state, new_error) ⇒ Object private
- #upsert(kind, item) ⇒ Object private
Constructor Details
#initialize(data_store, status_broadcaster, flag_change_broadcaster) ⇒ UpdateSink
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 UpdateSink.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ldclient-rb/impl/data_source.rb', line 34 def initialize(data_store, status_broadcaster, flag_change_broadcaster) # @type [LaunchDarkly::Interfaces::FeatureStore] @data_store = data_store # @type [Broadcaster] @status_broadcaster = status_broadcaster # @type [Broadcaster] @flag_change_broadcaster = flag_change_broadcaster @dependency_tracker = LaunchDarkly::Impl::DependencyTracker.new @mutex = Mutex.new @current_status = LaunchDarkly::Interfaces::DataSource::Status.new( LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING, Time.now, nil) end |
Instance Attribute Details
#current_status ⇒ LaunchDarkly::Interfaces::DataSource::Status (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.
32 33 34 |
# File 'lib/ldclient-rb/impl/data_source.rb', line 32 def current_status @current_status end |
Instance Method Details
#delete(kind, key, version) ⇒ 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.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ldclient-rb/impl/data_source.rb', line 85 def delete(kind, key, version) monitor_store_update { @data_store.delete(kind, key, version) } @dependency_tracker.update_dependencies_from(kind, key, nil) if @flag_change_broadcaster.has_listeners? affected_items = Set.new @dependency_tracker.add_affected_items(affected_items, {kind: kind, key: key}) send_change_events(affected_items) end end |
#init(all_data) ⇒ 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ldclient-rb/impl/data_source.rb', line 50 def init(all_data) old_data = nil monitor_store_update do if @flag_change_broadcaster.has_listeners? old_data = {} Impl::DataStore::ALL_KINDS.each do |kind| old_data[kind] = @data_store.all(kind) end end @data_store.init(all_data) end update_full_dependency_tracker(all_data) return if old_data.nil? send_change_events( compute_changed_items_for_full_data_set(old_data, all_data) ) end |
#update_status(new_state, new_error) ⇒ 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ldclient-rb/impl/data_source.rb', line 96 def update_status(new_state, new_error) return if new_state.nil? status_to_broadcast = nil @mutex.synchronize do old_status = @current_status if new_state == LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED && old_status.state == LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING # See {LaunchDarkly::Interfaces::DataSource::UpdateSink#update_status} for more information new_state = LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING end unless new_state == old_status.state && new_error.nil? @current_status = LaunchDarkly::Interfaces::DataSource::Status.new( new_state, new_state == current_status.state ? current_status.state_since : Time.now, new_error.nil? ? current_status.last_error : new_error ) status_to_broadcast = current_status end end @status_broadcaster.broadcast(status_to_broadcast) unless status_to_broadcast.nil? end |
#upsert(kind, item) ⇒ 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.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ldclient-rb/impl/data_source.rb', line 72 def upsert(kind, item) monitor_store_update { @data_store.upsert(kind, item) } # TODO(sc-197908): We only want to do this if the store successfully # updates the record. @dependency_tracker.update_dependencies_from(kind, item[:key], item) if @flag_change_broadcaster.has_listeners? affected_items = Set.new @dependency_tracker.add_affected_items(affected_items, {kind: kind, key: item[:key]}) send_change_events(affected_items) end end |