Class: Concurrent::Actor::Behaviour::Abstract

Inherits:
Object
  • Object
show all
Includes:
Concern::Logging, InternalDelegations, TypeCheck
Defined in:
lib/concurrent/actor/behaviour/abstract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InternalDelegations

#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #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?

Constructor Details

#initialize(core, subsequent, core_options) ⇒ Abstract

Returns a new instance of Abstract.



13
14
15
16
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 13

def initialize(core, subsequent, core_options)
  @core       = Type! core, Core
  @subsequent = Type! subsequent, Abstract, NilClass
end

Instance Attribute Details

#coreObject (readonly)



11
12
13
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 11

def core
  @core
end

#subsequentObject (readonly)



11
12
13
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 11

def subsequent
  @subsequent
end

Instance Method Details

#broadcast(public, event) ⇒ Object

broadcasts event to all behaviours and context



38
39
40
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 38

def broadcast(public, event)
  core.broadcast(public, event)
end

#on_envelope(envelope) ⇒ Object

Note:

super needs to be called not to break the chain

override to add extra behaviour



20
21
22
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 20

def on_envelope(envelope)
  pass envelope
end

#on_event(public, event) ⇒ Object

Note:

super needs to be called not to break the chain

override to add extra behaviour



31
32
33
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 31

def on_event(public, event)
  subsequent.on_event public, event if subsequent
end

#pass(envelope) ⇒ Object

Parameters:



25
26
27
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 25

def pass(envelope)
  subsequent.on_envelope envelope
end

#reject_envelope(envelope) ⇒ Object



42
43
44
45
46
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 42

def reject_envelope(envelope)
  envelope.reject! ActorTerminated.new(reference)
  dead_letter_routing << envelope unless envelope.future
  log DEBUG, "rejected #{envelope.message} from #{envelope.sender_path}"
end