Module: DCell
- Defined in:
- lib/dcell.rb,
lib/dcell/rpc.rb,
lib/dcell/node.rb,
lib/dcell/global.rb,
lib/dcell/router.rb,
lib/dcell/server.rb,
lib/dcell/version.rb,
lib/dcell/explorer.rb,
lib/dcell/messages.rb,
lib/dcell/directory.rb,
lib/dcell/responses.rb,
lib/dcell/actor_proxy.rb,
lib/dcell/future_proxy.rb,
lib/dcell/info_service.rb,
lib/dcell/node_manager.rb,
lib/dcell/mailbox_proxy.rb,
lib/dcell/registries/zk_adapter.rb,
lib/dcell/registries/redis_adapter.rb,
lib/dcell/registries/mongodb_adapter.rb,
lib/dcell/registries/cassandra_adapter.rb
Overview
not sure this is right yet … Keyspace “whatever” [
ColumnFamily "dcell" {
RowKey "nodes": {
<nodeid>: <address>,
<nodeid>: <address>,
...
}
RowKey "globals": {
<key>: <marshal blob>,
<key>: <marshal blob>,
...
}
}
]
Defined Under Namespace
Modules: Directory, Global, Registry Classes: Actor, CellProxy, ErrorResponse, Explorer, FutureProxy, InfoService, MailboxProxy, Message, Node, NodeManager, NotConfiguredError, RPB, RPBC, RPC, Response, Router, Server, SubjectProxy, SuccessResponse, SupervisionGroup, ThreadHandleProxy
Constant Summary collapse
- Logger =
Celluloid::Logger
- VERSION =
"0.16.1"
Class Attribute Summary collapse
-
.me ⇒ Object
readonly
Returns the value of attribute me.
-
.registry ⇒ Object
readonly
Returns the value of attribute registry.
Class Method Summary collapse
-
.addr ⇒ Object
(also: address)
Obtain the 0MQ address to the local mailbox.
- .addr=(addr) ⇒ Object (also: address=)
-
.generate_node_id ⇒ Object
Attempt to generate a unique node ID for this machine.
-
.id ⇒ Object
Obtain the local node ID.
-
.run ⇒ Object
Run the DCell application.
-
.run! ⇒ Object
Run the DCell application in the background.
-
.setup(options = {}) ⇒ Object
Configure DCell with the following options:.
-
.start(options = {}) ⇒ Object
Start combines setup and run! into a single step.
Class Attribute Details
.me ⇒ Object (readonly)
Returns the value of attribute me.
35 36 37 |
# File 'lib/dcell.rb', line 35 def me @me end |
.registry ⇒ Object (readonly)
Returns the value of attribute registry.
35 36 37 |
# File 'lib/dcell.rb', line 35 def registry @registry end |
Class Method Details
.addr ⇒ Object Also known as: address
Obtain the 0MQ address to the local mailbox
81 |
# File 'lib/dcell.rb', line 81 def addr; @configuration['addr']; end |
.addr=(addr) ⇒ Object Also known as: address=
84 85 86 87 |
# File 'lib/dcell.rb', line 84 def addr=(addr) @configuration['addr'] = addr @me.update_server_address addr end |
.generate_node_id ⇒ Object
Attempt to generate a unique node ID for this machine
91 92 93 94 95 96 97 98 99 100 |
# 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 ⇒ Object
Obtain the local node ID
75 76 77 78 |
# File 'lib/dcell.rb', line 75 def id raise NotConfiguredError, "please configure DCell with DCell.setup" unless @configuration @configuration['id'] end |
.run ⇒ Object
Run the DCell application
103 104 105 |
# File 'lib/dcell.rb', line 103 def run DCell::SupervisionGroup.run end |
.run! ⇒ Object
Run the DCell application in the background
108 109 110 |
# File 'lib/dcell.rb', line 108 def run! DCell::SupervisionGroup.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)
*
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dcell.rb', line 42 def setup( = {}) # Stringify keys :/ = .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() @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 = {}) ⇒ Object
Start combines setup and run! into a single step
113 114 115 116 |
# File 'lib/dcell.rb', line 113 def start( = {}) setup run! end |