You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dmytro Milinevskyy edited this page Mar 7, 2015
·
6 revisions
All services exposed by DCell must take the form of registered Celluloid actors.
What follows is an extremely brief introduction to creating and registering
actors, but for more information, you should definitely read the Celluloid
documentation.
DCell exposes all Celluloid actors you've registered directly onto the network.
The best way to register an actor is by supervising it. Below is an example of
how to create an actor and register it on the network:
classTimeServerincludeCelluloiddeftime"The time is: #{Time.now}"endend
Now that we've defined the TimeServer, we're going to supervise it and register
it in the local registry:
Supervising actors means that if they crash, they're automatically restarted
and registered under the same name. We can access registered actors by using
Celluloid::Actor#[]:
>> Celluloid::Actor[:time_server]=>#<Celluloid::Actor(TimeServer:0xee8)>
>> Celluloid::Actor[:time_server].time=>"The time is: 2011-11-10 20:17:48 -0800"
This same actor is now available using the DCell::Node#[] syntax. This example assumes our local node (i.e. DCell.id) is "cryptosphere.local":
>> node=DCell::Node["cryptosphere.local"]=>#<DCell::Node[cryptosphere.local] @addr="tcp://127.0.0.1:1870">
>> node[:time_server].time=>"The time is: 2011-11-10 20:28:27 -0800"
The actor might be also obtained using DCell#[] syntax. In this case a list of actors from all available nodes is generated.