Class: LaunchDarkly::Impl::DataSource::UpdateSink Private

Inherits:
Object
  • Object
show all
Includes:
LaunchDarkly::Interfaces::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.

Since:

  • 5.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Since:

  • 5.5.0



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 55

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
  @environment_id = nil
  @current_status = LaunchDarkly::Interfaces::DataSource::Status.new(
    LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING,
    Time.now,
    nil)
end

Instance Attribute Details

#current_statusLaunchDarkly::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.



53
54
55
# File 'lib/ldclient-rb/impl/data_source.rb', line 53

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.

Since:

  • 5.5.0



122
123
124
125
126
127
128
129
130
131
# File 'lib/ldclient-rb/impl/data_source.rb', line 122

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

#environment_idString?

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 The environment ID reported by LaunchDarkly, if known.

Returns:

  • (String, nil)

    The environment ID reported by LaunchDarkly, if known

Since:

  • 5.5.0



75
76
77
# File 'lib/ldclient-rb/impl/data_source.rb', line 75

def environment_id
  @mutex.synchronize { @environment_id }
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.

Since:

  • 5.5.0



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ldclient-rb/impl/data_source.rb', line 87

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

#set_environment_id(environment_id) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • environment_id (String)

Since:

  • 5.5.0



83
84
85
# File 'lib/ldclient-rb/impl/data_source.rb', line 83

def set_environment_id(environment_id)
  @mutex.synchronize { @environment_id = environment_id }
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.

Since:

  • 5.5.0



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ldclient-rb/impl/data_source.rb', line 133

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.

Since:

  • 5.5.0



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ldclient-rb/impl/data_source.rb', line 109

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