Class: Concurrent::Actor::Core
- Inherits:
-
Synchronization::LockableObject
- Object
- Synchronization::LockableObject
- Concurrent::Actor::Core
- Includes:
- TypeCheck
- Defined in:
- lib/concurrent/actor/core.rb
Overview
Instance Attribute Summary (collapse)
-
- (Context) actor_class
readonly
A subclass of AbstractContext representing Actor's behaviour.
- - (undocumented) behaviour_definition readonly
- - (undocumented) context readonly
- - (undocumented) context_class readonly
-
- (Executor) executor
readonly
Executor which is used to process messages.
-
- (String) name
readonly
The name of actor instance, it should be uniq (not enforced).
-
- (String) path
readonly
Path of this actor.
-
- (Reference) reference
readonly
Reference to this actor which can be safely passed around.
Instance Method Summary (collapse)
- - (undocumented) add_child(child) private
- - (undocumented) allocate_context private
-
- (Behaviour::Abstract, nil) behaviour(behaviour_class)
Based on behaviour_class.
-
- (Behaviour::Abstract) behaviour!(behaviour_class)
Based on behaviour_class.
- - (undocumented) broadcast(public, event)
- - (undocumented) build_context private
- - (undocumented) Child!(value, *types) included from TypeCheck
- - (Boolean) Child?(value, *types) included from TypeCheck
-
- (Array<Reference>) children
Of children actors.
- - (undocumented) dead_letter_routing
-
- (undocumented) guard!
ensures that we are inside of the executor.
-
- (Core) initialize(opts = {}, &block)
constructor
A new instance of Core.
- - (undocumented) log(level, message = nil, &block)
- - (undocumented) Match!(value, *types) included from TypeCheck
- - (Boolean) Match?(value, *types) included from TypeCheck
-
- (undocumented) on_envelope(envelope)
is executed by Reference scheduling processing of new messages can be called from other alternative Reference implementations.
-
- (Reference, nil) parent
A parent Actor.
- - (undocumented) process_envelope(envelope) private
- - (undocumented) remove_child(child) private
-
- (undocumented) schedule_execution
Schedules blocks to be executed on executor sequentially, sets Actress.current.
- - (undocumented) Type!(value, *types) included from TypeCheck
- - (Boolean) Type?(value, *types) included from TypeCheck
Constructor Details
- (Core) initialize(opts = {}, &block)
Returns a new instance of Core
50 51 52 53 |
# File 'lib/concurrent/actor/core.rb', line 50 def initialize(opts = {}, &block) super(&nil) synchronize { ns_initialize(opts, &block) } end |
Instance Attribute Details
- (Context) actor_class (readonly)
A subclass of AbstractContext representing Actor's behaviour.
35 |
# File 'lib/concurrent/actor/core.rb', line 35 attr_reader :reference, :name, :path, :executor, :context_class, :context, :behaviour_definition |
- (undocumented) behaviour_definition (readonly)
35 36 37 |
# File 'lib/concurrent/actor/core.rb', line 35 def behaviour_definition @behaviour_definition end |
- (undocumented) context (readonly)
35 36 37 |
# File 'lib/concurrent/actor/core.rb', line 35 def context @context end |
- (undocumented) context_class (readonly)
35 36 37 |
# File 'lib/concurrent/actor/core.rb', line 35 def context_class @context_class end |
- (Executor) executor (readonly)
Executor which is used to process messages.
35 |
# File 'lib/concurrent/actor/core.rb', line 35 attr_reader :reference, :name, :path, :executor, :context_class, :context, :behaviour_definition |
- (String) name (readonly)
The name of actor instance, it should be uniq (not enforced). Allows easier orientation between actor instances.
35 |
# File 'lib/concurrent/actor/core.rb', line 35 attr_reader :reference, :name, :path, :executor, :context_class, :context, :behaviour_definition |
- (String) path (readonly)
Path of this actor. It is used for easier orientation and logging.
Path is constructed recursively with: parent.path + self.name
up to a Concurrent::Actor.root,
e.g. /an_actor/its_child
.
35 |
# File 'lib/concurrent/actor/core.rb', line 35 attr_reader :reference, :name, :path, :executor, :context_class, :context, :behaviour_definition |
- (Reference) reference (readonly)
Reference to this actor which can be safely passed around.
35 36 37 |
# File 'lib/concurrent/actor/core.rb', line 35 def reference @reference end |
Instance Method Details
- (undocumented) add_child(child)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 77 78 79 |
# File 'lib/concurrent/actor/core.rb', line 74 def add_child(child) guard! Type! child, Reference @children.add child nil end |
- (undocumented) allocate_context
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
149 150 151 |
# File 'lib/concurrent/actor/core.rb', line 149 def allocate_context @context = @context_class.allocate end |
- (Behaviour::Abstract, nil) behaviour(behaviour_class)
Returns based on behaviour_class
137 138 139 |
# File 'lib/concurrent/actor/core.rb', line 137 def behaviour(behaviour_class) @behaviours[behaviour_class] end |
- (Behaviour::Abstract) behaviour!(behaviour_class)
Returns based on behaviour_class
144 145 146 |
# File 'lib/concurrent/actor/core.rb', line 144 def behaviour!(behaviour_class) @behaviours.fetch behaviour_class end |
- (undocumented) broadcast(public, event)
130 131 132 133 |
# File 'lib/concurrent/actor/core.rb', line 130 def broadcast(public, event) log(DEBUG) { "event: #{event.inspect} (#{public ? 'public' : 'private'})" } @first_behaviour.on_event(public, event) end |
- (undocumented) build_context
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
154 155 156 157 |
# File 'lib/concurrent/actor/core.rb', line 154 def build_context @context.send :initialize_core, self @context.send :initialize, *@args, &@block end |
- (undocumented) Child!(value, *types) Originally defined in module TypeCheck
- (Boolean) Child?(value, *types) Originally defined in module TypeCheck
- (Array<Reference>) children
Returns of children actors
68 69 70 71 |
# File 'lib/concurrent/actor/core.rb', line 68 def children guard! @children.to_a end |
- (undocumented) dead_letter_routing
63 64 65 |
# File 'lib/concurrent/actor/core.rb', line 63 def dead_letter_routing @context.dead_letter_routing end |
- (undocumented) guard!
ensures that we are inside of the executor
101 102 103 104 105 |
# File 'lib/concurrent/actor/core.rb', line 101 def guard! unless Actor.current == reference raise "can be called only inside actor #{reference} but was #{Actor.current}" end end |
- (undocumented) log(level, message = nil, &block)
107 108 109 |
# File 'lib/concurrent/actor/core.rb', line 107 def log(level, = nil, &block) super level, @path, , &block end |
- (undocumented) Match!(value, *types) Originally defined in module TypeCheck
- (Boolean) Match?(value, *types) Originally defined in module TypeCheck
- (undocumented) on_envelope(envelope)
is executed by Reference scheduling processing of new messages can be called from other alternative Reference implementations
92 93 94 95 96 97 98 |
# File 'lib/concurrent/actor/core.rb', line 92 def on_envelope(envelope) schedule_execution do log(DEBUG) { "was #{envelope.future ? 'asked' : 'told'} #{envelope..inspect} by #{envelope.sender}" } process_envelope envelope end nil end |
- (Reference, nil) parent
A parent Actor. When actor is spawned the Concurrent::Actor.current becomes its parent. When actor is spawned from a thread outside of an actor (Concurrent::Actor.current is nil) Concurrent::Actor.root is assigned.
58 59 60 |
# File 'lib/concurrent/actor/core.rb', line 58 def parent @parent_core && @parent_core.reference end |
- (undocumented) process_envelope(envelope)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
160 161 162 |
# File 'lib/concurrent/actor/core.rb', line 160 def process_envelope(envelope) @first_behaviour.on_envelope envelope end |
- (undocumented) remove_child(child)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 |
# File 'lib/concurrent/actor/core.rb', line 82 def remove_child(child) guard! Type! child, Reference @children.delete child nil end |
- (undocumented) schedule_execution
Schedules blocks to be executed on executor sequentially, sets Actress.current
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/concurrent/actor/core.rb', line 113 def schedule_execution @serialized_execution.post(@executor) do synchronize do begin Thread.current[:__current_actor__] = reference yield rescue => e log FATAL, e ensure Thread.current[:__current_actor__] = nil end end end nil end |