This repository has been archived by the owner on Dec 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Usage
Dmytro Milinevskyy edited this page Mar 7, 2015
·
4 revisions
Before using DCell you'll need to join a cluster.
You can obtain the DCell::Node object representing the local node by calling DCell.me:
>> DCell.start
=> #<Celluloid::Supervisor(DCell::Application):0xed6>
>> DCell.me
=> #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">
DCell::Node objects are the entry point for locating actors on the system. DCell.me returns the local node. Other nodes can be obtained by their node IDs:
>> node = DCell::Node["cryptosphere.local"]
=> #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">
DCell::Node.all returns all connected nodes in the cluster:
>> DCell::Node.all
=> [#<DCell::Node[test_node] @addr="tcp://127.0.0.1:21264">, #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">]
DCell::Node is a Ruby Enumerable. You can iterate across all nodes with DCell::Node.each.
Once you've obtained a node, you can look up services it exports and call them just like you'd invoke methods on any other Ruby object:
>> node = DCell::Node["wintermute.local"]
=> #<DCell::Node[wintermute.local] @addr="tcp://127.0.0.1:7777">
>> info_service = node[:info]
=> #<Celluloid::Actor(DCell::InfoService:0x3fd847dd26d8) @cpu_arch="x86_64" @os="darwin" @os_version="11.3.0" @hostname="wintermute.local" @platform="x86_64-darwin11.3.0" @ruby_version="1.9.3" @ruby_engine="ruby" @cpu_type="Intel(R) Core(TM) i7-2635QM CPU" @cpu_vendor=:intel @cpu_speed=2.0 @cpu_count=8 @distribution="Mac OS X 10.7.3 (11D50b)" @ruby_platform="ruby 1.9.3">
>> info_service.load_averages
=> [0.71, 0.74, 0.79]
You can also find all available services on a node with DCell::Node#all:
>> node = DCell::Node["cryptosphere.local"]
=> #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">
>> node.all
=> [:node_manager, :dcell_server, :info]
It's possible to get a list of actors from all nodes by their names:
workers = DCell[:worker]
id = SecureRandom.uuid
workers.each { |w| w.async.work(id) }
workers.reduce(0) {|sum, worker| sum + worker.res(id) }