Class: Concurrent::Actor::AbstractContext Abstract
- Inherits:
-
Object
- Object
- Concurrent::Actor::AbstractContext
- Includes:
- Concern::Logging, InternalDelegations, TypeCheck
- Defined in:
- lib/concurrent/actor/context.rb
Overview
implement #on_message and #behaviour_definition
New actor is defined by subclassing RestartingContext, Context and defining its abstract methods. AbstractContext can be subclassed directly to implement more specific behaviour see Root implementation.
-
> Basic Context of an Actor. It supports only linking and it simply terminates on error. Uses Behaviour.basic_behaviour_definition:
-
> Context of an Actor for robust systems. It supports supervision, linking, pauses on error. Uses Behaviour.restarting_behaviour_definition
Example of ac actor definition:
See methods of AbstractContext what else can be tweaked, e.g #default_reference_class
Direct Known Subclasses
Instance Attribute Summary collapse
- #core ⇒ Object readonly
Class Method Summary collapse
-
.spawn(name_or_opts, *args, &block) ⇒ Object
Behaves as spawn but :class is auto-inserted based on receiver so it can be omitted.
-
.spawn!(name_or_opts, *args, &block) ⇒ Object
behaves as spawn! but :class is auto-inserted based on receiver so it can be omitted.
Instance Method Summary collapse
- #ask(message) ⇒ Object (also: #ask!)
- #behaviour_definition ⇒ Array<Array(Behavior::Abstract, Array<Object>)>
-
#dead_letter_routing ⇒ Reference
Defines an actor responsible for dead letters.
-
#default_executor ⇒ Executor
override to se different default executor, e.g.
-
#default_reference_class ⇒ CLass
override if different class for reference is needed.
-
#envelope ⇒ Envelope
Current envelope, accessible inside #on_message processing.
- #on_envelope(envelope) ⇒ Object private
-
#on_event(event) ⇒ Object
override to add custom code invocation on internal events like ‘:terminated`, `:resumed`, `anError`.
-
#on_message(message) ⇒ Object
abstract
A result which will be used to set the Future supplied to Reference#ask.
-
#pass ⇒ Object
if you want to pass the message to next behaviour, usually Behaviour::ErrorsOnUnknownMessage.
-
#tell(message) ⇒ Object
(also: #<<)
tell self a message.
Methods included from InternalDelegations
#behaviour, #behaviour!, #children, #context, #log, #redirect, #terminate!, #terminated?
Methods included from PublicDelegations
#context_class, #executor, #name, #parent, #path, #reference
Methods included from TypeCheck
#Child!, #Child?, #Match!, #Match?, #Type!, #Type?
Instance Attribute Details
#core ⇒ Object (readonly)
29 30 31 |
# File 'lib/concurrent/actor/context.rb', line 29 def core @core end |
Class Method Details
.spawn(name_or_opts, *args, &block) ⇒ Object
Behaves as Concurrent::Actor.spawn but :class is auto-inserted based on receiver so it can be omitted.
116 117 118 |
# File 'lib/concurrent/actor/context.rb', line 116 def self.spawn(name_or_opts, *args, &block) Actor.spawn (name_or_opts, *args), &block end |
.spawn!(name_or_opts, *args, &block) ⇒ Object
behaves as Concurrent::Actor.spawn! but :class is auto-inserted based on receiver so it can be omitted.
121 122 123 |
# File 'lib/concurrent/actor/context.rb', line 121 def self.spawn!(name_or_opts, *args, &block) Actor.spawn! (name_or_opts, *args), &block end |
Instance Method Details
#ask(message) ⇒ Object Also known as: ask!
97 98 99 |
# File 'lib/concurrent/actor/context.rb', line 97 def ask() raise 'actor cannot ask itself' end |
#behaviour_definition ⇒ Array<Array(Behavior::Abstract, Array<Object>)>
71 72 73 |
# File 'lib/concurrent/actor/context.rb', line 71 def behaviour_definition raise NotImplementedError end |
#dead_letter_routing ⇒ Reference
Defines an actor responsible for dead letters. Any rejected message send with Reference#tell is sent there, a message with future is considered already monitored for failures. Default behaviour is to use #dead_letter_routing of the parent, so if no #dead_letter_routing method is overridden in parent-chain the message ends up in ‘Actor.root.dead_letter_routing` agent which will log warning.
66 67 68 |
# File 'lib/concurrent/actor/context.rb', line 66 def dead_letter_routing parent.dead_letter_routing end |
#default_executor ⇒ Executor
override to se different default executor, e.g. to change it to global_operation_pool
88 89 90 |
# File 'lib/concurrent/actor/context.rb', line 88 def default_executor Concurrent.global_io_executor end |
#default_reference_class ⇒ CLass
override if different class for reference is needed
82 83 84 |
# File 'lib/concurrent/actor/context.rb', line 82 def default_reference_class Reference end |
#envelope ⇒ Envelope
Returns current envelope, accessible inside #on_message processing.
76 77 78 |
# File 'lib/concurrent/actor/context.rb', line 76 def envelope @envelope or raise 'envelope not set' end |
#on_envelope(envelope) ⇒ Object
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.
45 46 47 48 49 50 |
# File 'lib/concurrent/actor/context.rb', line 45 def on_envelope(envelope) @envelope = envelope envelope. ensure @envelope = nil end |
#on_event(event) ⇒ Object
override to add custom code invocation on internal events like ‘:terminated`, `:resumed`, `anError`.
41 42 |
# File 'lib/concurrent/actor/context.rb', line 41 def on_event(event) end |
#on_message(message) ⇒ Object
override to define Actor’s behaviour
self should not be returned (or sent to other actors), PublicDelegations#reference should be used instead
Returns a result which will be used to set the Future supplied to Reference#ask.
36 37 38 |
# File 'lib/concurrent/actor/context.rb', line 36 def () raise NotImplementedError end |
#pass ⇒ Object
if you want to pass the message to next behaviour, usually Behaviour::ErrorsOnUnknownMessage
54 55 56 |
# File 'lib/concurrent/actor/context.rb', line 54 def pass core.behaviour!(Behaviour::ExecutesContext).pass envelope end |
#tell(message) ⇒ Object Also known as: <<
tell self a message
93 94 95 |
# File 'lib/concurrent/actor/context.rb', line 93 def tell() reference.tell end |