Class: SplitIoClient::SSE::SSEHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/sse/sse_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, synchronizer, splits_repository, segments_repository, notification_manager_keeper) {|_self| ... } ⇒ SSEHandler

Returns a new instance of SSEHandler.

Yields:

  • (_self)

Yield Parameters:



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| handle_incoming_message(event) }
    client.on_action { |action| process_action(action) }
  end

  @on = { action: ->(_) {} }

  yield self if block_given?
end

Instance Attribute Details

#sse_clientObject (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

Returns:

  • (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_workersObject



40
41
42
43
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 40

def start_workers
  @splits_worker.start
  @segments_worker.start
end

#stopObject



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_workersObject



45
46
47
48
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 45

def stop_workers
  @splits_worker.stop
  @segments_worker.stop
end