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 28 |
# 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) @ready = Concurrent::Event.new end |
Instance Method Details
#initialized? ⇒ Boolean
30 31 32 |
# File 'lib/ldclient-rb/stream.rb', line 30 def initialized? @initialized.value end |
#start ⇒ Object
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 59 60 61 62 63 |
# File 'lib/ldclient-rb/stream.rb', line 34 def start return @ready unless @started.make_true @config.logger.info { "[LDClient] Initializing stream connection" } headers = { 'Authorization' => @sdk_key, 'User-Agent' => 'RubyClient/' + LaunchDarkly::VERSION } opts = { headers: headers, proxy: @config.proxy, read_timeout: READ_TIMEOUT_SECONDS, logger: @config.logger } @es = SSE::SSEClient.new(@config.stream_uri + "/all", opts) do |conn| conn.on_event { |event| (event, event.type) } conn.on_error { |err| status = err[:status_code] = Util.(status, "streaming connection", "will retry") @config.logger.error { "[LDClient] #{}" } if !Util.http_error_recoverable?(status) @ready.set # if client was waiting on us, make it stop waiting - has no effect if already set stop end } end @ready end |
#stop ⇒ Object
65 66 67 68 69 70 |
# File 'lib/ldclient-rb/stream.rb', line 65 def stop if @stopped.make_true @es.close @config.logger.info { "[LDClient] Stream connection stopped" } end end |