Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392906
  • 博文数量: 69
  • 博客积分: 1984
  • 博客等级: 上尉
  • 技术积分: 953
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-28 00:43
个人简介

学无所长,一事无成

文章分类

全部博文(69)

文章存档

2015年(19)

2014年(14)

2013年(9)

2012年(17)

2010年(10)

我的朋友

分类: Python/Ruby

2015-02-07 22:49:53



使用 DCell 首先节点必须加入集群(join a cluster )。
使用 DCell.me 可以获取 local node,这是一个 DCell::Node 对象:
  1. >> DCell.start
  2.  => #<Celluloid::Supervisor(DCell::Application):0xed6>
  3. >> DCell.me
  4.  => #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">
DCell::Node 对象就是系统中用来定位 actors 的接入点。DCell.me 返回本地节点( local node)。要获取其他节点可以通过他们的节点 ID:
  1. >> node = DCell::Node["cryptosphere.local"]
  2.  => #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">
DCell::Node.all 返回当前集群中的所有节点:
  1. >> DCell::Node.all
  2.  => [#<DCell::Node[test_node] @addr="tcp://127.0.0.1:21264">, #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">]
DCell::Node 是可以枚举的,你可以通过 DCell::Node.each 进行迭代。

获取了一个节点后,你紧接着就需要查看其上提供的服务(services),你可以像调用普通 Ruby 对象的方法一样调用这些服务:
  1. >> node = DCell::Node["wintermute.local"]
  2.  => #<DCell::Node[wintermute.local] @addr="tcp://127.0.0.1:7777">
  3. >> info_service = node[:info]
  4.  => #<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">
  5. >> info_service.load_averages
  6.  => [0.71, 0.74, 0.79]
要查看某个节点提供的所有服务(services),你可以调用 DCell::Node#all 方法:

  1. >> node = DCell::Node["cryptosphere.local"]
  2.  => #<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:7777">
  3. >> node.all
  4.  => [:node_manager, :dcell_server, :info]
阅读(757) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~