Class: LaunchDarkly::Impl::DataSource::StatusProviderV2 Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::DataSource::StatusProviderV2
- Extended by:
- Forwardable
- Defined in:
- lib/ldclient-rb/impl/data_source/status_provider.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.
Provides status tracking and listener management for data sources.
This class implements the LaunchDarkly::Interfaces::DataSource::StatusProvider interface. It maintains the current status of the data source and broadcasts status changes to listeners.
Instance Method Summary collapse
-
#initialize(status_broadcaster) ⇒ StatusProviderV2
constructor
private
Creates a new status provider.
-
#status ⇒ Status
private
Returns the current status of the data source.
-
#update_status(new_state, new_error) ⇒ Object
private
Informs the SDK of a change in the data source’s status.
Methods included from LaunchDarkly::Interfaces::DataSource::StatusProvider
#add_listener, #remove_listener
Constructor Details
#initialize(status_broadcaster) ⇒ StatusProviderV2
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.
Creates a new status provider.
27 28 29 30 31 32 33 34 35 |
# File 'lib/ldclient-rb/impl/data_source/status_provider.rb', line 27 def initialize(status_broadcaster) @status_broadcaster = status_broadcaster @status = LaunchDarkly::Interfaces::DataSource::Status.new( LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING, Time.now, nil ) @lock = Concurrent::ReadWriteLock.new end |
Instance Method Details
#status ⇒ Status
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 current status of the data source.
All of the built-in data source implementations are guaranteed to update this status whenever they successfully initialize, encounter an error, or recover after an error.
For a custom data source implementation, it is the responsibility of the data source to push status updates to the SDK; if it does not do so, the status will always be reported as Status::INITIALIZING.
38 39 40 41 42 |
# File 'lib/ldclient-rb/impl/data_source/status_provider.rb', line 38 def status @lock.with_read_lock do @status end 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.
Informs the SDK of a change in the data source’s status.
Data source implementations should use this method if they have any concept of being in a valid state, a temporarily disconnected state, or a permanently stopped state.
If new_state is different from the previous state, and/or new_error is non-null, the SDK will start returning the new status (adding a timestamp for the change) from LaunchDarkly::Impl::DataSource::StatusProvider#status, and will trigger status change events to any registered listeners.
A special case is that if new_state is Status::INTERRUPTED, but the previous state was Status::INITIALIZING, the state will remain at Status::INITIALIZING because Status::INTERRUPTED is only meaningful after a successful startup.
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 73 74 75 76 77 78 |
# File 'lib/ldclient-rb/impl/data_source/status_provider.rb', line 45 def update_status(new_state, new_error) status_to_broadcast = nil @lock.with_write_lock do old_status = @status # Special handling: INTERRUPTED during INITIALIZING stays INITIALIZING if new_state == LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED && old_status.state == LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING new_state = LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING end # Special handling: You can't go back to INITIALIZING after being anything else if new_state == LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING && !old_status.state.nil? new_state = old_status.state end # No change if state is the same and no error return if new_state == old_status.state && new_error.nil? new_since = new_state == old_status.state ? @status.state_since : Time.now new_error = @status.last_error if new_error.nil? @status = LaunchDarkly::Interfaces::DataSource::Status.new( new_state, new_since, new_error ) status_to_broadcast = @status end @status_broadcaster.broadcast(status_to_broadcast) if status_to_broadcast end |