Class: Pantry::Communication::FileService::ReceiveFile
- Inherits:
-
Object
- Object
- Pantry::Communication::FileService::ReceiveFile
- 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
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#pipeline_size ⇒ Object
Returns the value of attribute pipeline_size.
Instance Method Summary collapse
-
#initialize(service, chunk_size: 250_000, pipeline_size: 10) ⇒ ReceiveFile
constructor
A new instance of ReceiveFile.
- #receive_file(file_size, checksum) ⇒ Object
- #receive_message(from_identity, message) ⇒ Object
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_size ⇒ Object
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_size ⇒ Object
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 (from_identity, ) if current_file = @receiving[.to] current_file.sender_uuid = from_identity else return end case .body[0] when "START" Pantry.logger.debug("[Receive File] Received START message #{.inspect}") fill_the_pipeline(current_file, ) when "CHUNK" Pantry.logger.debug("[Receive File] Received CHUNK message #{.}") process_chunk(current_file, ) end end |