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_action(&action) ⇒ 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 |
# 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_action { |action| process_action(action) } end @on = { action: ->(_) {} } 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
36 37 38 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 36 def connected? @sse_client&.connected? || false end |
#on_action(&action) ⇒ Object
50 51 52 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 50 def on_action(&action) @on[:action] = action end |
#start(token_jwt, channels) ⇒ Object
24 25 26 27 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 24 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
40 41 42 43 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 40 def start_workers @splits_worker.start @segments_worker.start end |
#stop ⇒ Object
29 30 31 32 33 34 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 29 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
45 46 47 48 |
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 45 def stop_workers @splits_worker.stop @segments_worker.stop end |