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
-
#add_listener(listener) ⇒ Object
included
from LaunchDarkly::Interfaces::DataSource::StatusProvider
Subscribes for notifications of status changes.
-
#initialize(status_broadcaster, clock: MONOTONIC_CLOCK) ⇒ StatusProviderV2
constructor
private
Creates a new status provider.
-
#remove_listener(listener) ⇒ Object
included
from LaunchDarkly::Interfaces::DataSource::StatusProvider
Unsubscribes from notifications of status changes.
-
#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.
Constructor Details
#initialize(status_broadcaster, clock: MONOTONIC_CLOCK) ⇒ 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.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ldclient-rb/impl/data_source/status_provider.rb', line 32 def initialize(status_broadcaster, clock: MONOTONIC_CLOCK) @status_broadcaster = status_broadcaster @clock = clock @status = LaunchDarkly::Interfaces::DataSource::Status.new( LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING, Time.now, nil ) @state_since_monotonic = @clock.call @lock = Concurrent::ReadWriteLock.new end |
Instance Method Details
#add_listener(listener) ⇒ Object Originally defined in module LaunchDarkly::Interfaces::DataSource::StatusProvider
Subscribes for notifications of status changes.
The listener will be notified whenever any property of the status has changed. See LaunchDarkly::Interfaces::DataSource::Status for an explanation of the meaning of each property and what could cause it to change.
Notifications will be dispatched on a worker thread. It is the listener's responsibility to return as soon as possible so as not to block subsequent notifications.
#remove_listener(listener) ⇒ Object Originally defined in module LaunchDarkly::Interfaces::DataSource::StatusProvider
Unsubscribes from notifications of status changes.
#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.
45 46 47 48 49 |
# File 'lib/ldclient-rb/impl/data_source/status_provider.rb', line 45 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.
After a Status::OFF status, the SDK ignores every later update.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ldclient-rb/impl/data_source/status_provider.rb', line 71 def update_status(new_state, new_error) return if new_state.nil? 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? if new_state == old_status.state new_since = @status.state_since else new_since = Time.now @state_since_monotonic = @clock.call end 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 |