Skip to content

Instantly share code, notes, and snippets.

@waynerobinson
Created October 25, 2012 14:26
Show Gist options
  • Save waynerobinson/3952839 to your computer and use it in GitHub Desktop.
Save waynerobinson/3952839 to your computer and use it in GitHub Desktop.
require "jruby"
require "dcell"
DCell.start id: "node1-client", addr: "tcp://127.0.0.1:4001", directory: {id: "node1", addr: "tcp://127.0.0.1:4000"}
loop {
duck = DCell::Global[:duck]
if duck
begin
puts duck.future.quack.value(1.5)
rescue RuntimeError => ex
if ex.message == "Timed out"
puts "Quacking timed out."
else
puts ex.inspect
end
end
else
puts "No duck."
end
sleep 0.5
}
require "jruby"
require "celluloid"
require "dcell"
class Duck
include Celluloid
def quack
@actor_version ||= rand(1000000)
"Quack from #{@actor_version} #{Time.now}"
end
end
class DuckGroup < Celluloid::SupervisionGroup
pool Duck, as: :duck, size: 3
end
DuckGroup.run!
puts "Starting DCell..."
DCell.start id: "node1", addr: "tcp://127.0.0.1:4000"
DCell::Global[:duck] = Celluloid::Actor[:duck]
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment