Class: Concurrent::Actor::AbstractContext

Inherits:
Object
  • Object
show all
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:

  • Context

    > 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

  • RestartingContext.

    > Context of an Actor for complex robust systems.

    • linking

    • supervising

    • pauses on error

    TODO describe behaviour TODO usage

Direct Known Subclasses

Context, RestartingContext, Root

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#coreObject (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(message)
  raise 'actor cannot ask itself'
end

#behaviour_definitionArray<Array(Behavior::Abstract, Array<Object>)>

Returns:

  • (Array<Array(Behavior::Abstract, Array<Object>)>)

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/concurrent/actor/context.rb', line 58

def behaviour_definition
  raise NotImplementedError
end

#dead_letter_routingReference

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.

Returns:



53
54
55
# File 'lib/concurrent/actor/context.rb', line 53

def dead_letter_routing
  parent.dead_letter_routing
end

#default_reference_classCLass

override if different class for reference is needed

Returns:



69
70
71
# File 'lib/concurrent/actor/context.rb', line 69

def default_reference_class
  Reference
end

#envelopeEnvelope

Returns current envelope, accessible inside #on_message processing.

Returns:

  • (Envelope)

    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
  on_message envelope.message
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

This method is abstract.

override to define Actor’s behaviour

Note:

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.

Parameters:

  • message (Object)

Returns:

  • (Object)

    a result which will be used to set the IVar supplied to Reference#ask

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/concurrent/actor/context.rb', line 26

def on_message(message)
  raise NotImplementedError
end

#passObject

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(message)
  reference.tell message
end