Class: RightScale::ActorRegistry
- Defined in:
- lib/right_agent/actor_registry.rb
Instance Attribute Summary collapse
-
#actors ⇒ Object
readonly
(Hash) Actors that are registered; key is actor prefix and value is actor.
Instance Method Summary collapse
-
#actor_for(prefix) ⇒ Object
Retrieve actor by prefix.
-
#initialize ⇒ ActorRegistry
constructor
Initialize registry.
-
#register(actor, prefix) ⇒ Object
Register as an actor.
-
#services ⇒ Object
Retrieve services provided by all of the registered actors.
Constructor Details
#initialize ⇒ ActorRegistry
Initialize registry
31 32 33 |
# File 'lib/right_agent/actor_registry.rb', line 31 def initialize @actors = {} end |
Instance Attribute Details
#actors ⇒ Object (readonly)
(Hash) Actors that are registered; key is actor prefix and value is actor
28 29 30 |
# File 'lib/right_agent/actor_registry.rb', line 28 def actors @actors end |
Instance Method Details
#actor_for(prefix) ⇒ Object
Retrieve actor by prefix
Parameters
- prefix(String)
-
Prefix identifying actor
Return
- (Actor|nil)
-
Retrieved actor, or nil if unknown
70 71 72 |
# File 'lib/right_agent/actor_registry.rb', line 70 def actor_for(prefix) @actors[prefix] end |
#register(actor, prefix) ⇒ Object
Register as an actor
Parameters
- actor(Actor)
-
Actor to be registered
- prefix(String)
-
Prefix used in request to identify actor
Return
- (Actor)
-
Actor registered
Raises
ArgumentError if actor is not an Actor
46 47 48 49 50 51 52 53 |
# File 'lib/right_agent/actor_registry.rb', line 46 def register(actor, prefix) raise ArgumentError, "#{actor.inspect} is not a RightScale::Actor subclass instance" unless RightScale::Actor === actor log_msg = "[actor] #{actor.class.to_s}" log_msg += ", prefix #{prefix}" if prefix && !prefix.empty? Log.info(log_msg) prefix ||= actor.class.default_prefix @actors[prefix.to_s] = actor end |
#services ⇒ Object
Retrieve services provided by all of the registered actors
Return
- (Array)
-
List of unique /prefix/method path strings
59 60 61 |
# File 'lib/right_agent/actor_registry.rb', line 59 def services @actors.map { |prefix, actor| actor.class.provides_for(prefix) }.flatten.uniq end |