Files

Class/Module Index [+]

Quicksearch

Concurrent::Actor::Behaviour::Termination

Handles actor termination. @note Actor rejects envelopes when terminated. @note TODO missing example

Attributes

reason[R]

@!attribute [r] terminated

@return [Edge::Event] event which will become set when actor is terminated.

@!attribute [r] reason

terminated[R]

@!attribute [r] terminated

@return [Edge::Event] event which will become set when actor is terminated.

@!attribute [r] reason

Public Class Methods

new(core, subsequent, core_options, trapping = false) click to toggle source
# File lib/concurrent/actor/behaviour/termination.rb, line 15
def initialize(core, subsequent, core_options, trapping = false)
  super core, subsequent, core_options
  @terminated        = Concurrent.event
  @public_terminated = @terminated.hide_completable
  @reason            = nil
  @trapping          = trapping
end

Public Instance Methods

on_envelope(envelope) click to toggle source
# File lib/concurrent/actor/behaviour/termination.rb, line 37
def on_envelope(envelope)
  command, reason = envelope.message
  case command
  when :terminated?
    terminated?
  when :terminate!
    if trapping? && reason != :kill
      pass envelope
    else
      terminate! reason
    end
  when :termination_event
    @public_terminated
  else
    if terminated?
      reject_envelope envelope
      MESSAGE_PROCESSED
    else
      pass envelope
    end
  end
end
terminate!(reason = :normal) click to toggle source

Terminates the actor. Any Envelope received after termination is rejected. Terminates all its children, does not wait until they are terminated.

# File lib/concurrent/actor/behaviour/termination.rb, line 62
def terminate!(reason = :normal)
  # TODO return after all children are terminated
  return true if terminated?
  @reason = reason
  terminated.complete
  broadcast(true, [:terminated, reason]) # TODO do not end up in Dead Letter Router
  parent << :remove_child if parent
  true
end
terminated?() click to toggle source

@note Actor rejects envelopes when terminated. @return [true, false] if actor is terminated

# File lib/concurrent/actor/behaviour/termination.rb, line 25
def terminated?
  @terminated.completed?
end
trapping=(val) click to toggle source
# File lib/concurrent/actor/behaviour/termination.rb, line 33
def trapping=(val)
  @trapping = !!val
end
trapping?() click to toggle source
# File lib/concurrent/actor/behaviour/termination.rb, line 29
def trapping?
  @trapping
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.