lib/dcell.rb in dcell-0.9.0 vs lib/dcell.rb in dcell-0.10.0

- old
+ new

@@ -7,23 +7,31 @@ require 'dcell/actor_proxy' require 'dcell/directory' require 'dcell/mailbox_proxy' require 'dcell/messages' require 'dcell/node' +require 'dcell/node_manager' require 'dcell/global' require 'dcell/responses' require 'dcell/router' require 'dcell/rpc' +require 'dcell/future_proxy' require 'dcell/server' +require 'dcell/info_service' require 'dcell/registries/redis_adapter' require 'dcell/registries/moneta_adapter' +require 'dcell/registries/gossip/core' +require 'dcell/registries/gossip_adapter' + require 'dcell/celluloid_ext' # Distributed Celluloid module DCell + class NotConfiguredError < RuntimeError; end # Not configured yet + DEFAULT_PORT = 7777 # Default DCell port @config_lock = Mutex.new class << self attr_reader :me, :registry @@ -44,10 +52,20 @@ 'registry' => {'adapter' => 'redis', 'server' => 'localhost'} }.merge(options) @me = Node.new @configuration['id'], @configuration['addr'] + # Specify the directory server (defaults to me), and add it + # to the local directory. + directory = @configuration['directory'] || {} + directory = directory.inject({}) { |h,(k,v)| h[k.to_s] = v; h } + directory = { + 'id' => @configuration['id'], + 'addr' => @configuration['addr'] + }.merge(directory) + DCell::Directory.set directory['id'], directory['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" @@ -65,11 +83,14 @@ me end # Obtain the local node ID - def id; @configuration['id']; end + def id + raise NotConfiguredError, "please configure DCell with DCell.setup" unless @configuration + @configuration['id'] + end # Obtain the 0MQ address to the local mailbox def addr; @configuration['addr']; end alias_method :address, :addr @@ -95,8 +116,12 @@ end end # DCell's actor dependencies class Group < Celluloid::Group - supervise Server, :as => :dcell_server + supervise NodeManager, :as => :node_manager + supervise Server, :as => :dcell_server + supervise InfoService, :as => :info end + + Logger = Celluloid::Logger end