Class: MCollective::Registration::Base
- Inherits:
-
Object
- Object
- MCollective::Registration::Base
- Defined in:
- lib/mcollective/registration/base.rb
Overview
This is a base class that other registration plugins can use to handle regular announcements to the mcollective
The configuration file determines how often registration messages gets sent using the registerinterval option, the plugin runs in the background in a thread.
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
Register plugins that inherits base.
Instance Method Summary collapse
- #body ⇒ Object
- #config ⇒ Object
- #interval ⇒ Object
- #msg_filter ⇒ Object
- #publish(message) ⇒ Object
-
#run(connection) ⇒ Object
Creates a background thread that periodically send a registration notice.
- #target_collective ⇒ Object
Class Method Details
.inherited(klass) ⇒ Object
Register plugins that inherits base
11 12 13 14 |
# File 'lib/mcollective/registration/base.rb', line 11 def self.inherited(klass) PluginManager << {:type => "registration_plugin", :class => klass.to_s} super end |
Instance Method Details
#body ⇒ Object
68 69 70 |
# File 'lib/mcollective/registration/base.rb', line 68 def body raise "Registration Plugins must implement the #body method" end |
#config ⇒ Object
28 29 30 |
# File 'lib/mcollective/registration/base.rb', line 28 def config Config.instance end |
#interval ⇒ Object
51 52 53 |
# File 'lib/mcollective/registration/base.rb', line 51 def interval config.registerinterval end |
#msg_filter ⇒ Object
32 33 34 35 36 |
# File 'lib/mcollective/registration/base.rb', line 32 def msg_filter filter = Util.empty_filter filter["agent"] << "registration" filter end |
#publish(message) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mcollective/registration/base.rb', line 55 def publish() if req = Message.new(, nil, {:type => :request, :agent => "registration", :collective => target_collective, :filter => msg_filter}) req.encode! Log.debug("Sending registration #{req.requestid} to collective #{req.collective}") req.publish else Log.debug("Skipping registration due to nil body") end end |
#run(connection) ⇒ Object
Creates a background thread that periodically send a registration notice.
The actual registration notices comes from the ‘body’ method of the registration plugins.
20 21 22 23 24 25 26 |
# File 'lib/mcollective/registration/base.rb', line 20 def run(connection) return false if interval == 0 Thread.new do publish_thread(connection) end end |
#target_collective ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mcollective/registration/base.rb', line 38 def target_collective main_collective = config.main_collective collective = config.registration_collective || main_collective unless config.collectives.include?(collective) Log.warn("Sending registration to #{main_collective}: #{collective} is not a valid collective") collective = main_collective end collective end |