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

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

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) ⇒ Abstract

Returns a new instance of Abstract.



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

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

Instance Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



8
9
10
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 8

def core
  @core
end

#subsequentObject (readonly)

Returns the value of attribute subsequent.



8
9
10
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 8

def subsequent
  @subsequent
end

Instance Method Details

#broadcast(event) ⇒ Object

broadcasts event to all behaviours and context



35
36
37
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 35

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

#on_envelope(envelope) ⇒ Object

Note:

super needs to be called not to break the chain

override to add extra behaviour



17
18
19
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 17

def on_envelope(envelope)
  pass envelope
end

#on_event(event) ⇒ Object

Note:

super needs to be called not to break the chain

override to add extra behaviour



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

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

#pass(envelope) ⇒ Object

Parameters:



22
23
24
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 22

def pass(envelope)
  subsequent.on_envelope envelope
end

#reject_envelope(envelope) ⇒ Object



39
40
41
42
43
# File 'lib/concurrent/actor/behaviour/abstract.rb', line 39

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