Class: Concurrent::Actor::Behaviour::Linking

Inherits:
Abstract
  • Object
show all
Defined in:
lib/concurrent/actor/behaviour/linking.rb

Overview

Links the actor to other actors and sends actor’s events to them, like: ‘:terminated`, `:paused`, errors, etc TODO example

Instance Attribute Summary

Attributes inherited from Abstract

#core, #subsequent

Instance Method Summary collapse

Methods inherited from Abstract

#broadcast, #pass, #reject_envelope

Methods included from InternalDelegations

#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!

Methods included from PublicDelegations

#context_class, #executor, #name, #parent, #path, #reference

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?

Constructor Details

#initialize(core, subsequent) ⇒ Linking

Returns a new instance of Linking.



9
10
11
12
# File 'lib/concurrent/actor/behaviour/linking.rb', line 9

def initialize(core, subsequent)
  super core, subsequent
  @linked = Set.new
end

Instance Method Details



27
28
29
30
# File 'lib/concurrent/actor/behaviour/linking.rb', line 27

def link(ref)
  @linked.add(ref)
  true
end

#on_envelope(envelope) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/concurrent/actor/behaviour/linking.rb', line 14

def on_envelope(envelope)
  case envelope.message
  when :link
    link envelope.sender
  when :unlink
    unlink envelope.sender
  when :linked?
    @linked.include? envelope.sender
  else
    pass envelope
  end
end

#on_event(event) ⇒ Object



37
38
39
40
41
# File 'lib/concurrent/actor/behaviour/linking.rb', line 37

def on_event(event)
  @linked.each { |a| a << event }
  @linked.clear if event == :terminated
  super event
end


32
33
34
35
# File 'lib/concurrent/actor/behaviour/linking.rb', line 32

def unlink(ref)
  @linked.delete(ref)
  true
end