Sha256: 784050bfc7c37cee00007bca7ef9a15163580fb3192dcda2d297b093bf0505d1

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

$: << File.expand_path('../../lib', __FILE__)

require 'bundler/setup'
require 'mikka'


class Worker < Mikka::Actor
  life_cycle :permanent
  
  def pre_start
    puts "#{context.id} starting"
  end
  
  def pre_restart(reason)
    puts "#{context.id} restarting"
  end
  
  def post_restart(reason)
    puts "#{context.id} restarted"
  end
  
  def post_stop
    puts "#{context.id} stopped"
  end
  
  def receive(message)
    raise java.lang.Exception.new('Oh, shucks') if message == 'hard work'
    puts "#{context.id} Work on #{message}"
  end
end

class Manager < Mikka::Actor
  fault_handling :strategy => :all_for_one, :trap => [java.lang.Exception], :max_retries => 3, :time_range => 3000
  
  def pre_start
    @worker1 = Mikka.actor_of { Worker.new }
    @worker2 = Mikka.actor_of { Worker.new }
    @worker1.id = 'worker1'
    @worker2.id = 'worker2'
    context.start_link(@worker1)
    context.start_link(@worker2)
    @worker1 << 'simple work'
    @worker2 << 'hard work'
    @worker2 << 'simple work'
    @worker2 << 'simple work'
    @worker2 << 'hard work'
    @worker2 << 'simple work'
    @worker2 << 'simple work'
    @worker2 << 'simple work'
  end
end

manager = Mikka.actor_of(Manager).start

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mikka-1.1.1-java examples/supervision1.rb
mikka-1.1.0-java examples/supervision1.rb
mikka-1.0.1-java examples/supervision1.rb
mikka-1.0.0-universal-darwin-11 examples/supervision1.rb