Class: LaunchDarkly::StreamProcessor
- Inherits:
-
Object
- Object
- LaunchDarkly::StreamProcessor
- Defined in:
- lib/ldclient-rb/stream.rb
Instance Method Summary collapse
- #get_all_features ⇒ Object
- #get_feature(key) ⇒ Object
-
#initialize(api_key, config) ⇒ StreamProcessor
constructor
A new instance of StreamProcessor.
- #initialized? ⇒ Boolean
- #should_fallback_update ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
Constructor Details
#initialize(api_key, config) ⇒ StreamProcessor
Returns a new instance of StreamProcessor.
67 68 69 70 71 72 73 |
# File 'lib/ldclient-rb/stream.rb', line 67 def initialize(api_key, config) @api_key = api_key @config = config @store = config.feature_store ? config.feature_store : InMemoryFeatureStore.new @disconnected = Concurrent::AtomicReference.new(nil) @started = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#get_all_features ⇒ Object
83 84 85 86 87 88 |
# File 'lib/ldclient-rb/stream.rb', line 83 def get_all_features if not initialized? throw :uninitialized end @store.all end |
#get_feature(key) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/ldclient-rb/stream.rb', line 90 def get_feature(key) if not initialized? throw :uninitialized end @store.get(key) end |
#initialized? ⇒ Boolean
75 76 77 |
# File 'lib/ldclient-rb/stream.rb', line 75 def initialized? @store.initialized? end |
#should_fallback_update ⇒ Object
165 166 167 168 |
# File 'lib/ldclient-rb/stream.rb', line 165 def should_fallback_update disc = @disconnected.get !disc.nil? && disc < (Time.now - 120) end |
#start ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ldclient-rb/stream.rb', line 110 def start # Try to start the reactor. If it's not started, we shouldn't start # the stream processor return if not start_reactor # If someone else booted the stream processor connection, just return return unless @started.make_true # If we're the first and only thread to set started, boot # the stream processor connection EM.defer do boot_event_manager end end |
#started? ⇒ Boolean
79 80 81 |
# File 'lib/ldclient-rb/stream.rb', line 79 def started? @started.value end |