Class: Nanite::Agent
- Includes:
- AMQPHelper, ConsoleHelper, DaemonizeHelper, FileStreaming
- Defined in:
- lib/nanite/agent.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
COMMON_DEFAULT_OPTIONS.merge({:user => 'nanite', :ping_time => 15, :default_services => []})
Instance Attribute Summary collapse
-
#amq ⇒ Object
readonly
Returns the value of attribute amq.
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
-
#status_proc ⇒ Object
Returns the value of attribute status_proc.
Class Method Summary collapse
-
.start(options = {}) ⇒ Object
Initializes a new agent and establishes AMQP connection.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Agent
constructor
A new instance of Agent.
- #register(actor, prefix = nil) ⇒ Object
Methods included from DaemonizeHelper
Methods included from ConsoleHelper
Methods included from FileStreaming
#broadcast_data, #broadcast_file, #subscribe_to_files
Methods included from AMQPHelper
Constructor Details
#initialize(opts) ⇒ Agent
Returns a new instance of Agent.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/nanite/agent.rb', line 74 def initialize(opts) set_configuration(opts) @log = Log.new(@options, @identity) @serializer = Serializer.new(@options[:format]) @status_proc = lambda { parse_uptime(`uptime`) rescue 'no status' } daemonize if @options[:daemonize] @amq = start_amqp(@options) @registry = ActorRegistry.new(@log) @dispatcher = Dispatcher.new(@amq, @registry, @serializer, @identity, @log, @options) load_actors setup_queue advertise_services setup_heartbeat start_console if @options[:console] && !@options[:daemonize] end |
Instance Attribute Details
#amq ⇒ Object (readonly)
Returns the value of attribute amq.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def amq @amq end |
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def dispatcher @dispatcher end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def identity @identity end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def log @log end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def @options end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def registry @registry end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
8 9 10 |
# File 'lib/nanite/agent.rb', line 8 def serializer @serializer end |
#status_proc ⇒ Object
Returns the value of attribute status_proc.
9 10 11 |
# File 'lib/nanite/agent.rb', line 9 def status_proc @status_proc end |
Class Method Details
.start(options = {}) ⇒ Object
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
services : list of services provided by this agent, by default
all methods exposed by actors are listed
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.
70 71 72 |
# File 'lib/nanite/agent.rb', line 70 def self.start( = {}) new() end |
Instance Method Details
#register(actor, prefix = nil) ⇒ Object
90 91 92 |
# File 'lib/nanite/agent.rb', line 90 def register(actor, prefix = nil) registry.register(actor, prefix) end |