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(metadata, synchronizer, repositories, notification_manager_keeper, telemetry_runtime_producer) {|_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
23
24
25
26
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 8

def initialize(,
               synchronizer,
               repositories,
               notification_manager_keeper,
               telemetry_runtime_producer)
  @config = [:config]
  @notification_manager_keeper = notification_manager_keeper
  @splits_worker = SplitIoClient::SSE::Workers::SplitsWorker.new(synchronizer, @config, repositories[:splits])
  @segments_worker = SplitIoClient::SSE::Workers::SegmentsWorker.new(synchronizer, @config, repositories[:segments])
  @notification_processor = SplitIoClient::SSE::NotificationProcessor.new(@config, @splits_worker, @segments_worker)
  @sse_client = SSE::EventSource::Client.new(@config, [:api_key], telemetry_runtime_producer) 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)


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

def connected?
  @sse_client&.connected? || false
end

#on_action(&action) ⇒ Object



54
55
56
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 54

def on_action(&action)
  @on[:action] = action
end

#start(token_jwt, channels) ⇒ Object



28
29
30
31
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 28

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



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

def start_workers
  @splits_worker.start
  @segments_worker.start
end

#stopObject



33
34
35
36
37
38
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 33

def stop
  @sse_client.close(Constants::PUSH_NONRETRYABLE_ERROR)
  stop_workers
rescue StandardError => e
  @config.logger.debug("SSEHandler stop error: #{e.inspect}") if @config.debug_enabled
end

#stop_workersObject



49
50
51
52
# File 'lib/splitclient-rb/sse/sse_handler.rb', line 49

def stop_workers
  @splits_worker.stop
  @segments_worker.stop
end