Class: Contrast::Agent::Reporting::ConnectionStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent/reporting/connection_status.rb

Overview

Keeps track of the state of connections to TeamServer.

Instance Method Summary collapse

Constructor Details

#initializeConnectionStatus

Returns a new instance of ConnectionStatus.



9
10
11
12
13
# File 'lib/contrast/agent/reporting/connection_status.rb', line 9

def initialize
  @last_success = nil
  @last_failure = nil
  @startup_messages_sent = false
end

Instance Method Details

#connected?Boolean

The last message sent was successful or not

Returns:

  • (Boolean)


26
27
28
# File 'lib/contrast/agent/reporting/connection_status.rb', line 26

def connected?
  @last_success && (@last_failure.nil? || @last_success > @last_failure)
end

#failure!Object

The TeamServer may be in some sort of error state



37
38
39
40
# File 'lib/contrast/agent/reporting/connection_status.rb', line 37

def failure!
  @startup_messages_sent = false
  @last_failure = Time.now.to_f
end

#startup_messages_sent?Boolean

Whether we have sent startup message to TeamServer. True after successfully sending startup messages to TeamServer and reset to false if we lose connection.

Returns:

  • (Boolean)


19
20
21
# File 'lib/contrast/agent/reporting/connection_status.rb', line 19

def startup_messages_sent?
  @startup_messages_sent
end

#success!Object

The current state of the TeamServer is active with a successful message sent



31
32
33
34
# File 'lib/contrast/agent/reporting/connection_status.rb', line 31

def success!
  @startup_messages_sent = true
  @last_success = Time.now.to_f
end