Class: LaunchDarkly::Impl::DataStore::FeatureStoreClientWrapperV2 Private

Inherits:
Object
  • Object
show all
Includes:
LaunchDarkly::Interfaces::FeatureStore
Defined in:
lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.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 additional behavior that the client requires before or after feature store operations. Currently this just means sorting the data set for init() and dealing with data store status listeners.

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(store, store_update_sink, logger) ⇒ FeatureStoreClientWrapperV2

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

Parameters:

Since:

  • 5.5.0



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 25

def initialize(store, store_update_sink, logger)
  @store = store
  @store_update_sink = store_update_sink
  @logger = logger
  @monitoring_enabled = store_supports_monitoring?

  # Thread synchronization
  @mutex = Mutex.new
  @last_available = true
  @poller = nil
  @closed = false
end

Instance Method Details

#all(kind) ⇒ Hash

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 all stored entities of the specified kind, not including deleted entities.

Parameters:

  • kind (Object)

    the kind of entity to get

Returns:

  • (Hash)

    a hash where each key is the entity's :key property and each value is the entity

Since:

  • 5.5.0



49
50
51
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 49

def all(kind)
  wrapper { @store.all(kind) }
end

#delete(kind, key, version) ⇒ 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.

Attempt to delete an entity if it exists. Deletion should only succeed if the version parameter is greater than the existing entity's :version; otherwise, the method should do nothing.

Parameters:

  • kind (Object)

    the kind of entity to delete

  • key (String)

    the unique key of the entity

  • version (Integer)

    the entity must have a lower version than this to be deleted

Since:

  • 5.5.0



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

def delete(kind, key, version)
  wrapper { @store.delete(kind, key, version) }
end

#get(kind, key) ⇒ Hash

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 entity to which the specified key is mapped, if any.

Parameters:

  • kind (Object)

    the kind of entity to get

  • key (String)

    the unique key of the entity to get

Returns:

  • (Hash)

    the entity; nil if the key was not found, or if the stored entity's :deleted property was true

Since:

  • 5.5.0



44
45
46
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 44

def get(kind, key)
  wrapper { @store.get(kind, key) }
end

#init(all_data) ⇒ 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.

Initializes (or re-initializes) the store with the specified set of entities. Any existing entries will be removed. Implementations can assume that this data set is up to date-- there is no need to perform individual version comparisons between the existing objects and the supplied features.

If possible, the store should update the entire data set atomically. If that is not possible, it should iterate through the outer hash and then the inner hash using the existing iteration order of those hashes (the SDK will ensure that the items were inserted into the hashes in the correct order), storing each item, and then delete any leftover items at the very end.

Parameters:

  • all_data (Hash)

    a hash where each key is one of the data kind objects, and each value is in turn a hash of string keys to entities

Since:

  • 5.5.0



39
40
41
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 39

def init(all_data)
  wrapper { @store.init(FeatureStoreDataSetSorter.sort_all_collections(all_data)) }
end

#initialized?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.

Checks whether this store has been initialized. That means that init has been called either by this process, or (if the store can be shared) by another process. This method will be called frequently, so it should be efficient. You can assume that if it has returned true once, it can continue to return true, i.e. a store cannot become uninitialized again.

Returns:

  • (Boolean)

    true if the store is in an initialized state

Since:

  • 5.5.0



64
65
66
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 64

def initialized?
  @store.initialized?
end

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

Returns whether monitoring is enabled.

Returns:

  • (Boolean)

Since:

  • 5.5.0



90
91
92
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 90

def monitoring_enabled?
  @monitoring_enabled
end

#stopvoid

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.

Performs any necessary cleanup to shut down the store when the client is being shut down.

This method should be idempotent - it is safe to call it multiple times, and subsequent calls after the first should have no effect.

Since:

  • 5.5.0



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 69

def stop
  poller_to_stop = nil

  @mutex.synchronize do
    return if @closed

    @closed = true
    poller_to_stop = @poller
    @poller = nil
  end

  poller_to_stop.stop if poller_to_stop

  @store.stop
end

#upsert(kind, item) ⇒ 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.

Attempt to add an entity, or update an existing entity with the same key. An update should only succeed if the new item's :version is greater than the old one; otherwise, the method should do nothing.

Parameters:

  • kind (Object)

    the kind of entity to add or update

  • item (Hash)

    the entity to add or update

Since:

  • 5.5.0



59
60
61
# File 'lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb', line 59

def upsert(kind, item)
  wrapper { @store.upsert(kind, item) }
end