| Class | MCollective::Registration::Base |
| In: |
lib/mcollective/registration/base.rb
|
| Parent: | Object |
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.
Register plugins that inherits base
# File lib/mcollective/registration/base.rb, line 11
11: def self.inherited(klass)
12: PluginManager << {:type => "registration_plugin", :class => klass.to_s}
13: end
# File lib/mcollective/registration/base.rb, line 57
57: def interval
58: config.registerinterval
59: end
# File lib/mcollective/registration/base.rb, line 40
40: def msg_filter
41: {"agent" => "registration"}
42: end
# File lib/mcollective/registration/base.rb, line 61
61: def publish(message)
62: unless message
63: Log.debug("Skipping registration due to nil body")
64: else
65: req = Message.new(message, nil, {:type => :request, :agent => "registration", :collective => target_collective, :filter => msg_filter})
66: req.encode!
67:
68: Log.debug("Sending registration #{req.requestid} to collective #{req.collective}")
69:
70: req.publish
71: end
72: end
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, line 19
19: def run(connection)
20: return false if interval == 0
21:
22: Thread.new do
23: loop do
24: begin
25: publish(body)
26:
27: sleep interval
28: rescue Exception => e
29: Log.error("Sending registration message failed: #{e}")
30: sleep interval
31: end
32: end
33: end
34: end
# File lib/mcollective/registration/base.rb, line 44
44: def target_collective
45: main_collective = config.main_collective
46:
47: collective = config.registration_collective || main_collective
48:
49: unless config.collectives.include?(collective)
50: Log.warn("Sending registration to #{main_collective}: #{collective} is not a valid collective")
51: collective = main_collective
52: end
53:
54: return collective
55: end