Module: DCell

Defined in:
lib/dcell.rb,
lib/dcell/node.rb,
lib/dcell/global.rb,
lib/dcell/router.rb,
lib/dcell/server.rb,
lib/dcell/version.rb,
lib/dcell/messages.rb,
lib/dcell/directory.rb,
lib/dcell/responses.rb,
lib/dcell/actor_proxy.rb,
lib/dcell/application.rb,
lib/dcell/mailbox_proxy.rb,
lib/dcell/registries/zk_adapter.rb,
lib/dcell/registries/redis_adapter.rb

Overview

Distributed Celluloid

Defined Under Namespace

Modules: Directory, Global, Registry Classes: ActorProxy, Application, ErrorResponse, MailboxProxy, Message, Node, Response, Router, Server, SuccessResponse

Constant Summary collapse

DEFAULT_PORT =

Default DCell port

7777
ZMQ_POOL_SIZE =

DCell uses a fixed-size 0MQ thread pool

1
VERSION =
"0.7.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.meObject (readonly)

Returns the value of attribute me.



27
28
29
# File 'lib/dcell.rb', line 27

def me
  @me
end

.registryObject (readonly)

Returns the value of attribute registry.



27
28
29
# File 'lib/dcell.rb', line 27

def registry
  @registry
end

.zmq_contextObject (readonly)

Returns the value of attribute zmq_context.



27
28
29
# File 'lib/dcell.rb', line 27

def zmq_context
  @zmq_context
end

Class Method Details

.addrObject Also known as: address

Obtain the 0MQ address to the local mailbox



71
# File 'lib/dcell.rb', line 71

def addr; @configuration['addr']; end

.generate_node_idObject

Attempt to generate a unique node ID for this machine



75
76
77
# File 'lib/dcell.rb', line 75

def generate_node_id
  `hostname`.strip # Super creative I know
end

.idObject

Obtain the local node ID



68
# File 'lib/dcell.rb', line 68

def id; @configuration['id']; end

.runObject

Run the DCell application



80
81
82
# File 'lib/dcell.rb', line 80

def run
  DCell::Application.run
end

.run!Object

Run the DCell application in the background



85
86
87
# File 'lib/dcell.rb', line 85

def run!
  DCell::Application.run!
end

.setup(options = {}) ⇒ Object

Configure DCell with the following options:

  • id: to identify the local node, defaults to hostname

  • addr: 0MQ address of the local node (e.g. tcp://4.3.2.1:7777)

*



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dcell.rb', line 34

def setup(options = {})
  # Stringify keys :/
  options = options.inject({}) { |h,(k,v)| h[k.to_s] = v; h }

  @config_lock.synchronize do
    @configuration = {
      'id'   => generate_node_id,
      'addr' => "tcp://127.0.0.1:#{DEFAULT_PORT}",
      'registry' => {'adapter' => 'redis', 'server' => 'localhost'}
    }.merge(options)

    @me = Node.new @configuration['id'], @configuration['addr']

    registry_adapter = @configuration['registry'][:adapter] || @configuration['registry']['adapter']
    raise ArgumentError, "no registry adapter given in config" unless registry_adapter

    registry_class_name = registry_adapter.split("_").map(&:capitalize).join << "Adapter"

    begin
      registry_class = DCell::Registry.const_get registry_class_name
    rescue NameError
      raise ArgumentError, "invalid registry adapter: #{@configuration['registry']['adapter']}"
    end

    @registry = registry_class.new(@configuration['registry'])

    addr = @configuration['public'] || @configuration['addr']
    DCell::Directory.set @configuration['id'], addr
  end

  me
end

.start(options = {}) ⇒ Object

Start combines setup and run! into a single step



90
91
92
93
# File 'lib/dcell.rb', line 90

def start(options = {})
  setup options
  run!
end