AgentDispatcher is (almost) a non-intrusive application micro-framework that turns your plain ruby objects into configurable, reactive, and easily operable “agents”. They will react on commands; combine behaviors using dynamic configurations; multiply instances, play nice with with *nix infrastructure. In other words, object-oriented, shell-script-enabled approach towards agents modelling.

No rocket science – just a practical construct.


Download and Installation

The library is available as gem. Install it by: gem install agentdispatcher


The most up-to-date documentation of the library is its API (RDoc) documentation. Although the most effective documentation are usually examples.



The basic features can be best illustrated by simple example.


 1 require 'rubygems'
 2 require 'agentdispatcher'
 4 class Agent
 5     include AgentDispatcher
 6     @AllowedCommands =['run']
 7     def on_run *args
 8        "Executing run command #{@id}, config: {@cfg.inspect}"
 9     end
10 end
12 class AgentChild < Agent
13     @DefaultCfg = {:log_path=>'/tmp'}
14     @AllowedCommands = %w(foo run)
15     upMethod :initBussines
16     def initBussines
17         @log.debug "post creation placeholder"
18     end
19     downMethod :closeBussines
20     def closeBussines
21         @log.debug "pre-shutdown placeholder"
22     end
23     def on_foo *args
24 "Executing foo arguments:#{args}"
25     end
26 end
27 if __FILE__ == $0
28   AgentChild::Dispatch *ARGV
29 end

The “agent” can be easily invoked/customized from command-line:

  1. agent.rb myId foo arg1 arg2
    ... executes a single instance of agent with id myId and invoke method foo that will be passed arguments arg1, arg2. A default configuration is used.
  2. agent.rb
    ... all default. Id agentchild, method run, default config, no arguments.
  3. agent.rb --config cfgfile1,cfgfile2 agentID
    ... agent loads two configurations (specified by name here).
  4. agent.rb --help
    ... prints a usage help.

Note: If you are trying the examples your are probably getting an error complaining on missing path. This is because agents wants to write pid file (and logs). Just run the command with nopid options agent.rb --nopid ... (or specify it in the config).

The example shows the objects can use standard inheritance (AgentChild

Author and License

Copyright© 2008 Viktor Zigo. All rights reserved. Distributed under GNU GPL License (see LICENSE).

Sponsored by: