Parent

Files

Class/Module Index [+]

Quicksearch

Concurrent::Actor::AbstractContext

New actor is defined by subclassing {RestartingContext}, {Context} and defining its abstract methods. {AbstractContext} can be subclassed directly to implement more specific behaviour see {Root} implementation.

Example of ac actor definition:

{include:file:doc/actor/define.out.rb}

See methods of {AbstractContext} what else can be tweaked, e.g {AbstractContext#default_reference_class}

@abstract implement {AbstractContext#on_message} and {AbstractContext#behaviour_definition}

Attributes

core[R]

Public Class Methods

spawn(name_or_opts, *args, &block) click to toggle source

Behaves as {Concurrent::Actor.spawn} but :class is auto-inserted based on receiver so it can be omitted. @example by class and name

AdHoc.spawn(:ping1) { -> message { message } }

@example by option hash

inc2 = AdHoc.spawn(name:     'increment by 2',
                   args:     [2],
                   executor: Concurrent.configuration.global_task_pool) do |increment_by|
  lambda { |number| number + increment_by }
end
inc2.ask!(2) # => 4

@see Concurrent::Actor.spawn

# File lib/concurrent/actor/context.rb, line 116
def self.spawn(name_or_opts, *args, &block)
  Actor.spawn to_spawn_options(name_or_opts, *args), &block
end
spawn!(name_or_opts, *args, &block) click to toggle source

behaves as {Concurrent::Actor.spawn!} but :class is auto-inserted based on receiver so it can be omitted.

# File lib/concurrent/actor/context.rb, line 121
def self.spawn!(name_or_opts, *args, &block)
  Actor.spawn! to_spawn_options(name_or_opts, *args), &block
end

Public Instance Methods

<<(message) click to toggle source
Alias for: tell
ask(message) click to toggle source
# File lib/concurrent/actor/context.rb, line 97
def ask(message)
  raise 'actor cannot ask itself'
end
Also aliased as: ask!
ask!(message) click to toggle source
Alias for: ask
behaviour_definition() click to toggle source

@return [Array<Array(Behavior::Abstract, Array<Object>)>]

# File lib/concurrent/actor/context.rb, line 71
def behaviour_definition
  raise NotImplementedError
end
dead_letter_routing() click to toggle source

Defines an actor responsible for dead letters. Any rejected message send with {Reference#tell} is sent there, a message with future is considered already monitored for failures. Default behaviour is to use {AbstractContext#dead_letter_routing} of the parent, so if no {AbstractContext#dead_letter_routing} method is overridden in parent-chain the message ends up in `Actor.root.dead_letter_routing` agent which will log warning. @return [Reference]

# File lib/concurrent/actor/context.rb, line 66
def dead_letter_routing
  parent.dead_letter_routing
end
default_executor() click to toggle source

override to se different default executor, e.g. to change it to global_operation_pool @return [Executor]

# File lib/concurrent/actor/context.rb, line 88
def default_executor
  Concurrent.global_io_executor
end
default_reference_class() click to toggle source

override if different class for reference is needed @return [CLass] descendant of {Reference}

# File lib/concurrent/actor/context.rb, line 82
def default_reference_class
  Reference
end
envelope() click to toggle source

@return [Envelope] current envelope, accessible inside on_message processing

# File lib/concurrent/actor/context.rb, line 76
def envelope
  @envelope or raise 'envelope not set'
end
on_envelope(envelope) click to toggle source

@api private

# File lib/concurrent/actor/context.rb, line 45
def on_envelope(envelope)
  @envelope = envelope
  on_message envelope.message
ensure
  @envelope = nil
end
on_event(event) click to toggle source

override to add custom code invocation on internal events like `:terminated`, `:resumed`, `anError`.

# File lib/concurrent/actor/context.rb, line 41
def on_event(event)
end
on_message(message) click to toggle source

@abstract override to define Actor's behaviour @param [Object] message @return [Object] a result which will be used to set the Future supplied to Reference#ask @note self should not be returned (or sent to other actors), {reference} should be used

instead
# File lib/concurrent/actor/context.rb, line 36
def on_message(message)
  raise NotImplementedError
end
pass() click to toggle source

if you want to pass the message to next behaviour, usually {Behaviour::ErrorsOnUnknownMessage}

# File lib/concurrent/actor/context.rb, line 54
def pass
  core.behaviour!(Behaviour::ExecutesContext).pass envelope
end
tell(message) click to toggle source

tell self a message

# File lib/concurrent/actor/context.rb, line 93
def tell(message)
  reference.tell message
end
Also aliased as: <<

[Validate]

Generated with the Darkfish Rdoc Generator 2.