Class: Sensu::Server::Socket

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/sensu/server/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_errorProc

Returns callback to be called when there is an error.

Returns:

  • (Proc)

    callback to be called when there is an error.



11
12
13
# File 'lib/sensu/server/socket.rb', line 11

def on_error
  @on_error
end

#on_successProc

Returns callback to be called after the data has been transmitted successfully.

Returns:

  • (Proc)

    callback to be called after the data has been transmitted successfully.



7
8
9
# File 'lib/sensu/server/socket.rb', line 7

def on_success
  @on_success
end

Instance Method Details

#connection_completedObject

Record the current time and the inactivity timeout value, when the socket connection is successful. These values are used to determine if the a connection was closed due to the timeout.



16
17
18
19
# File 'lib/sensu/server/socket.rb', line 16

def connection_completed
  @connected_at = Time.now.to_f
  @inactivity_timeout = comm_inactivity_timeout
end

#unbindObject

Determine if the connection and data transmission was successful and call the appropriate callback, ‘@on_success` or `@on_error`, providing it with a message. The `@connected_at` timestamp indicates that the connection was successful. If the elapsed time is greater than the inactivity timeout value, the connection was closed abruptly by the timeout timer, and the data was not transmitted.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sensu/server/socket.rb', line 28

def unbind
  if @connected_at
    elapsed_time = Time.now.to_f - @connected_at
    if elapsed_time >= @inactivity_timeout
      @on_error.call("socket inactivity timeout")
    else
      @on_success.call("wrote to socket")
    end
  else
    @on_error.call("failed to connect to socket")
  end
end