Skip to content

Commit

Permalink
make async messages to remote nodes really async(do not wait message …
Browse files Browse the repository at this point in the history
…for the result nor confirmation on request delivery)
  • Loading branch information
niamster committed Feb 15, 2015
1 parent c2498a6 commit 3c5babc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/dcell/actor_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def initialize(lnode, actor, methods)
raise e
end
end
self.class.send(:define_method, "____async_#{meth}") do |*args|
begin
______async_method_missing meth.to_sym, *args
rescue AbortError => e
raise e
end
end
end
end

Expand All @@ -30,5 +37,14 @@ def ______method_missing(meth, *args, &block)
abort Celluloid::DeadActorError.new
end
end

def ______async_method_missing(meth, *args)
message = {:actor => @actor, :meth => meth, :args => args, :async => true}
begin
@lnode.async_relay message
rescue Celluloid::Task::TerminatedError
abort Celluloid::DeadActorError.new
end
end
end
end
10 changes: 10 additions & 0 deletions lib/dcell/celluloid_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def supervise_as(name, *args, &block)
end
end

class AsyncProxy
alias_method :____method_missing, :method_missing
def method_missing(meth, *args, &block)
if @klass == "DCell::ActorProxy"
meth = "____async_#{meth}".to_sym
end
____method_missing meth, *args, &block
end
end

class CellProxy
alias_method :____async, :async
def async(meth = nil, *args, &block)
Expand Down
4 changes: 4 additions & 0 deletions lib/dcell/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def __dispatch(actor)

def dispatch
actor = DCell.get_local_actor @message[:actor].to_sym
if @message[:async]
Celluloid::Actor::async actor.mailbox, @message[:meth], *@message[:args]
return
end
if actor
rsp = __dispatch actor
else
Expand Down
6 changes: 6 additions & 0 deletions lib/dcell/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def relay(message)
send_request request
end

# Relay async message to remote actor
def async_relay(message)
request = Message::Relay.new(Thread.mailbox, message)
send_message request
end

# Send a message to another DCell node
def send_message(message)
begin
Expand Down

0 comments on commit 3c5babc

Please sign in to comment.