Created
October 25, 2012 14:26
-
-
Save waynerobinson/3952839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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