Class: LaunchDarkly::Impl::DataSystem::FDv1

Inherits:
Object
  • Object
show all
Includes:
LaunchDarkly::Impl::DataSystem
Defined in:
lib/ldclient-rb/impl/data_system/fdv1.rb

Overview

FDv1 wires the existing v1 data source and store behavior behind the generic DataSystem surface.

See Also:

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(sdk_key, config) ⇒ FDv1

Creates a new FDv1 data system.

Since:

  • 5.5.0



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 27

def initialize(sdk_key, config)
  @sdk_key = sdk_key
  @config = config
  @shared_executor = Concurrent::SingleThreadExecutor.new

  # Set up data store plumbing
  @data_store_broadcaster = LaunchDarkly::Impl::Broadcaster.new(@shared_executor, @config.logger)
  @data_store_update_sink = LaunchDarkly::Impl::DataStore::UpdateSink.new(
    @data_store_broadcaster
  )

  # Wrap the data store with client wrapper (must be created before status provider)
  @store_wrapper = LaunchDarkly::Impl::FeatureStoreClientWrapper.new(
    @config.feature_store,
    @data_store_update_sink,
    @config.logger
  )

  # Create status provider with store wrapper
  @data_store_status_provider = LaunchDarkly::Impl::DataStore::StatusProvider.new(
    @store_wrapper,
    @data_store_update_sink
  )

  # Set up data source plumbing
  @data_source_broadcaster = LaunchDarkly::Impl::Broadcaster.new(@shared_executor, @config.logger)
  @flag_change_broadcaster = LaunchDarkly::Impl::Broadcaster.new(@shared_executor, @config.logger)
  @data_source_update_sink = LaunchDarkly::Impl::DataSource::UpdateSink.new(
    @store_wrapper,
    @data_source_broadcaster,
    @flag_change_broadcaster
  )
  @data_source_status_provider = LaunchDarkly::Impl::DataSource::StatusProvider.new(
    @data_source_broadcaster,
    @data_source_update_sink
  )

  # Ensure v1 processors can find the sink via config for status updates
  @config.data_source_update_sink = @data_source_update_sink

  # Update processor created in start()
  @update_processor = nil

  # Diagnostic accumulator provided by client for streaming metrics
  @diagnostic_accumulator = nil
end

Instance Method Details

#data_availabilitySymbol

Indicates what form of data is currently available.

This is calculated dynamically based on current system state.

In LDD mode, always returns CACHED for backwards compatibility, even if the store is empty.

Since:

  • 5.5.0



117
118
119
120
121
122
123
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 117

def data_availability
  return DataAvailability::DEFAULTS if @config.offline?
  return DataAvailability::REFRESHED if @update_processor && @update_processor.initialized?
  return DataAvailability::CACHED if @store_wrapper.initialized?

  DataAvailability::DEFAULTS
end

#data_source_status_providerLaunchDarkly::Interfaces::DataSource::StatusProvider

Returns an interface for tracking the status of the data source.

The data source is the mechanism that the SDK uses to get feature flag configurations, such as a streaming connection (the default) or poll requests.

Since:

  • 5.5.0



97
98
99
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 97

def data_source_status_provider
  @data_source_status_provider
end

#data_store_status_providerLaunchDarkly::Interfaces::DataStore::StatusProvider

Returns an interface for tracking the status of a persistent data store.

The provider has methods for checking whether the data store is (as far as the SDK knows) currently operational, tracking changes in this status, and getting cache statistics. These are only relevant for a persistent data store; if you are using an in-memory data store, then this method will return a stub object that provides no information.

Since:

  • 5.5.0



102
103
104
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 102

def data_store_status_provider
  @data_store_status_provider
end

#flag_change_broadcasterLaunchDarkly::Impl::Broadcaster

Returns the broadcaster for flag change notifications.

Consumers can use this broadcaster to build their own flag tracker or listen for flag changes directly.

Since:

  • 5.5.0



107
108
109
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 107

def flag_change_broadcaster
  @flag_change_broadcaster
end

#set_diagnostic_accumulator(diagnostic_accumulator) ⇒ void

This method returns an undefined value.

Sets the diagnostic accumulator for streaming initialization metrics. This should be called before start() to ensure metrics are collected.

Since:

  • 5.5.0



92
93
94
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 92

def set_diagnostic_accumulator(diagnostic_accumulator)
  @diagnostic_accumulator = diagnostic_accumulator
end

#startConcurrent::Event

Starts the data system.

This method will return immediately. The returned event will be set when the system has reached an initial state (either permanently failed, e.g. due to bad auth, or succeeded).

If called multiple times, returns the same event as the first call.

Since:

  • 5.5.0



75
76
77
78
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 75

def start
  @update_processor ||= make_update_processor
  @update_processor.start
end

#stopvoid

This method returns an undefined value.

Halts the data system. Should be called when the client is closed to stop any long running operations. Makes the data system no longer usable.

Since:

  • 5.5.0



81
82
83
84
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 81

def stop
  @update_processor&.stop
  @shared_executor.shutdown
end

#storeObject

Returns the data store used by the data system.

Since:

  • 5.5.0



87
88
89
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 87

def store
  @store_wrapper
end

#target_availabilitySymbol

Indicates the ideal form of data attainable given the current configuration.

Since:

  • 5.5.0



126
127
128
129
130
# File 'lib/ldclient-rb/impl/data_system/fdv1.rb', line 126

def target_availability
  return DataAvailability::DEFAULTS if @config.offline?

  DataAvailability::REFRESHED
end