Class: Pantry::Communication::FileService::ReceiveFile

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

Overview

Chunk file receiving tool that implements the protocol as described here

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

In short, this tool requests chunks in a pipeline flow, writing out the received chunks to the file system at the given path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, chunk_size: 250_000, pipeline_size: 10) ⇒ ReceiveFile

Returns a new instance of ReceiveFile.



14
15
16
17
18
19
20
21
# File 'lib/pantry/communication/file_service/receive_file.rb', line 14

def initialize(service, chunk_size: 250_000, pipeline_size: 10)
  @service = service

  @chunk_size    = chunk_size
  @pipeline_size = pipeline_size

  @receiving = {}
end

Instance Attribute Details

#chunk_sizeObject

Returns the value of attribute chunk_size.



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

def chunk_size
  @chunk_size
end

#pipeline_sizeObject

Returns the value of attribute pipeline_size.



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

def pipeline_size
  @pipeline_size
end

Instance Method Details

#receive_file(file_size, checksum) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/pantry/communication/file_service/receive_file.rb', line 23

def receive_file(file_size, checksum)
  FileService::ReceivingFile.new(
    file_size, checksum, chunk_size, pipeline_size
  ).tap do |info|
    @receiving[info.file_uuid] = info
  end
end

#receive_message(from_identity, message) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pantry/communication/file_service/receive_file.rb', line 31

def receive_message(from_identity, message)
  if current_file = @receiving[message.to]
    current_file.sender_uuid = from_identity
  else
    return
  end

  case message.body[0]
  when "START"
    Pantry.logger.debug("[Receive File] Received START message #{message.inspect}")
    fill_the_pipeline(current_file, message)
  when "CHUNK"
    Pantry.logger.debug("[Receive File] Received CHUNK message #{message.}")
    process_chunk(current_file, message)
  end
end