Class: BackgroundQueue::ClientLib::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/client_lib/connection.rb

Overview

A connection to a backend queue server Handles sending the command to the server and receiving the reply For now connections are not pooled/reused

Instance Method Summary collapse

Constructor Details

#initialize(client, server) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
# File 'lib/background_queue/client_lib/connection.rb', line 8

def initialize(client, server)
  @client = client
  @server = server
  @socket = nil
end

Instance Method Details

#send_command(command) ⇒ Object

send a command to the server



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/background_queue/client_lib/connection.rb', line 15

def send_command(command)
  check_connected
  send_with_header(command.to_buf)
  response = receive_with_header
  BackgroundQueue::Command.from_buf(response)
ensure
  begin
    @socket.close unless @socket.nil?
  rescue Exception=>e
    #dont care...
  end
  @socket = nil
end