class Pantry::Communication::Client

The communication layer of a Pantry::Client This class manages all of the ZeroMQ sockets and underlying communication systems, handling the sending and receiving of messages.

Public Class Methods

new(listener) click to toggle source
# File lib/pantry/communication/client.rb, line 10
def initialize(listener)
  @listener = listener
  @response_wait_list = Communication::WaitList.new
end

Public Instance Methods

handle_message(message) click to toggle source

Callback from the SubscribeSocket when a message is received.

# File lib/pantry/communication/client.rb, line 45
def handle_message(message)
  if @response_wait_list.waiting_for?(message)
    @response_wait_list.received(message)
  else
    @listener.receive_message(message)
  end
end
receive_file(file_size, file_checksum) click to toggle source
# File lib/pantry/communication/client.rb, line 64
def receive_file(file_size, file_checksum)
  @file_service.receive_file(file_size, file_checksum)
end
run() click to toggle source

Start up the networking layer, opening up sockets and getting ready for communication.

# File lib/pantry/communication/client.rb, line 17
def run
  @security = Communication::Security.new_client

  @subscribe_socket = Communication::SubscribeSocket.new_link(
    Pantry.config.server_host,
    Pantry.config.pub_sub_port,
    @security
  )
  @subscribe_socket.add_listener(self)
  @subscribe_socket.filter_on(@listener.filter)
  @subscribe_socket.open

  @send_socket = Communication::SendSocket.new_link(
    Pantry.config.server_host,
    Pantry.config.receive_port,
    @security
  )
  @send_socket.open

  @file_service = Communication::FileService.new_link(
    Pantry.config.server_host,
    Pantry.config.file_service_port,
    @security
  )
  @file_service.start_client
end
send_file(file_path, receiver_uuid, file_uuid) click to toggle source
# File lib/pantry/communication/client.rb, line 68
def send_file(file_path, receiver_uuid, file_uuid)
  @file_service.send_file(file_path, receiver_uuid, file_uuid)
end
send_message(message) click to toggle source
# File lib/pantry/communication/client.rb, line 59
def send_message(message)
  message.from = @listener
  @send_socket.send_message(message)
end
send_request(message) click to toggle source
# File lib/pantry/communication/client.rb, line 53
def send_request(message)
  @response_wait_list.wait_for(message).tap do
    send_message(message)
  end
end