Class: Concurrent::Actor::Behaviour::Linking
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Abstract
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Actor::Behaviour::Abstract
|
Defined in: | lib/concurrent-ruby-edge/concurrent/actor/behaviour/linking.rb |
Overview
Links the actor to other actors and sends actor’s events to them, like: :terminated
, :paused
, :resumed
, errors, etc. Linked actor needs to handle those messages.
listener = AdHoc.spawn name: :listener do
lambda do ||
case
when Reference
if .ask!(:linked?)
<< :unlink
else
<< :link
end
else
puts "got event #{ .inspect} from #{envelope.sender}"
end
end
end
an_actor = AdHoc.spawn name: :an_actor, supervise: true, behaviour_definition: Behaviour.restarting_behaviour_definition do
lambda { || raise 'failed'}
end
# link the actor
listener.ask(an_actor).wait
an_actor.ask(:fail).wait
# unlink the actor
listener.ask(an_actor).wait
an_actor.ask(:fail).wait
an_actor << :terminate!
produces only two events, other events happened after unlinking
got event #<RuntimeError: failed> from #<Concurrent::Actor::Reference /an_actor (Concurrent::Actor::Utils::AdHoc)>
got event :reset from #<Concurrent::Actor::Reference /an_actor (Concurrent::Actor::Utils::AdHoc)>
Constant Summary
Concern::Logging
- Included
Class Method Summary
Instance Attribute Summary
Instance Method Summary
Abstract
- Inherited
#broadcast | broadcasts event to all behaviours and context. |
#on_envelope | override to add extra behaviour. |
#on_event | override to add extra behaviour. |
#pass, #reject_envelope |
Actor::InternalDelegations
- Included
#behaviour | see Core#behaviour |
#behaviour! | see Core#behaviour! |
#children, #context, #dead_letter_routing, | |
#log | delegates to core.log. |
#redirect, #terminate! |
Concern::Logging
- Included
#log | Logs through Concurrent.global_logger, it can be overridden by setting @logger. |
Actor::PublicDelegations
- Included
#actor_class | Alias for PublicDelegations#context_class. |
#context_class, #executor, #name, #parent, #path, | |
#ref | Alias for PublicDelegations#reference. |
#reference |
Actor::TypeCheck
- Included
Constructor Details
.new(core, subsequent, core_options) ⇒ Linking
Instance Method Details
#link(ref)
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/linking.rb', line 66
def link(ref) @linked.add(ref) true end
#on_envelope(envelope)
[ GitHub ]#on_event(public, event)
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/linking.rb', line 76
def on_event(public, event) event_name, _ = event @linked.each { |a| a << event } if public @linked.clear if event_name == :terminated super public, event end
#unlink(ref)
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/linking.rb', line 71
def unlink(ref) @linked.delete(ref) true end