Permalink
Browse files

Merge branch 'master' of git://github.com/ezmobius/nanite

* 'master' of git://github.com/ezmobius/nanite:
  offline queue
  Spelling
  updating gitignore
  do it in init;rb
  Make the simple nanite example work again
  Added support for rdoc generation from Rakefile, and use hanna if available
  need to register simple
  • Loading branch information...
raggi committed Jan 30, 2009
2 parents b0afbf5 + 777a715 commit 7a2bed128e832d8f0fb3208d0cc39a023e9d6705
Showing with 24 additions and 11 deletions.
  1. +2 −0 .gitignore
  2. +2 −2 bin/nanite
  3. +1 −0 examples/simpleagent/init.rb
  4. +12 −9 lib/nanite/agent.rb
  5. +7 −0 lib/nanite/mapper.rb
View
@@ -3,5 +3,7 @@
.#*
.emacs*
pkg
+db
+vendor
*.log
rdoc
View
@@ -38,7 +38,7 @@ opts = OptionParser.new do |opts|
options[:port] = port
end
- opts.on("-t", "--token IDENITY", "Specify the nanite identity.") do |ident|
+ opts.on("-t", "--token IDENTITY", "Specify the nanite identity.") do |ident|
options[:identity] = ident
end
@@ -62,7 +62,7 @@ opts = OptionParser.new do |opts|
options[:ping_time] = ping
end
- opts.on("-s", "--services SERVIVES", "Specify nanite's global services: -s /slice/42,/foo/3") do |res|
+ opts.on("-s", "--services SERVICES", "Specify nanite's global services: -s /slice/42,/foo/3") do |res|
options[:services] = res.split(/,/).map { |r| r.strip }
end
@@ -0,0 +1 @@
+register Simple.new
View
@@ -134,19 +134,22 @@ def start
send_ping
end
- amq.queue(identity, :exclusive => true).subscribe{ |msg|
- if opts[:threaded_actors]
- Thread.new(msg) do |msg_in_thread|
- dispatcher.handle(load_packet(msg_in_thread))
- end
- else
- dispatcher.handle(load_packet(msg))
- end
- }
+ amq.queue("nanite.offline").subscribe{ |msg| dispatch_message(msg) }
+ amq.queue(identity, :exclusive => true).subscribe{ |msg| dispatch_message(msg) }
end
start_console if opts[:console] && !opts[:daemonize]
end
+
+ def dispatch_message(msg)
+ if opts[:threaded_actors]
+ Thread.new(msg) do |msg_in_thread|
+ dispatcher.handle(load_packet(msg_in_thread))
+ end
+ else
+ dispatcher.handle(load_packet(msg))
+ end
+ end
def register(actor_instance, prefix = nil)
dispatcher.register(actor_instance, prefix)
View
@@ -157,6 +157,7 @@ def request(type, payload="", opts = {}, &blk)
if target = opts[:target]
answer = route_specific(req, target)
else
+ opts[:selector] = false if opts[:timeout] == false
answer = route(req, opts[:selector])
end
return false unless answer
@@ -178,6 +179,7 @@ def push(type, payload="", opts = {:selector => :least_loaded, :timeout => 60})
req = Request.new(type, payload, agent.identity)
req.token = Nanite.gensym
req.reply_to = nil
+ opts[:selector] = false if opts[:timeout] == false
if answer = route(req, opts[:selector])
true
else
@@ -305,6 +307,11 @@ def route_specific(req, target)
# multicast routing method
def route(req, selector)
+ unless selector
+ send_request(req, "nanite.offline")
+ return
+ end
+
targets = __send__(selector, req.type)
unless targets.empty?
answer = Answer.new(agent, req.token)

0 comments on commit 7a2bed1

Please sign in to comment.