Class: LaunchDarkly::Impl::DataStore::StatusProviderV2 Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
LaunchDarkly::Interfaces::DataStore::StatusProvider
Defined in:
lib/ldclient-rb/impl/data_store/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.

StatusProviderV2 is the FDv2-specific implementation of LaunchDarkly::Interfaces::DataStore::StatusProvider.

This type is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is not suitable for production usage.

Do not use it. You have been warned.

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(store, 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.

Initialize the status provider.

Parameters:

  • store (Object, nil)

    The feature store (may be nil for in-memory only)

  • status_broadcaster (LaunchDarkly::Impl::Broadcaster)

    Broadcaster for status changes

Since:

  • 5.5.0



31
32
33
34
35
36
37
# File 'lib/ldclient-rb/impl/data_store/status_provider.rb', line 31

def initialize(store, status_broadcaster)
  @store = store
  @status_broadcaster = status_broadcaster
  @lock = Concurrent::ReadWriteLock.new
  @status = LaunchDarkly::Interfaces::DataStore::Status.new(true, false)
  @monitoring_enabled = store_supports_monitoring?
end

Instance Method Details

#add_listener(listener) ⇒ Object Originally defined in module LaunchDarkly::Interfaces::DataStore::StatusProvider

Subscribes for notifications of status changes.

Applications may wish to know if there is an outage in a persistent data store, since that could mean that flag evaluations are unable to get the flag data from the store (unless it is currently cached) and therefore might return default values.

If the SDK receives an exception while trying to query or update the data store, then it notifies listeners that the store appears to be offline (LaunchDarkly::Interfaces::DataStore::Status#available is false) and begins polling the store at intervals until a query succeeds. Once it succeeds, it notifies listeners again with LaunchDarkly::Interfaces::DataStore::Status#available set to true.

This method has no effect if the data store implementation does not support status tracking, such as if you are using the default in-memory store rather than a persistent store.

Parameters:

  • listener (#update)

    the listener to add

#monitoring_enabled?Boolean

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.

Indicates whether the current data store implementation supports status monitoring.

This is normally true for all persistent data stores, and false for the default in-memory store. A true value means that any listeners added with LaunchDarkly::Interfaces::DataStore::StatusProvider#add_listener can expect to be notified if there is any error in storing data, and then notified again when the error condition is resolved. A false value means that the status is not meaningful and listeners should not expect to be notified.

Returns:

  • (Boolean)

    true if status monitoring is enabled

Since:

  • 5.5.0



61
62
63
# File 'lib/ldclient-rb/impl/data_store/status_provider.rb', line 61

def monitoring_enabled?
  @monitoring_enabled
end

#remove_listener(listener) ⇒ Object Originally defined in module LaunchDarkly::Interfaces::DataStore::StatusProvider

Unsubscribes from notifications of status changes.

This method has no effect if the data store implementation does not support status tracking, such as if you are using the default in-memory store rather than a persistent store.

Parameters:

  • listener (Object)

    the listener to remove; if no such listener was added, this does nothing

#statusStatus

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 store.

This is only meaningful for persistent stores, or any custom data store implementation that makes use of the status reporting mechanism provided by the SDK. For the default in-memory store, the status will always be reported as "available".

Returns:

  • (Status)

    the latest status

Since:

  • 5.5.0



54
55
56
57
58
# File 'lib/ldclient-rb/impl/data_store/status_provider.rb', line 54

def status
  @lock.with_read_lock do
    LaunchDarkly::Interfaces::DataStore::Status.new(@status.available, @status.stale)
  end
end

#update_status(status) ⇒ 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.

Reports a change in the data store's operational status.

This is what makes the status monitoring mechanisms in LaunchDarkly::Impl::DataStore::StatusProvider work.

Parameters:

  • status (Status)

    the updated status properties

Since:

  • 5.5.0



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ldclient-rb/impl/data_store/status_provider.rb', line 40

def update_status(status)
  modified = false

  @lock.with_write_lock do
    if @status.available != status.available || @status.stale != status.stale
      @status = status
      modified = true
    end
  end

  @status_broadcaster.broadcast(status) if modified
end