Class: SplitIoClient::SSE::SSEHandler
- Inherits:
-
Object
- Object
- SplitIoClient::SSE::SSEHandler
- Defined in:
- lib/splitclient-rb/sse/sse_handler.rb
Instance Attribute Summary collapse
-
#sse_client ⇒ Object
readonly
Returns the value of attribute sse_client.
Instance Method Summary collapse
- #connected? ⇒ Boolean
-
#initialize(config, synchronizer, splits_repository, segments_repository, notification_manager_keeper) {|_self| ... } ⇒ SSEHandler
constructor
A new instance of SSEHandler.
- #on_connected(&action) ⇒ Object
- #on_disconnect(&action) ⇒ Object
- #process_disconnect ⇒ Object
- #start(token_jwt, channels) ⇒ Object
- #start_workers ⇒ Object
- #stop ⇒ Object
- #stop_workers ⇒ Object
Constructor Details
#initialize(config, synchronizer, splits_repository, segments_repository, notification_manager_keeper) {|_self| ... } ⇒ SSEHandler
Returns a new instance of SSEHandler.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 8 def initialize(config, synchronizer, splits_repository, segments_repository, notification_manager_keeper) @config = config @notification_manager_keeper = notification_manager_keeper @splits_worker = SplitIoClient::SSE::Workers::SplitsWorker.new(synchronizer, config, splits_repository) @segments_worker = SplitIoClient::SSE::Workers::SegmentsWorker.new(synchronizer, config, segments_repository) @notification_processor = SplitIoClient::SSE::NotificationProcessor.new(config, @splits_worker, @segments_worker) @sse_client = SSE::EventSource::Client.new(@config) do |client| client.on_event { |event| (event) } client.on_connected { process_connected } client.on_disconnect { process_disconnect } end @on = { connected: ->(_) {}, disconnect: ->(_) {} } yield self if block_given? end |
Instance Attribute Details
#sse_client ⇒ Object (readonly)
Returns the value of attribute sse_client.
6 7 8 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 6 def sse_client @sse_client end |
Instance Method Details
#connected? ⇒ Boolean
37 38 39 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 37 def connected? @sse_client&.connected? || false end |
#on_connected(&action) ⇒ Object
51 52 53 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 51 def on_connected(&action) @on[:connected] = action end |
#on_disconnect(&action) ⇒ Object
55 56 57 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 55 def on_disconnect(&action) @on[:disconnect] = action end |
#process_disconnect ⇒ Object
59 60 61 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 59 def process_disconnect @on[:disconnect].call end |
#start(token_jwt, channels) ⇒ Object
25 26 27 28 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 25 def start(token_jwt, channels) url = "#{@config.streaming_service_url}?channels=#{channels}&v=1.1&accessToken=#{token_jwt}" @sse_client.start(url) end |
#start_workers ⇒ Object
41 42 43 44 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 41 def start_workers @splits_worker.start @segments_worker.start end |
#stop ⇒ Object
30 31 32 33 34 35 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 30 def stop @sse_client.close stop_workers rescue StandardError => e @config.logger.debug("SSEHandler stop error: #{e.inspect}") if @config.debug_enabled end |
#stop_workers ⇒ Object
46 47 48 49 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 46 def stop_workers @splits_worker.stop @segments_worker.stop end |