Skip to content
This repository

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:

class TimeServer
  include Celluloid

  def time
    "The time is: #{Time.now}"
  end
end

Now that we've defined the TimeServer, we're going to supervise it and register it in the local registry:

>> TimeServer.supervise_as :time_server
 => #<Celluloid::Supervisor(TimeServer):0xee4>

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"
Something went wrong with that request. Please try again.