README.md in dcell-0.12.0.pre vs README.md in dcell-0.13.0.pre

- old
+ new

@@ -1,9 +1,10 @@ ![DCell](https://github.com/celluloid/dcell/raw/master/logo.png) ===== [![Build Status](https://secure.travis-ci.org/celluloid/dcell.png?branch=master)](http://travis-ci.org/celluloid/dcell) [![Dependency Status](https://gemnasium.com/celluloid/dcell.png)](https://gemnasium.com/celluloid/dcell) +[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/celluloid/dcell) > "Objects can message objects transparently that live on other machines > over the network, and you don't have to worry about the networking gunk, > and you don't have to worry about finding them, and you don't have to > worry about anything. It's just as if you messaged an object that's @@ -71,54 +72,73 @@ ...to pull it in as a dependency. Example ------- -Create a ruby script with the following contents: +Copy and paste this into `itchy.rb` (or run `bundle exec examples/itchy.rb`): - # node1.rb +```ruby +require 'dcell' - require 'dcell' +DCell.start :id => "itchy", :addr => "tcp://127.0.0.1:9001" - class Duck - include Celluloid +class Itchy + include Celluloid - def quack - puts "Quack!" - end + def initialize + puts "Ready for mayhem!" + @n = 0 + end + + def fight + @n = (@n % 6) + 1 + if @n <= 3 + puts "Bite!" + else + puts "Fight!" end + end +end - Duck.supervise_as :duck_actor +Itchy.supervise_as :itchy +sleep +``` - DCell.start :id => "node1", :addr => "tcp://127.0.0.1:4000" +You can now launch itchy with: - sleep +``` +ruby itchy.rb +``` -Now save and run the script via the command line and open a new shell. In there, create another ruby script: +Now copy and paste the following into `scratchy.rb` (also in examples) - # node2.rb +```ruby +require 'dcell' - require 'dcell' +DCell.start :id => "scratchy", :addr => "tcp://127.0.0.1:9002" +itchy_node = DCell::Node["itchy"] - DCell.start :id => "node2", :addr => "tcp://127.0.0.1:4001", :directory => {:id => "node1", :addr => "tcp://127.0.0.1:4000"} +puts "Fighting itchy! (check itchy's output)" - loop { - node = DCell::Node["node1"] - duck = node[:duck_actor] - duck.quack - sleep 3 - } +6.times do + itchy_node[:itchy].fight + sleep 1 +end +``` -When you run the second script in the second shell, you will see the following output in your first shell: +Now run scratchy side-by-side with itchy. You should see this on itchy: - $ ruby node1.rb - I, [2012-08-30T20:00:00.759342 #26124] INFO -- : Connected to node1 - I, [2012-08-30T20:00:04.454006 #26124] INFO -- : Connected to node2 - Quack! - Quack! - Quack! - -The loop in the second script looks up the node we registered in the first script, takes the registered Duck actor and calls the `quack` method every three seconds. +``` +$ bundle exec examples/itchy.rb +Ready for mayhem! +I, [2012-12-25T22:52:45.362355 #74272] INFO -- : Connected to scratchy +Bite! +Bite! +Bite! +Fight! +Fight! +Fight! +``` This is a basic example how individual DCell::Nodes have registered Celluloid actors which can be accessed remotely by other DCell::Nodes. Supported Platforms -------------------