Skip to content

Commit

Permalink
do not expose internal celluloid actors
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Jan 29, 2015
1 parent 8cd134c commit c7222f9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
24 changes: 22 additions & 2 deletions lib/dcell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
module DCell
class NotConfiguredError < RuntimeError; end # Not configured yet

@config_lock = Mutex.new
@lock = Mutex.new
@actors = Set.new

def self.included(base)
base.extend(ClassMethods)
Expand All @@ -47,7 +48,7 @@ def setup(options = {})
# Stringify keys :/
options = options.inject({}) { |h,(k,v)| h[k.to_s] = v; h }

@config_lock.synchronize do
@lock.synchronize do
@configuration = {
'addr' => "tcp://127.0.0.1:*",
'heartbeat_rate' => 5,
Expand All @@ -65,6 +66,24 @@ def setup(options = {})
me
end

def add_actor(name)
@lock.synchronize do
@actors << name.to_sym
end
end

def get_actor(name)
name = name.to_sym
if @actors.include? name
return Celluloid::Actor[name]
end
nil
end

def actors
@actors.to_a
end

def config(option)
unless @configuration
Logger.warn "DCell unconfigured, can't get #{option}"
Expand Down Expand Up @@ -132,6 +151,7 @@ class SupervisionGroup < Celluloid::SupervisionGroup
supervise Server, :as => :dcell_server, :args => [DCell]
supervise InfoService, :as => :info
end
DCell.add_actor :info

Logger = Celluloid::Logger
end
7 changes: 7 additions & 0 deletions lib/dcell/celluloid_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def to_msgpack(pk=nil)
end
end

module ClassMethods
def supervise_as(name, *args, &block)
DCell.add_actor name
Supervisor.supervise_as(name, self, *args, &block)
end
end

class CellProxy
alias_method :____async, :async
def async(meth = nil, *args, &block)
Expand Down
4 changes: 2 additions & 2 deletions lib/dcell/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(sender, name)
end

def dispatch
actor = Celluloid::Actor[@name]
actor = DCell.get_actor @name
mailbox, methods = nil, nil
if actor
mailbox, methods = actor.mailbox, actor.class.instance_methods(false)
Expand All @@ -66,7 +66,7 @@ def initialize(sender)
end

def dispatch
Node[@sender[:id]] << SuccessResponse.new(@id, @sender[:address], Celluloid::Actor.registered)
Node[@sender[:id]] << SuccessResponse.new(@id, @sender[:address], DCell.actors)
end

def to_msgpack(pk=nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/dcell_mock.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module DCellMock
@config_lock = Mutex.new
@lock = Mutex.new
include DCell
end

0 comments on commit c7222f9

Please sign in to comment.