Class: Rapid::Baps::Connection

Inherits:
EventMachine::Connection
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ury_rapid/services/connection.rb

Overview

An object that handles the connection from Rapid to a server

Instance Method Summary collapse

Constructor Details

#initialize(in_reader, request_queue, logger) ⇒ Connection

Initialises the Connection

Examples:

Initialises the Connection.

conn = Connection.new(parser, request_queue)

Parameters:

  • in_reader (Reader)

    An object that interprets and acts upon raw responses from the server.

  • request_queue (EventMachine::Queue)

    A queue that holds raw requests to the server.

  • logger (Proc)

    jhe logger, for logging errors.


21
22
23
24
25
26
# File 'lib/ury_rapid/services/connection.rb', line 21

def initialize(in_reader, request_queue, logger)
  @reader         = in_reader
  @request_queue  = request_queue
  @logger         = logger
  @closing        = false
end

Instance Method Details

#connection_completedvoid

This method returns an undefined value.

Handles a successful connection completion

Examples:

Tell the Connection it's finished.

conn.connection_completed

44
45
46
# File 'lib/ury_rapid/services/connection.rb', line 44

def connection_completed
  @closing = true
end

#post_initObject


28
29
30
31
# File 'lib/ury_rapid/services/connection.rb', line 28

def post_init
  # Initiate the request queue pumping loop.
  pop_queue
end

#unbindvoid

TODO:

Make Rapid able to handle this instead of just dying

This method returns an undefined value.

Handles a connection loss

Examples:

Tell the Connection it's died.

conn.unbind

58
59
60
61
62
# File 'lib/ury_rapid/services/connection.rb', line 58

def unbind
  return if @closing
  @logger.call(:fatal, 'Lost connection, dying.')
  EventMachine.stop
end