class MCollective::Registration::Base
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.
Public Class Methods
inherited(klass)
click to toggle source
Register plugins that inherits base
# File lib/mcollective/registration/base.rb 11 def self.inherited(klass) 12 PluginManager << {:type => "registration_plugin", :class => klass.to_s} 13 end
Public Instance Methods
body()
click to toggle source
# File lib/mcollective/registration/base.rb 67 def body 68 raise "Registration Plugins must implement the #body method" 69 end
config()
click to toggle source
# File lib/mcollective/registration/base.rb 27 def config 28 Config.instance 29 end
interval()
click to toggle source
# File lib/mcollective/registration/base.rb 50 def interval 51 config.registerinterval 52 end
msg_filter()
click to toggle source
# File lib/mcollective/registration/base.rb 31 def msg_filter 32 filter = Util.empty_filter 33 filter["agent"] << "registration" 34 filter 35 end
publish(message)
click to toggle source
# File lib/mcollective/registration/base.rb 54 def publish(message) 55 unless message 56 Log.debug("Skipping registration due to nil body") 57 else 58 req = Message.new(message, nil, {:type => :request, :agent => "registration", :collective => target_collective, :filter => msg_filter}) 59 req.encode! 60 61 Log.debug("Sending registration #{req.requestid} to collective #{req.collective}") 62 63 req.publish 64 end 65 end
run(connection)
click to toggle source
Creates a background thread that periodically send a registration notice.
The actual registration notices comes from the 'body' method of the registration plugins.
# File lib/mcollective/registration/base.rb 19 def run(connection) 20 return false if interval == 0 21 22 Thread.new do 23 publish_thread(connection) 24 end 25 end
target_collective()
click to toggle source
# File lib/mcollective/registration/base.rb 37 def target_collective 38 main_collective = config.main_collective 39 40 collective = config.registration_collective || main_collective 41 42 unless config.collectives.include?(collective) 43 Log.warn("Sending registration to #{main_collective}: #{collective} is not a valid collective") 44 collective = main_collective 45 end 46 47 return collective 48 end