Class: Celluloid::Call
- Inherits:
-
Object
- Object
- Celluloid::Call
- Defined in:
- lib/celluloid/calls.rb,
lib/celluloid/call/sync.rb,
lib/celluloid/call/async.rb,
lib/celluloid/call/block.rb
Overview
Calls represent requests to an actor
Defined Under Namespace
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #check(obj) ⇒ Object
- #dispatch(obj) ⇒ Object
- #execute_block_on_receiver ⇒ Object
-
#initialize(method, arguments = [], block = nil) ⇒ Call
constructor
A new instance of Call.
Constructor Details
#initialize(method, arguments = [], block = nil) ⇒ Call
Returns a new instance of Call.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/celluloid/calls.rb', line 6 def initialize(method, arguments = [], block = nil) @retry = 0 @method = method @arguments = arguments if block if Celluloid.exclusive? # FIXME: nicer exception fail "Cannot execute blocks on sender in exclusive mode" end @block = Proxy::Block.new(Celluloid.mailbox, self, block) else @block = nil end end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/celluloid/calls.rb', line 4 def arguments @arguments end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/celluloid/calls.rb', line 4 def block @block end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/celluloid/calls.rb', line 4 def method @method end |
Instance Method Details
#check(obj) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/celluloid/calls.rb', line 37 def check(obj) # NOTE: don't use respond_to? here begin meth = obj.method(@method) rescue NameError raise NoMethodError, "undefined method `#{@method}' for #<#{obj.class}:0x#{obj.object_id.to_s(16)}>" end arity = meth.arity if arity >= 0 fail ArgumentError, "wrong number of arguments (#{@arguments.size} for #{arity})" if @arguments.size != arity elsif arity < -1 mandatory_args = -arity - 1 fail ArgumentError, "wrong number of arguments (#{@arguments.size} for #{mandatory_args}+)" if arguments.size < mandatory_args end rescue => ex raise AbortError.new(ex) end |
#dispatch(obj) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/celluloid/calls.rb', line 25 def dispatch(obj) check(obj) _b = @block && @block.to_proc obj.public_send(@method, *@arguments, &_b) # rescue Celluloid::TaskTimeout => ex # raise ex unless ( @retry += 1 ) <= RETRY_CALL_LIMIT # puts "retrying" # Internals::Logger.warn("TaskTimeout at Call dispatch. Retrying in #{RETRY_CALL_WAIT} seconds. ( Attempt #{@retry} of #{RETRY_CALL_LIMIT} )") # sleep RETRY_CALL_WAIT # retry end |
#execute_block_on_receiver ⇒ Object
21 22 23 |
# File 'lib/celluloid/calls.rb', line 21 def execute_block_on_receiver @block && @block.execution = :receiver end |