Class: Pantry::Communication::FileService::SendFile

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/pantry/communication/file_service/send_file.rb

Overview

Chunk file sending tool that implements the protocol as described here

http://zguide.zeromq.org/page:all#Transferring-Files

As this actor receives chunk requests from the Receiver, it reads that chunk from the given file and sends it along.

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ SendFile

Returns a new instance of SendFile.



12
13
14
15
# File 'lib/pantry/communication/file_service/send_file.rb', line 12

def initialize(service)
  @service = service
  @sending = {}
end

Instance Method Details

#receive_message(from_identity, message) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pantry/communication/file_service/send_file.rb', line 26

def receive_message(from_identity, message)
  current_file_info = @sending[message.to]
  return unless current_file_info

  case message.body[0]
  when "FETCH"
    Pantry.logger.debug("[Send File] FETCH requested #{message.inspect}")
    fetch_and_return_chunk(current_file_info, message)
  when "FINISH"
    Pantry.logger.debug("[Send File] FINISHED cleaning up for #{message.inspect}")
    clean_up(current_file_info, message)
  when "ERROR"
    Pantry.logger.debug("[Send File] ERROR #{message.inspect}")
  end
end

#send_file(file_path, receiver_uuid, file_uuid) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/pantry/communication/file_service/send_file.rb', line 17

def send_file(file_path, receiver_uuid, file_uuid)
  sender_info = FileService::SendingFile.new(file_path, receiver_uuid, file_uuid)

  @sending[file_uuid] = sender_info
  send_message(sender_info, "START")

  sender_info
end