Class: Celluloid::Call::Sync
- Inherits:
-
Celluloid::Call
- Object
- Celluloid::Call
- Celluloid::Call::Sync
- Defined in:
- lib/celluloid/call/sync.rb
Overview
Synchronous calls wait for a response
Instance Attribute Summary collapse
-
#chain_id ⇒ Object
readonly
Returns the value of attribute chain_id.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Attributes inherited from Celluloid::Call
Instance Method Summary collapse
- #cleanup ⇒ Object
- #dispatch(obj) ⇒ Object
-
#initialize(sender, method, arguments = [], block = nil, task = , chain_id = Internals::CallChain.current_id) ⇒ Sync
constructor
A new instance of Sync.
- #respond(message) ⇒ Object
- #response ⇒ Object
- #value ⇒ Object
- #wait ⇒ Object
Methods inherited from Celluloid::Call
#check, #execute_block_on_receiver
Constructor Details
#initialize(sender, method, arguments = [], block = nil, task = , chain_id = Internals::CallChain.current_id) ⇒ Sync
Returns a new instance of Sync.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/celluloid/call/sync.rb', line 7 def initialize( sender, method, arguments = [], block = nil, task = Thread.current[:celluloid_task], chain_id = Internals::CallChain.current_id ) super(method, arguments, block) @sender = sender @task = task @chain_id = chain_id || Celluloid.uuid end |
Instance Attribute Details
#chain_id ⇒ Object (readonly)
Returns the value of attribute chain_id.
5 6 7 |
# File 'lib/celluloid/call/sync.rb', line 5 def chain_id @chain_id end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender.
5 6 7 |
# File 'lib/celluloid/call/sync.rb', line 5 def sender @sender end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
5 6 7 |
# File 'lib/celluloid/call/sync.rb', line 5 def task @task end |
Instance Method Details
#cleanup ⇒ Object
38 39 40 41 |
# File 'lib/celluloid/call/sync.rb', line 38 def cleanup exception = DeadActorError.new("attempted to call a dead actor: #{method}") respond Internals::Response::Error.new(self, exception) end |
#dispatch(obj) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/celluloid/call/sync.rb', line 21 def dispatch(obj) Internals::CallChain.current_id = @chain_id result = super(obj) respond Internals::Response::Success.new(self, result) rescue ::Exception => ex # Exceptions that occur during synchronous calls are reraised in the # context of the sender respond Internals::Response::Error.new(self, ex) # Aborting indicates a protocol error on the part of the sender # It should crash the sender, but the exception isn't reraised # Otherwise, it's a bug in this actor and should be reraised raise unless ex.is_a?(AbortError) ensure Internals::CallChain.current_id = nil end |
#respond(message) ⇒ Object
43 44 45 |
# File 'lib/celluloid/call/sync.rb', line 43 def respond() @sender << end |
#response ⇒ Object
47 48 49 |
# File 'lib/celluloid/call/sync.rb', line 47 def response Celluloid.suspend(:callwait, self) end |
#value ⇒ Object
51 52 53 |
# File 'lib/celluloid/call/sync.rb', line 51 def value response.value end |
#wait ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/celluloid/call/sync.rb', line 55 def wait loop do = Celluloid.mailbox.receive do |msg| msg.respond_to?(:call) && msg.call == self end if .is_a?(SystemEvent) Thread.current[:celluloid_actor].handle_system_event() else # FIXME: add check for receiver block execution if .respond_to?(:value) # FIXME: disable block execution if on :sender and (exclusive or outside of task) # probably now in Call return else .dispatch end end end end |