Class: Celluloid::Cell
- Inherits:
-
Object
- Object
- Celluloid::Cell
- Defined in:
- lib/celluloid/cell.rb
Overview
Wrap the given subject with an Cell
Defined Under Namespace
Classes: ExitHandler
Instance Attribute Summary collapse
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(subject, options, actor_options) ⇒ Cell
constructor
A new instance of Cell.
- #invoke(call) ⇒ Object
-
#shutdown ⇒ Object
Run the user-defined finalizer, if one is set.
- #task(task_type, method_name = nil, subject = nil, meta = nil, &_block) ⇒ Object
Constructor Details
#initialize(subject, options, actor_options) ⇒ Cell
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/celluloid/cell.rb', line 20 def initialize(subject, , ) @actor = Actor.new(self, ) @subject = subject @receiver_block_executions = [:receiver_block_executions] @exclusive_methods = [:exclusive_methods] @finalizer = [:finalizer] @subject.instance_variable_set(OWNER_IVAR, @actor) if exit_handler_name = [:exit_handler_name] @actor.exit_handler = ExitHandler.new(self, @subject, exit_handler_name) end @actor.handle(Call) do || invoke() end @actor.handle(Call::Block) do || task(:invoke_block) { .dispatch } end @actor.handle(Internals::Response::Block, Internals::Response) do || .dispatch end @actor.start @proxy = ([:proxy_class] || Proxy::Cell).new(@actor.mailbox, @actor.proxy, @subject.class.to_s) end |
Instance Attribute Details
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
46 47 48 |
# File 'lib/celluloid/cell.rb', line 46 def proxy @proxy end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
46 47 48 |
# File 'lib/celluloid/cell.rb', line 46 def subject @subject end |
Class Method Details
.dispatch ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/celluloid/cell.rb', line 48 def self.dispatch proc do |subject| subject[:call].dispatch(subject[:subject]) subject[:call] = nil subject[:subject] = nil end end |
.shutdown ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/celluloid/cell.rb', line 81 def self.shutdown proc do |subject| begin subject[:subject].__send__(subject[:call]) rescue => ex Internals::Logger.crash("#{subject[:subject].class} finalizer crashed!", ex) end subject[:call] = nil subject[:subject] = nil end end |
Instance Method Details
#invoke(call) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/celluloid/cell.rb', line 56 def invoke(call) meth = call.method meth = call.arguments.first if meth == :__send__ if @receiver_block_executions && meth if @receiver_block_executions.include?(meth.to_sym) call.execute_block_on_receiver end end task(:call, meth, {call: call, subject: @subject}, dangerous_suspend: meth == :initialize, &Cell.dispatch) end |
#shutdown ⇒ Object
Run the user-defined finalizer, if one is set
94 95 96 97 98 99 |
# File 'lib/celluloid/cell.rb', line 94 def shutdown return unless @finalizer && @subject.respond_to?(@finalizer, true) task(:finalizer, @finalizer, {call: @finalizer, subject: @subject}, dangerous_suspend: true, &Cell.shutdown) end |
#task(task_type, method_name = nil, subject = nil, meta = nil, &_block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/celluloid/cell.rb', line 69 def task(task_type, method_name = nil, subject = nil, = nil, &_block) ||= {} .merge!(method_name: method_name) @actor.task(task_type, ) do if @exclusive_methods && method_name && @exclusive_methods.include?(method_name.to_sym) Celluloid.exclusive { yield subject } else yield subject end end end |