Class: SplitIoClient::SSE::EventSource::Client
- Inherits:
-
Object
- Object
- SplitIoClient::SSE::EventSource::Client
- Defined in:
- lib/splitclient-rb/sse/event_source/client.rb
Constant Summary collapse
- DEFAULT_READ_TIMEOUT =
70- CONNECT_TIMEOUT =
30_000- OK_CODE =
200- KEEP_ALIVE_RESPONSE =
"c\r\n:keepalive\n\n\r\n".freeze
- ERROR_EVENT_TYPE =
'error'.freeze
Instance Method Summary collapse
- #close(status = nil) ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(config, api_key, telemetry_runtime_producer, event_parser, notification_manager_keeper, notification_processor, status_queue, read_timeout: DEFAULT_READ_TIMEOUT) ⇒ Client
constructor
A new instance of Client.
- #start(url) ⇒ Object
Constructor Details
#initialize(config, api_key, telemetry_runtime_producer, event_parser, notification_manager_keeper, notification_processor, status_queue, read_timeout: DEFAULT_READ_TIMEOUT) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/splitclient-rb/sse/event_source/client.rb', line 18 def initialize(config, api_key, telemetry_runtime_producer, event_parser, notification_manager_keeper, notification_processor, status_queue, read_timeout: DEFAULT_READ_TIMEOUT) @config = config @api_key = api_key @telemetry_runtime_producer = telemetry_runtime_producer @event_parser = event_parser @notification_manager_keeper = notification_manager_keeper @notification_processor = notification_processor @status_queue = status_queue @read_timeout = read_timeout @connected = Concurrent::AtomicBoolean.new(false) @first_event = Concurrent::AtomicBoolean.new(true) @socket = nil end |
Instance Method Details
#close(status = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/splitclient-rb/sse/event_source/client.rb', line 39 def close(status = nil) unless connected? @config.logger.debug('SSEClient already disconected.') return end @config.logger.debug("Closing SSEClient socket") @connected.make_false @socket.sync_close = true if @socket.is_a? OpenSSL::SSL::SSLSocket @socket.close @config.logger.debug("SSEClient socket state #{@socket.state}") if @socket.is_a? OpenSSL::SSL::SSLSocket push_status(status) rescue StandardError => e @config.logger.error("SSEClient close Error: #{e.inspect}") end |
#connected? ⇒ Boolean
73 74 75 |
# File 'lib/splitclient-rb/sse/event_source/client.rb', line 73 def connected? @connected.value end |
#start(url) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/splitclient-rb/sse/event_source/client.rb', line 55 def start(url) if connected? @config.logger.debug('SSEClient already running.') return true end @uri = URI(url) latch = Concurrent::CountDownLatch.new(1) connect_thread(latch) return false unless latch.wait(CONNECT_TIMEOUT) connected? rescue StandardError => e @config.logger.error("SSEClient start Error: #{e.inspect}") connected? end |