Method: ContentServer::FileCopyClient#handle

Defined in:
lib/content_server/queue_copy.rb

#handle(message) ⇒ Object

This is a function which receives the messages (file or ack) and return answer in case of ack. Note that it is being executed from the class thread only!



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/content_server/queue_copy.rb', line 287

def handle(message)
  message_type, message_content = message
  Log.debug1("backup copy message: Type %s. message: %s", message_type, message_content)
  if message_type == :SEND_COPY_MESSAGE
    bytes_written = @tcp_client.send_obj([:COPY_MESSAGE, message_content])
    Log.debug2("Sending copy message succeeded? bytes_written: %s.", bytes_written)
  elsif message_type == :COPY_CHUNK
    if @file_receiver.receive_chunk(*message_content)
      file_checksum, offset, file_size, content, content_checksum = message_content
      @tcp_client.send_obj([:COPY_CHUNK_FROM_REMOTE, file_checksum])
    else
      file_checksum, offset, file_size, content, content_checksum = message_content
      Log.error("receive_chunk failed for chunk checksum:#{content_checksum}")
    end
  elsif message_type == :ACK_MESSAGE
    checksum, timestamp = message_content
    # check if checksum exists in final destination
    dest_path = FileReceiver.destination_filename(Params['backup_destination_folder'][0]['path'], checksum)
    need_to_copy = !File.exists?(dest_path)
    Log.debug1("Returning ack for content:'%s' timestamp:'%s' Ack:'%s'", checksum, timestamp, need_to_copy)
    @tcp_client.send_obj([:ACK_MESSAGE, [timestamp,
                                         need_to_copy,
                                         checksum]])
  elsif message_type == :ABORT_COPY
    @tcp_client.send_obj([:ABORT_COPY, message_content])
  elsif message_type == :RESET_RESUME_COPY
    @tcp_client.send_obj([:RESET_RESUME_COPY, message_content])
  else
    Log.error("Unexpected message type: #{message_type}")
  end
end