Class: Concurrent::Actor::AbstractContext
- Inherits:
-
Object
- Object
- Concurrent::Actor::AbstractContext
- Includes:
- InternalDelegations, TypeCheck
- Defined in:
- lib/concurrent/actor/context.rb
Overview
Abstract implementation of Actor context. Children has to implement #on_message and #behaviour_definition methods. There are two implementations:
-
> Basic Context of an Actor. It does not support supervision and pausing. It simply terminates on error.
-
linking
-
terminates on error
TODO describe behaviour TODO usage
-
-
> Context of an Actor for complex robust systems.
-
linking
-
supervising
-
pauses on error
TODO describe behaviour TODO usage
-
Direct Known Subclasses
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
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_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 events like ‘:terminated`, `:resumed`, `anError`.
-
#on_message(message) ⇒ Object
abstract
A result which will be used to set the IVar supplied to Reference#ask.
-
#pass ⇒ Object
if you want to pass the message to next behaviour, usually Behaviour::ErrorsOnUnknownMessage.
- #tell(message) ⇒ Object (also: #<<)
Methods included from InternalDelegations
#behaviour, #behaviour!, #children, #context, #log, #redirect, #terminate!
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)
Returns the value of attribute core.
19 20 21 |
# File 'lib/concurrent/actor/context.rb', line 19 def core @core end |
Instance Method Details
#ask(message) ⇒ Object Also known as: ask!
77 78 79 |
# File 'lib/concurrent/actor/context.rb', line 77 def ask() raise 'actor cannot ask itself' end |
#behaviour_definition ⇒ Array<Array(Behavior::Abstract, Array<Object>)>
58 59 60 |
# File 'lib/concurrent/actor/context.rb', line 58 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 ivar 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.
53 54 55 |
# File 'lib/concurrent/actor/context.rb', line 53 def dead_letter_routing parent.dead_letter_routing end |
#default_reference_class ⇒ CLass
override if different class for reference is needed
69 70 71 |
# File 'lib/concurrent/actor/context.rb', line 69 def default_reference_class Reference end |
#envelope ⇒ Envelope
Returns current envelope, accessible inside #on_message processing.
63 64 65 |
# File 'lib/concurrent/actor/context.rb', line 63 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.
35 36 37 38 39 40 |
# File 'lib/concurrent/actor/context.rb', line 35 def on_envelope(envelope) @envelope = envelope envelope. ensure @envelope = nil end |
#on_event(event) ⇒ Object
override to add custom code invocation on events like ‘:terminated`, `:resumed`, `anError`.
31 32 |
# File 'lib/concurrent/actor/context.rb', line 31 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 IVar supplied to Reference#ask.
26 27 28 |
# File 'lib/concurrent/actor/context.rb', line 26 def () raise NotImplementedError end |
#pass ⇒ Object
if you want to pass the message to next behaviour, usually Behaviour::ErrorsOnUnknownMessage
43 44 45 |
# File 'lib/concurrent/actor/context.rb', line 43 def pass core.behaviour!(Behaviour::ExecutesContext).pass envelope end |
#tell(message) ⇒ Object Also known as: <<
73 74 75 |
# File 'lib/concurrent/actor/context.rb', line 73 def tell() reference.tell end |