Class: Contrast::Api::Communication::Speedracer

Inherits:
Object
  • Object
show all
Includes:
ServiceLifecycle, Components::Interface
Defined in:
lib/contrast/api/communication/speedracer.rb

Overview

Wraps all connection data to speedracer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::Interface

included

Methods included from ServiceLifecycle

#attempt_local_service_startup, #determine_startup_options, #service_starter_thread, #spawn_service, #zombie_check

Constructor Details

#initializeSpeedracer

Returns a new instance of Speedracer.



17
18
19
20
21
22
# File 'lib/contrast/api/communication/speedracer.rb', line 17

def initialize
  @status = Contrast::Api::Communication::ConnectionStatus.new
  @socket_client = Contrast::Api::Communication::SocketClient.new
  @response_processor = Contrast::Api::Communication::ResponseProcessor.new
  @ensure_running = Mutex.new
end

Instance Attribute Details

#ensure_runningObject (readonly)

Returns the value of attribute ensure_running.



15
16
17
# File 'lib/contrast/api/communication/speedracer.rb', line 15

def ensure_running
  @ensure_running
end

#response_processorObject (readonly)

Returns the value of attribute response_processor.



15
16
17
# File 'lib/contrast/api/communication/speedracer.rb', line 15

def response_processor
  @response_processor
end

#socket_clientObject (readonly)

Returns the value of attribute socket_client.



15
16
17
# File 'lib/contrast/api/communication/speedracer.rb', line 15

def socket_client
  @socket_client
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/contrast/api/communication/speedracer.rb', line 15

def status
  @status
end

Instance Method Details

#ensure_startup!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/contrast/api/communication/speedracer.rb', line 24

def ensure_startup!
  return if status.connected?

  ensure_running.synchronize do
    if CONTRAST_SERVICE.use_bundled_service?
      logger.info('Attempting to start local service')
      unless attempt_local_service_startup
        logger.error('Failed to start local service')
        return
      end
    end
    unless status.startup_messages_sent?
      startup_responses = send_initialization_messages
      return false unless startup_responses

      startup_responses.each { |response| response_processor.process(response) }
    end
  end
end

#process_internally(event) ⇒ Object



50
51
52
53
54
# File 'lib/contrast/api/communication/speedracer.rb', line 50

def process_internally event
  send_to_speedracer(event) do |response|
    response_processor.process(response)
  end
end

#return_response(event) ⇒ Object



44
45
46
47
48
# File 'lib/contrast/api/communication/speedracer.rb', line 44

def return_response event
  send_to_speedracer(event) do |response|
    return response
  end
end