Class Nanite::Agent
In: lib/nanite/agent.rb
Parent: Object

Methods

Included Modules

AMQPHelper FileStreaming ConsoleHelper DaemonizeHelper

Constants

DEFAULT_OPTIONS = COMMON_DEFAULT_OPTIONS.merge({ :user => 'nanite', :ping_time => 15, :default_services => []

Attributes

amq  [R] 
dispatcher  [R] 
identity  [R] 
options  [R] 
registry  [R] 
serializer  [R] 
status_proc  [RW] 
tags  [R] 

Public Class methods

Initializes a new agent and establishes AMQP connection. This must be used inside EM.run block or if EventMachine reactor is already started, for instance, by a Thin server that your Merb/Rails application runs on.

Agent options:

identity : identity of this agent, may be any string

status_proc : a callable object that returns agent load as a string,

              defaults to load averages string extracted from `uptime`

format : format to use for packets serialization. One of the three:

              :marshall, :json, or :yaml. Defaults to
              Ruby's Marshall format. For interoperability with
              AMQP clients implemented in other languages, use JSON.

              Note that Nanite uses JSON gem,
              and ActiveSupport's JSON encoder may cause clashes
              if ActiveSupport is loaded after JSON gem.

root : application root for this agent, defaults to Dir.pwd

log_dir : path to directory where agent stores it‘s log file

              if not given, app_root is used.

file_root : path to directory to files this agent provides

              defaults to app_root/files

ping_time : time interval in seconds between two subsequent heartbeat messages

              this agent broadcasts. Default value is 15.

console : true tells Nanite to start interactive console

daemonize : true tells Nanite to daemonize

pid_dir : path to the directory where the agent stores its pid file (only if daemonized)

              defaults to the root or the current working directory.

services : list of services provided by this agent, by default

              all methods exposed by actors are listed

prefetch : Sets prefetch (only supported in RabbitMQ >= 1.6). Use value of 1 for long

              running jobs (greater than a second) to avoid slamming/stalling your agent.

single_threaded: Run all operations in one thread

threadpool_size: Number of threads to run operations in

Connection options:

vhost : AMQP broker vhost that should be used

user : AMQP broker user

pass : AMQP broker password

host : host AMQP broker (or node of interest) runs on,

           defaults to 0.0.0.0

port : port AMQP broker (or node of interest) runs on,

           this defaults to 5672, port used by some widely
           used AMQP brokers (RabbitMQ and ZeroMQ)

On start Nanite reads config.yml, so it is common to specify options in the YAML file. However, when both Ruby code options and YAML file specify option, Ruby code options take precedence.

Public Instance methods

Can be used in agent‘s initialization file to register a security module This security module ‘authorize’ method will be called back whenever the agent receives a request and will be given the corresponding deliverable. It should return ‘true’ for the request to proceed. Requests will return ‘deny_token’ or the string "Denied" by default when ‘authorize’ does not return ‘true’.

Protected Instance methods

[Validate]