Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
node: refactoring of message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Jan 8, 2015
1 parent db9590a commit e4b9bb0
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions lib/dcell/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,42 @@ def socket
@socket
end

def push_request(request)
send_message request
save_request request
response = receive(@heartbeat_timeout*2) do |msg|
msg.respond_to?(:request_id) && msg.request_id == request.id
end
delete_request request
response
end

def dead_actor
raise ::Celluloid::DeadActorError.new
end

def handle_response(request, response)
unless response
dead_actor if request.kind_of? Message::Relay
return false
end
return false if response.is_a? RetryResponse
dead_actor if response.is_a? DeadActorResponse
if response.is_a? ErrorResponse
klass = Utils::full_const_get response.value[:class]
msg = response.value[:msg]
raise klass.new msg
end
true
end

def send_request(request)
# FIXME: need a robust way to retry the lost requests
loop do
send_message request
save_request request
response = receive(@heartbeat_timeout*2) do |msg|
msg.respond_to?(:request_id) && msg.request_id == request.id
end
delete_request request

raise ::Celluloid::DeadActorError.new unless response # FIXME: need a robust way to retry the lost requests
next if response.is_a? RetryResponse
raise ::Celluloid::DeadActorError.new if response.is_a? DeadActorResponse
if response.is_a? ErrorResponse
klass = Utils::full_const_get response.value[:class]
msg = response.value[:msg]
raise klass.new msg
response = push_request request
if handle_response request, response
return response.value
end
return response.value
end
end

Expand Down

0 comments on commit e4b9bb0

Please sign in to comment.