module DCell
Distributed Celluloid
not sure this is right yet … Keyspace “whatever” [
ColumnFamily "dcell" { RowKey "nodes": { <nodeid>: <address>, <nodeid>: <address>, ... } RowKey "globals": { <key>: <marshal blob>, <key>: <marshal blob>, ... } }
]
Constants
- Logger
- VERSION
Attributes
me[R]
registry[R]
Public Class Methods
addr()
click to toggle source
Obtain the 0MQ address to the local mailbox
# File lib/dcell.rb, line 81 def addr; @configuration['addr']; end
Also aliased as: address
addr=(addr)
click to toggle source
# File lib/dcell.rb, line 84 def addr=(addr) @configuration['addr'] = addr @me.update_server_address addr end
Also aliased as: address=
generate_node_id()
click to toggle source
Attempt to generate a unique node ID for this machine
# File lib/dcell.rb, line 91 def generate_node_id # a little bit more creative if @registry.respond_to? :unique @registry.unique else digest = Digest::SHA512.new seed = Socket.gethostname + rand.to_s + Time.now.to_s + SecureRandom.hex digest.update(seed).to_s end end
id()
click to toggle source
Obtain the local node ID
# File lib/dcell.rb, line 75 def id raise NotConfiguredError, "please configure DCell with DCell.setup" unless @configuration @configuration['id'] end
run()
click to toggle source
Run the DCell
application
# File lib/dcell.rb, line 103 def run DCell::SupervisionGroup.run end
run!()
click to toggle source
Run the DCell
application in the background
# File lib/dcell.rb, line 108 def run! DCell::SupervisionGroup.run! end
setup(options = {})
click to toggle source
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)
*
# File lib/dcell.rb, line 42 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:*", 'registry' => {'adapter' => 'redis', 'server' => 'localhost'} }.merge(options) @me = Node.new @configuration['id'], nil 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']) ObjectSpace.define_finalizer(me, proc {Directory.remove @configuration['id']}) end me end
start(options = {})
click to toggle source
Start combines setup and run! into a single step
# File lib/dcell.rb, line 113 def start(options = {}) setup options run! end