Class: LaunchDarkly::StreamProcessor
- Inherits:
-
Object
- Object
- LaunchDarkly::StreamProcessor
- Defined in:
- lib/ldclient-rb/stream.rb
Instance Method Summary collapse
-
#initialize(sdk_key, config, requestor) ⇒ StreamProcessor
constructor
A new instance of StreamProcessor.
- #initialized? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(sdk_key, config, requestor) ⇒ StreamProcessor
Returns a new instance of StreamProcessor.
19 20 21 22 23 24 25 26 27 |
# File 'lib/ldclient-rb/stream.rb', line 19 def initialize(sdk_key, config, requestor) @sdk_key = sdk_key @config = config @feature_store = config.feature_store @requestor = requestor @initialized = Concurrent::AtomicBoolean.new(false) @started = Concurrent::AtomicBoolean.new(false) @stopped = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#initialized? ⇒ Boolean
29 30 31 |
# File 'lib/ldclient-rb/stream.rb', line 29 def initialized? @initialized.value end |
#start ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ldclient-rb/stream.rb', line 33 def start return unless @started.make_true @config.logger.info { "[LDClient] Initializing stream connection" } headers = { 'Authorization' => @sdk_key, 'User-Agent' => 'RubyClient/' + LaunchDarkly::VERSION } opts = {:headers => headers, :with_credentials => true, :proxy => @config.proxy, :read_timeout => READ_TIMEOUT_SECONDS} @es = Celluloid::EventSource.new(@config.stream_uri + "/all", opts) do |conn| conn.on(PUT) { || (, PUT) } conn.on(PATCH) { || (, PATCH) } conn.on(DELETE) { || (, DELETE) } conn.on(INDIRECT_PUT) { || (, INDIRECT_PUT) } conn.on(INDIRECT_PATCH) { || (, INDIRECT_PATCH) } conn.on_error { |err| @config.logger.error { "[LDClient] Unexpected status code #{err[:status_code]} from streaming connection" } if err[:status_code] == 401 @config.logger.error { "[LDClient] Received 401 error, no further streaming connection will be made since SDK key is invalid" } stop end } end end |
#stop ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ldclient-rb/stream.rb', line 60 def stop if @stopped.make_true @es.close @config.logger.info { "[LDClient] Stream connection stopped" } end end |