Update version according to OSCI-883
[packages/precise/mcollective.git] / doc / MCollective / Agents.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6         <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
8         <title>Class: MCollective::Agents</title>
9
10         <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
12         <script src="../js/jquery.js" type="text/javascript"
13                 charset="utf-8"></script>
14         <script src="../js/thickbox-compressed.js" type="text/javascript"
15                 charset="utf-8"></script>
16         <script src="../js/quicksearch.js" type="text/javascript"
17                 charset="utf-8"></script>
18         <script src="../js/darkfish.js" type="text/javascript"
19                 charset="utf-8"></script>
20
21 </head>
22 <body class="class">
23
24         <div id="metadata">
25                 <div id="file-metadata">
26                         <div id="file-list-section" class="section">
27                                 <h3 class="section-header">In Files</h3>
28                                 <div class="section-body">
29                                         <ul>
30                                         
31                                                 <li><a href="../lib/mcollective/agents_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
32                                                         class="thickbox" title="lib/mcollective/agents.rb">lib/mcollective/agents.rb</a></li>
33                                         
34                                         </ul>
35                                 </div>
36                         </div>
37
38                         
39                 </div>
40
41                 <div id="class-metadata">
42
43                         <!-- Parent Class -->
44                         
45                         <div id="parent-class-section" class="section">
46                                 <h3 class="section-header">Parent</h3>
47                                 
48                                 <p class="link"><a href="../Object.html">Object</a></p>
49                                 
50                         </div>
51                         
52
53                         <!-- Namespace Contents -->
54                         
55
56                         <!-- Method Quickref -->
57                         
58                         <div id="method-list-section" class="section">
59                                 <h3 class="section-header">Methods</h3>
60                                 <ul class="link-list">
61                                         
62                                         <li><a href="#M000112">::agentlist</a></li>
63                                         
64                                         <li><a href="#M000101">::new</a></li>
65                                         
66                                         <li><a href="#M000106">#activate_agent?</a></li>
67                                         
68                                         <li><a href="#M000105">#class_for_agent</a></li>
69                                         
70                                         <li><a href="#M000102">#clear!</a></li>
71                                         
72                                         <li><a href="#M000109">#dispatch</a></li>
73                                         
74                                         <li><a href="#M000107">#findagentfile</a></li>
75                                         
76                                         <li><a href="#M000108">#include?</a></li>
77                                         
78                                         <li><a href="#M000104">#loadagent</a></li>
79                                         
80                                         <li><a href="#M000103">#loadagents</a></li>
81                                         
82                                 </ul>
83                         </div>
84                         
85
86                         <!-- Included Modules -->
87                         
88                 </div>
89
90                 <div id="project-metadata">
91                         
92                         
93                         <div id="fileindex-section" class="section project-section">
94                                 <h3 class="section-header">Files</h3>
95                                 <ul>
96                                 
97                                         <li class="file"><a href="../COPYING.html">COPYING</a></li>
98                                 
99                                         <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
100                                 
101                                         <li class="file"><a href="../README.html">README</a></li>
102                                 
103                                         <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
104                                 
105                                         <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
106                                 
107                                         <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
108                                 
109                                         <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
110                                 
111                                         <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
112                                 
113                                         <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
114                                 
115                                         <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
116                                 
117                                         <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
118                                 
119                                         <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
120                                 
121                                         <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
122                                 
123                                         <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
124                                 
125                                         <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
126                                 
127                                         <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
128                                 
129                                         <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
130                                 
131                                         <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
132                                 
133                                         <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
134                                 
135                                         <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
136                                 
137                                 </ul>
138                         </div>
139                         
140
141                         <div id="classindex-section" class="section project-section">
142                                 <h3 class="section-header">Class Index
143                                         <span class="search-toggle"><img src="../images/find.png"
144                                                 height="16" width="16" alt="[+]"
145                                                 title="show/hide quicksearch" /></span></h3>
146                                 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
147                                 <fieldset>
148                                         <legend>Quicksearch</legend>
149                                         <input type="text" name="quicksearch" value=""
150                                                 class="quicksearch-field" />
151                                 </fieldset>
152                                 </form>
153
154                                 <ul class="link-list">
155                                 
156                                         <li><a href="../MCollective.html">MCollective</a></li>
157                                 
158                                         <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
159                                 
160                                         <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
161                                 
162                                         <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
163                                 
164                                         <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
165                                 
166                                         <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
167                                 
168                                         <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
169                                 
170                                         <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
171                                 
172                                         <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
173                                 
174                                         <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
175                                 
176                                         <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
177                                 
178                                         <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
179                                 
180                                         <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
181                                 
182                                         <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
183                                 
184                                         <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
185                                 
186                                         <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
187                                 
188                                         <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
189                                 
190                                         <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
191                                 
192                                         <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
193                                 
194                                         <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
195                                 
196                                         <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
197                                 
198                                         <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
199                                 
200                                         <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
201                                 
202                                         <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
203                                 
204                                         <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
205                                 
206                                         <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
207                                 
208                                         <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
209                                 
210                                         <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
211                                 
212                                         <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
213                                 
214                                         <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
215                                 
216                                         <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
217                                 
218                                         <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
219                                 
220                                         <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
221                                 
222                                         <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
223                                 
224                                         <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
225                                 
226                                         <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
227                                 
228                                         <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
229                                 
230                                         <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
231                                 
232                                         <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
233                                 
234                                         <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
235                                 
236                                         <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
237                                 
238                                         <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
239                                 
240                                         <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
241                                 
242                                         <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
243                                 
244                                         <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
245                                 
246                                         <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
247                                 
248                                         <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
249                                 
250                                         <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
251                                 
252                                         <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
253                                 
254                                         <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
255                                 
256                                         <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
257                                 
258                                         <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
259                                 
260                                         <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
261                                 
262                                         <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
263                                 
264                                         <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
265                                 
266                                         <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
267                                 
268                                         <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
269                                 
270                                         <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
271                                 
272                                         <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
273                                 
274                                         <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
275                                 
276                                         <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
277                                 
278                                         <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
279                                 
280                                         <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
281                                 
282                                         <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
283                                 
284                                         <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
285                                 
286                                         <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
287                                 
288                                         <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
289                                 
290                                         <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
291                                 
292                                         <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
293                                 
294                                         <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
295                                 
296                                         <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
297                                 
298                                         <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
299                                 
300                                         <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
301                                 
302                                         <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
303                                 
304                                         <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
305                                 
306                                         <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
307                                 
308                                         <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
309                                 
310                                         <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
311                                 
312                                         <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
313                                 
314                                         <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
315                                 
316                                         <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
317                                 
318                                         <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
319                                 
320                                         <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
321                                 
322                                         <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
323                                 
324                                         <li><a href="../Array.html">Array</a></li>
325                                 
326                                         <li><a href="../Dir.html">Dir</a></li>
327                                 
328                                         <li><a href="../Object.html">Object</a></li>
329                                 
330                                         <li><a href="../String.html">String</a></li>
331                                 
332                                         <li><a href="../Symbol.html">Symbol</a></li>
333                                 
334                                 </ul>
335                                 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
336                         </div>
337
338                         
339                 </div>
340         </div>
341
342         <div id="documentation">
343                 <h1 class="class">MCollective::Agents</h1>
344
345                 <div id="description">
346                         <p>
347 A collection of agents, loads them, reloads them and dispatches messages to
348 them. It uses the <a href="PluginManager.html">PluginManager</a> to store,
349 load and manage instances of plugins.
350 </p>
351
352                 </div>
353
354                 <!-- Constants -->
355                 
356
357                 <!-- Attributes -->
358                 
359
360                 <!-- Methods -->
361                 
362                 <div id="public-class-method-details" class="method-section section">
363                         <h3 class="section-header">Public Class Methods</h3>
364
365                 
366                         <div id="agentlist-method" class="method-detail ">
367                                 <a name="M000112"></a>
368
369                                 <div class="method-heading">
370                                 
371                                         <span class="method-name">agentlist</span><span
372                                                 class="method-args">()</span>
373                                         <span class="method-click-advice">click to toggle source</span>
374                                 
375                                 </div>
376
377                                 <div class="method-description">
378                                         
379                                         <p>
380 Get a list of agents that we have
381 </p>
382                                         
383
384                                         
385                                         <div class="method-source-code"
386                                                 id="agentlist-source">
387 <pre>
388      <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 145</span>
389 145:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">agentlist</span>
390 146:       <span class="ruby-ivar">@@agents</span>.<span class="ruby-identifier">keys</span>
391 147:     <span class="ruby-keyword kw">end</span></pre>
392                                         </div>
393                                         
394                                 </div>
395
396                                 
397                         </div>
398
399                 
400                         <div id="new-method" class="method-detail ">
401                                 <a name="M000101"></a>
402
403                                 <div class="method-heading">
404                                 
405                                         <span class="method-name">new</span><span
406                                                 class="method-args">(agents = {})</span>
407                                         <span class="method-click-advice">click to toggle source</span>
408                                 
409                                 </div>
410
411                                 <div class="method-description">
412                                         
413                                         <p class="missing-docs">(Not documented)</p>
414                                         
415
416                                         
417                                         <div class="method-source-code"
418                                                 id="new-source">
419 <pre>
420     <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 5</span>
421  5:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">agents</span> = {})
422  6:       <span class="ruby-ivar">@config</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>
423  7:       <span class="ruby-identifier">raise</span> (<span class="ruby-value str">&quot;Configuration has not been loaded, can't load agents&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">configured</span>
424  8: 
425  9:       <span class="ruby-ivar">@@agents</span> = <span class="ruby-identifier">agents</span>
426 10: 
427 11:       <span class="ruby-identifier">loadagents</span>
428 12:     <span class="ruby-keyword kw">end</span></pre>
429                                         </div>
430                                         
431                                 </div>
432
433                                 
434                         </div>
435
436                 
437                 </div>
438         
439                 <div id="public-instance-method-details" class="method-section section">
440                         <h3 class="section-header">Public Instance Methods</h3>
441
442                 
443                         <div id="activate-agent--method" class="method-detail ">
444                                 <a name="M000106"></a>
445
446                                 <div class="method-heading">
447                                 
448                                         <span class="method-name">activate_agent?</span><span
449                                                 class="method-args">(agent)</span>
450                                         <span class="method-click-advice">click to toggle source</span>
451                                 
452                                 </div>
453
454                                 <div class="method-description">
455                                         
456                                         <p>
457 Checks if a plugin should be activated by calling activate? on it if it
458 responds to that method else always activate it
459 </p>
460                                         
461
462                                         
463                                         <div class="method-source-code"
464                                                 id="activate-agent--source">
465 <pre>
466     <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 85</span>
467 85:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">activate_agent?</span>(<span class="ruby-identifier">agent</span>)
468 86:       <span class="ruby-identifier">klass</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">&quot;MCollective&quot;</span>).<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">&quot;Agent&quot;</span>).<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">agent</span>.<span class="ruby-identifier">capitalize</span>)
469 87: 
470 88:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">&quot;activate?&quot;</span>)
471 89:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">activate?</span>
472 90:       <span class="ruby-keyword kw">else</span>
473 91:         <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;#{klass} does not have an activate? method, activating as default&quot;</span>)
474 92:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
475 93:       <span class="ruby-keyword kw">end</span>
476 94:     <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
477 95:       <span class="ruby-constant">Log</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">&quot;Agent activation check for #{agent} failed: #{e.class}: #{e}&quot;</span>)
478 96:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
479 97:     <span class="ruby-keyword kw">end</span></pre>
480                                         </div>
481                                         
482                                 </div>
483
484                                 
485                         </div>
486
487                 
488                         <div id="class-for-agent-method" class="method-detail ">
489                                 <a name="M000105"></a>
490
491                                 <div class="method-heading">
492                                 
493                                         <span class="method-name">class_for_agent</span><span
494                                                 class="method-args">(agent)</span>
495                                         <span class="method-click-advice">click to toggle source</span>
496                                 
497                                 </div>
498
499                                 <div class="method-description">
500                                         
501                                         <p>
502 Builds a class name string given a <a href="Agent.html">Agent</a> name
503 </p>
504                                         
505
506                                         
507                                         <div class="method-source-code"
508                                                 id="class-for-agent-source">
509 <pre>
510     <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 78</span>
511 78:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_for_agent</span>(<span class="ruby-identifier">agent</span>)
512 79:       <span class="ruby-node">&quot;MCollective::Agent::#{agent.capitalize}&quot;</span>
513 80:     <span class="ruby-keyword kw">end</span></pre>
514                                         </div>
515                                         
516                                 </div>
517
518                                 
519                         </div>
520
521                 
522                         <div id="clear--method" class="method-detail ">
523                                 <a name="M000102"></a>
524
525                                 <div class="method-heading">
526                                 
527                                         <span class="method-name">clear!</span><span
528                                                 class="method-args">()</span>
529                                         <span class="method-click-advice">click to toggle source</span>
530                                 
531                                 </div>
532
533                                 <div class="method-description">
534                                         
535                                         <p>
536 Deletes all agents
537 </p>
538                                         
539
540                                         
541                                         <div class="method-source-code"
542                                                 id="clear--source">
543 <pre>
544     <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 15</span>
545 15:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear!</span>
546 16:       <span class="ruby-ivar">@@agents</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">agent</span><span class="ruby-operator">|</span>
547 17:         <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">delete</span> <span class="ruby-node">&quot;#{agent}_agent&quot;</span>
548 18:         <span class="ruby-constant">Util</span>.<span class="ruby-identifier">unsubscribe</span>(<span class="ruby-constant">Util</span>.<span class="ruby-identifier">make_subscriptions</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">:broadcast</span>))
549 19:       <span class="ruby-keyword kw">end</span>
550 20: 
551 21:       <span class="ruby-ivar">@@agents</span> = {}
552 22:     <span class="ruby-keyword kw">end</span></pre>
553                                         </div>
554                                         
555                                 </div>
556
557                                 
558                         </div>
559
560                 
561                         <div id="dispatch-method" class="method-detail ">
562                                 <a name="M000109"></a>
563
564                                 <div class="method-heading">
565                                 
566                                         <span class="method-name">dispatch</span><span
567                                                 class="method-args">(request, connection)</span>
568                                         <span class="method-click-advice">click to toggle source</span>
569                                 
570                                 </div>
571
572                                 <div class="method-description">
573                                         
574                                         <p>
575 Dispatches a message to an agent, accepts a block that will get run if
576 there are any replies to process from the agent
577 </p>
578                                         
579
580                                         
581                                         <div class="method-source-code"
582                                                 id="dispatch-source">
583 <pre>
584      <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 118</span>
585 118:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">connection</span>)
586 119:       <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;Dispatching a message to agent #{request.agent}&quot;</span>)
587 120: 
588 121:       <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
589 122:         <span class="ruby-keyword kw">begin</span>
590 123:           <span class="ruby-identifier">agent</span> = <span class="ruby-constant">PluginManager</span>[<span class="ruby-node">&quot;#{request.agent}_agent&quot;</span>]
591 124: 
592 125:           <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-identifier">timeout</span>(<span class="ruby-identifier">agent</span>.<span class="ruby-identifier">timeout</span>) <span class="ruby-keyword kw">do</span>
593 126:             <span class="ruby-identifier">replies</span> = <span class="ruby-identifier">agent</span>.<span class="ruby-identifier">handlemsg</span>(<span class="ruby-identifier">request</span>.<span class="ruby-identifier">payload</span>, <span class="ruby-identifier">connection</span>)
594 127: 
595 128:             <span class="ruby-comment cmt"># Agents can decide if they wish to reply or not,</span>
596 129:             <span class="ruby-comment cmt"># returning nil will mean nothing goes back to the</span>
597 130:             <span class="ruby-comment cmt"># requestor</span>
598 131:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">replies</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
599 132:               <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">replies</span>)
600 133:             <span class="ruby-keyword kw">end</span>
601 134:           <span class="ruby-keyword kw">end</span>
602 135:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
603 136:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">&quot;Timeout while handling message for #{request.agent}&quot;</span>)
604 137:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
605 138:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">&quot;Execution of #{request.agent} failed: #{e}&quot;</span>)
606 139:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n\t\t&quot;</span>))
607 140:         <span class="ruby-keyword kw">end</span>
608 141:       <span class="ruby-keyword kw">end</span>
609 142:     <span class="ruby-keyword kw">end</span></pre>
610                                         </div>
611                                         
612                                 </div>
613
614                                 
615                         </div>
616
617                 
618                         <div id="findagentfile-method" class="method-detail ">
619                                 <a name="M000107"></a>
620
621                                 <div class="method-heading">
622                                 
623                                         <span class="method-name">findagentfile</span><span
624                                                 class="method-args">(agentname)</span>
625                                         <span class="method-click-advice">click to toggle source</span>
626                                 
627                                 </div>
628
629                                 <div class="method-description">
630                                         
631                                         <p>
632 searches the libdirs for agents
633 </p>
634                                         
635
636                                         
637                                         <div class="method-source-code"
638                                                 id="findagentfile-source">
639 <pre>
640      <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 100</span>
641 100:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">findagentfile</span>(<span class="ruby-identifier">agentname</span>)
642 101:       <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">libdir</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">libdir</span><span class="ruby-operator">|</span>
643 102:         <span class="ruby-identifier">agentfile</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>([<span class="ruby-identifier">libdir</span>, <span class="ruby-value str">&quot;mcollective&quot;</span>, <span class="ruby-value str">&quot;agent&quot;</span>, <span class="ruby-node">&quot;#{agentname}.rb&quot;</span>])
644 103:         <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">agentfile</span>)
645 104:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;Found #{agentname} at #{agentfile}&quot;</span>)
646 105:           <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">agentfile</span>
647 106:         <span class="ruby-keyword kw">end</span>
648 107:       <span class="ruby-keyword kw">end</span>
649 108:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
650 109:     <span class="ruby-keyword kw">end</span></pre>
651                                         </div>
652                                         
653                                 </div>
654
655                                 
656                         </div>
657
658                 
659                         <div id="include--method" class="method-detail ">
660                                 <a name="M000108"></a>
661
662                                 <div class="method-heading">
663                                 
664                                         <span class="method-name">include?</span><span
665                                                 class="method-args">(agentname)</span>
666                                         <span class="method-click-advice">click to toggle source</span>
667                                 
668                                 </div>
669
670                                 <div class="method-description">
671                                         
672                                         <p>
673 Determines if we have an agent with a certain name
674 </p>
675                                         
676
677                                         
678                                         <div class="method-source-code"
679                                                 id="include--source">
680 <pre>
681      <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 112</span>
682 112:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include?</span>(<span class="ruby-identifier">agentname</span>)
683 113:       <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-node">&quot;#{agentname}_agent&quot;</span>)
684 114:     <span class="ruby-keyword kw">end</span></pre>
685                                         </div>
686                                         
687                                 </div>
688
689                                 
690                         </div>
691
692                 
693                         <div id="loadagent-method" class="method-detail ">
694                                 <a name="M000104"></a>
695
696                                 <div class="method-heading">
697                                 
698                                         <span class="method-name">loadagent</span><span
699                                                 class="method-args">(agentname)</span>
700                                         <span class="method-click-advice">click to toggle source</span>
701                                 
702                                 </div>
703
704                                 <div class="method-description">
705                                         
706                                         <p>
707 Loads a specified agent from disk if available
708 </p>
709                                         
710
711                                         
712                                         <div class="method-source-code"
713                                                 id="loadagent-source">
714 <pre>
715     <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 42</span>
716 42:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">loadagent</span>(<span class="ruby-identifier">agentname</span>)
717 43:       <span class="ruby-identifier">agentfile</span> = <span class="ruby-identifier">findagentfile</span>(<span class="ruby-identifier">agentname</span>)
718 44:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">agentfile</span>
719 45:       <span class="ruby-identifier">classname</span> = <span class="ruby-identifier">class_for_agent</span>(<span class="ruby-identifier">agentname</span>)
720 46: 
721 47:       <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-node">&quot;#{agentname}_agent&quot;</span>)
722 48: 
723 49:       <span class="ruby-keyword kw">begin</span>
724 50:         <span class="ruby-identifier">single_instance</span> = [<span class="ruby-value str">&quot;registration&quot;</span>, <span class="ruby-value str">&quot;discovery&quot;</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">agentname</span>)
725 51: 
726 52:         <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">loadclass</span>(<span class="ruby-identifier">classname</span>)
727 53: 
728 54:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">activate_agent?</span>(<span class="ruby-identifier">agentname</span>)
729 55:           <span class="ruby-constant">PluginManager</span> <span class="ruby-operator">&lt;&lt;</span> {<span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{agentname}_agent&quot;</span>, <span class="ruby-identifier">:class</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">classname</span>, <span class="ruby-identifier">:single_instance</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">single_instance</span>}
730 56: 
731 57:           <span class="ruby-comment cmt"># Attempt to instantiate the agent once so any validation and hooks get run</span>
732 58:           <span class="ruby-comment cmt"># this does a basic sanity check on the agent as a whole, if this fails it</span>
733 59:           <span class="ruby-comment cmt"># will be removed from the plugin list</span>
734 60:           <span class="ruby-constant">PluginManager</span>[<span class="ruby-node">&quot;#{agentname}_agent&quot;</span>]
735 61: 
736 62:           <span class="ruby-constant">Util</span>.<span class="ruby-identifier">subscribe</span>(<span class="ruby-constant">Util</span>.<span class="ruby-identifier">make_subscriptions</span>(<span class="ruby-identifier">agentname</span>, <span class="ruby-identifier">:broadcast</span>)) <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@@agents</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">agentname</span>)
737 63: 
738 64:           <span class="ruby-ivar">@@agents</span>[<span class="ruby-identifier">agentname</span>] = {<span class="ruby-identifier">:file</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">agentfile</span>}
739 65:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
740 66:         <span class="ruby-keyword kw">else</span>
741 67:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;Not activating agent #{agentname} due to agent policy in activate? method&quot;</span>)
742 68:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
743 69:         <span class="ruby-keyword kw">end</span>
744 70:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
745 71:         <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">&quot;Loading agent #{agentname} failed: #{e}&quot;</span>)
746 72:         <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-node">&quot;#{agentname}_agent&quot;</span>)
747 73:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
748 74:       <span class="ruby-keyword kw">end</span>
749 75:     <span class="ruby-keyword kw">end</span></pre>
750                                         </div>
751                                         
752                                 </div>
753
754                                 
755                         </div>
756
757                 
758                         <div id="loadagents-method" class="method-detail ">
759                                 <a name="M000103"></a>
760
761                                 <div class="method-heading">
762                                 
763                                         <span class="method-name">loadagents</span><span
764                                                 class="method-args">()</span>
765                                         <span class="method-click-advice">click to toggle source</span>
766                                 
767                                 </div>
768
769                                 <div class="method-description">
770                                         
771                                         <p>
772 Loads all agents from disk
773 </p>
774                                         
775
776                                         
777                                         <div class="method-source-code"
778                                                 id="loadagents-source">
779 <pre>
780     <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 25</span>
781 25:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">loadagents</span>
782 26:       <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">&quot;Reloading all agents from disk&quot;</span>)
783 27: 
784 28:       <span class="ruby-identifier">clear!</span>
785 29: 
786 30:       <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">libdir</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">libdir</span><span class="ruby-operator">|</span>
787 31:         <span class="ruby-identifier">agentdir</span> = <span class="ruby-node">&quot;#{libdir}/mcollective/agent&quot;</span>
788 32:         <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">agentdir</span>)
789 33: 
790 34:         <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">agentdir</span>).<span class="ruby-identifier">grep</span>(<span class="ruby-regexp re">/\.rb$/</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">agent</span><span class="ruby-operator">|</span>
791 35:           <span class="ruby-identifier">agentname</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-value str">&quot;.rb&quot;</span>)
792 36:           <span class="ruby-identifier">loadagent</span>(<span class="ruby-identifier">agentname</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-node">&quot;#{agentname}_agent&quot;</span>)
793 37:         <span class="ruby-keyword kw">end</span>
794 38:       <span class="ruby-keyword kw">end</span>
795 39:     <span class="ruby-keyword kw">end</span></pre>
796                                         </div>
797                                         
798                                 </div>
799
800                                 
801                         </div>
802
803                 
804                 </div>
805         
806
807         </div>
808
809
810         <div id="rdoc-debugging-section-dump" class="debugging-section">
811         
812                 <p>Disabled; run with --debug to generate this.</p>
813         
814         </div>
815
816         <div id="validator-badges">
817                 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
818                 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
819                         Rdoc Generator</a> 1.1.6</small>.</p>
820         </div>
821
822 </body>
823 </html>
824